15924: Change import paths to git.arvados.org.
[arvados.git] / lib / controller / handler_test.go
index 9b0ff2764be620bd847dc03c2da2f0848b008f07..5243002256c1d743b4b2a1b1925ca096ddff1bad 100644 (file)
@@ -15,16 +15,21 @@ import (
        "testing"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
-       "git.curoverse.com/arvados.git/sdk/go/ctxlog"
-       "git.curoverse.com/arvados.git/sdk/go/httpserver"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
+       "git.arvados.org/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/ctxlog"
+       "git.arvados.org/arvados.git/sdk/go/httpserver"
+       "github.com/prometheus/client_golang/prometheus"
        check "gopkg.in/check.v1"
 )
 
+var enableBetaController14287 bool
+
 // Gocheck boilerplate
 func Test(t *testing.T) {
-       check.TestingT(t)
+       for _, enableBetaController14287 = range []bool{false, true} {
+               check.TestingT(t)
+       }
 }
 
 var _ = check.Suite(&HandlerSuite{})
@@ -42,11 +47,13 @@ func (s *HandlerSuite) SetUpTest(c *check.C) {
        s.cluster = &arvados.Cluster{
                ClusterID:  "zzzzz",
                PostgreSQL: integrationTestCluster().PostgreSQL,
+
+               EnableBetaController14287: enableBetaController14287,
        }
        s.cluster.TLS.Insecure = true
        arvadostest.SetServiceURL(&s.cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
        arvadostest.SetServiceURL(&s.cluster.Services.Controller, "http://localhost:/")
-       s.handler = newHandler(s.ctx, s.cluster, "")
+       s.handler = newHandler(s.ctx, s.cluster, "", prometheus.NewRegistry())
 }
 
 func (s *HandlerSuite) TearDownTest(c *check.C) {
@@ -58,18 +65,27 @@ func (s *HandlerSuite) TestConfigExport(c *check.C) {
        s.cluster.SystemRootToken = "secret"
        s.cluster.Collections.BlobSigning = true
        s.cluster.Collections.BlobSigningTTL = arvados.Duration(23 * time.Second)
-       req := httptest.NewRequest("GET", "/arvados/v1/config", nil)
-       resp := httptest.NewRecorder()
-       s.handler.ServeHTTP(resp, req)
-       c.Check(resp.Code, check.Equals, http.StatusOK)
-       var cluster arvados.Cluster
-       c.Log(resp.Body.String())
-       err := json.Unmarshal(resp.Body.Bytes(), &cluster)
-       c.Check(err, check.IsNil)
-       c.Check(cluster.ManagementToken, check.Equals, "")
-       c.Check(cluster.SystemRootToken, check.Equals, "")
-       c.Check(cluster.Collections.BlobSigning, check.DeepEquals, true)
-       c.Check(cluster.Collections.BlobSigningTTL, check.Equals, arvados.Duration(23*time.Second))
+       for _, method := range []string{"GET", "OPTIONS"} {
+               req := httptest.NewRequest(method, "/arvados/v1/config", nil)
+               resp := httptest.NewRecorder()
+               s.handler.ServeHTTP(resp, req)
+               c.Check(resp.Code, check.Equals, http.StatusOK)
+               c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, `*`)
+               c.Check(resp.Header().Get("Access-Control-Allow-Methods"), check.Matches, `.*\bGET\b.*`)
+               c.Check(resp.Header().Get("Access-Control-Allow-Headers"), check.Matches, `.+`)
+               if method == "OPTIONS" {
+                       c.Check(resp.Body.String(), check.HasLen, 0)
+                       continue
+               }
+               var cluster arvados.Cluster
+               c.Log(resp.Body.String())
+               err := json.Unmarshal(resp.Body.Bytes(), &cluster)
+               c.Check(err, check.IsNil)
+               c.Check(cluster.ManagementToken, check.Equals, "")
+               c.Check(cluster.SystemRootToken, check.Equals, "")
+               c.Check(cluster.Collections.BlobSigning, check.DeepEquals, true)
+               c.Check(cluster.Collections.BlobSigningTTL, check.Equals, arvados.Duration(23*time.Second))
+       }
 }
 
 func (s *HandlerSuite) TestProxyDiscoveryDoc(c *check.C) {
@@ -149,11 +165,18 @@ func (s *HandlerSuite) TestProxyNotFound(c *check.C) {
 }
 
 func (s *HandlerSuite) TestProxyRedirect(c *check.C) {
+       s.cluster.Login.ProviderAppID = "test"
+       s.cluster.Login.ProviderAppSecret = "test"
        req := httptest.NewRequest("GET", "https://0.0.0.0:1/login?return_to=foo", nil)
        resp := httptest.NewRecorder()
        s.handler.ServeHTTP(resp, req)
-       c.Check(resp.Code, check.Equals, http.StatusFound)
-       c.Check(resp.Header().Get("Location"), check.Matches, `https://0.0.0.0:1/auth/joshid\?return_to=%2Cfoo&?`)
+       if !c.Check(resp.Code, check.Equals, http.StatusFound) {
+               c.Log(resp.Body.String())
+       }
+       // Old "proxy entire request" code path returns an absolute
+       // URL. New lib/controller/federation code path returns a
+       // relative URL.
+       c.Check(resp.Header().Get("Location"), check.Matches, `(https://0.0.0.0:1)?/auth/joshid\?return_to=%2Cfoo&?`)
 }
 
 func (s *HandlerSuite) TestValidateV1APIToken(c *check.C) {