Merge branch '15928-fs-deadlock'
[arvados.git] / lib / controller / federation / login_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package federation
6
7 import (
8         "context"
9         "net/url"
10
11         "git.arvados.org/arvados.git/sdk/go/arvados"
12         "git.arvados.org/arvados.git/sdk/go/arvadostest"
13         check "gopkg.in/check.v1"
14 )
15
16 var _ = check.Suite(&LoginSuite{})
17
18 type LoginSuite struct {
19         FederationSuite
20 }
21
22 func (s *LoginSuite) TestDeferToLoginCluster(c *check.C) {
23         s.addHTTPRemote(c, "zhome", &arvadostest.APIStub{})
24         s.cluster.Login.LoginCluster = "zhome"
25
26         returnTo := "https://app.example.com/foo?bar"
27         for _, remote := range []string{"", "ccccc"} {
28                 resp, err := s.fed.Login(context.Background(), arvados.LoginOptions{Remote: remote, ReturnTo: returnTo})
29                 c.Check(err, check.IsNil)
30                 c.Logf("remote %q -- RedirectLocation %q", remote, resp.RedirectLocation)
31                 target, err := url.Parse(resp.RedirectLocation)
32                 c.Check(err, check.IsNil)
33                 c.Check(target.Host, check.Equals, s.cluster.RemoteClusters["zhome"].Host)
34                 c.Check(target.Scheme, check.Equals, "http")
35                 c.Check(target.Query().Get("return_to"), check.Equals, returnTo)
36                 c.Check(target.Query().Get("remote"), check.Equals, remote)
37                 _, remotePresent := target.Query()["remote"]
38                 c.Check(remotePresent, check.Equals, remote != "")
39         }
40 }