15867: Don't pass blank remote param.
[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.curoverse.com/arvados.git/sdk/go/arvados"
12         "git.curoverse.com/arvados.git/sdk/go/arvadostest"
13         check "gopkg.in/check.v1"
14 )
15
16 func (s *FederationSuite) TestDeferToLoginCluster(c *check.C) {
17         s.addHTTPRemote(c, "zhome", &arvadostest.APIStub{})
18         s.cluster.Login.LoginCluster = "zhome"
19
20         returnTo := "https://app.example.com/foo?bar"
21         for _, remote := range []string{"", "ccccc"} {
22                 resp, err := s.fed.Login(context.Background(), arvados.LoginOptions{Remote: remote, ReturnTo: returnTo})
23                 c.Check(err, check.IsNil)
24                 c.Logf("remote %q -- RedirectLocation %q", remote, resp.RedirectLocation)
25                 target, err := url.Parse(resp.RedirectLocation)
26                 c.Check(err, check.IsNil)
27                 c.Check(target.Host, check.Equals, s.cluster.RemoteClusters["zhome"].Host)
28                 c.Check(target.Scheme, check.Equals, "http")
29                 c.Check(target.Query().Get("return_to"), check.Equals, returnTo)
30                 c.Check(target.Query().Get("remote"), check.Equals, remote)
31                 _, remotePresent := target.Query()["remote"]
32                 c.Check(remotePresent, check.Equals, remote != "")
33         }
34 }