X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c3b26754a231ec909506f2ff28af1af9f2e27f2b..2a4c07b8a031b64714cd02b5e3caec413c849a31:/lib/controller/handler_test.go diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go index 746b9242f2..fbfb037d36 100644 --- a/lib/controller/handler_test.go +++ b/lib/controller/handler_test.go @@ -5,6 +5,7 @@ package controller import ( + "context" "encoding/json" "net/http" "net/http/httptest" @@ -16,13 +17,18 @@ import ( "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" 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{}) @@ -30,21 +36,46 @@ var _ = check.Suite(&HandlerSuite{}) type HandlerSuite struct { cluster *arvados.Cluster handler http.Handler + ctx context.Context + cancel context.CancelFunc } func (s *HandlerSuite) SetUpTest(c *check.C) { + s.ctx, s.cancel = context.WithCancel(context.Background()) + s.ctx = ctxlog.Context(s.ctx, ctxlog.New(os.Stderr, "json", "debug")) s.cluster = &arvados.Cluster{ ClusterID: "zzzzz", PostgreSQL: integrationTestCluster().PostgreSQL, - NodeProfiles: map[string]arvados.NodeProfile{ - "*": { - Controller: arvados.SystemServiceInstance{Listen: ":"}, - RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"), TLS: true, Insecure: true}, - }, - }, + + EnableBetaController14287: enableBetaController14287, } - node := s.cluster.NodeProfiles["*"] - s.handler = newHandler(s.cluster, &node) + 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, "") +} + +func (s *HandlerSuite) TearDownTest(c *check.C) { + s.cancel() +} + +func (s *HandlerSuite) TestConfigExport(c *check.C) { + s.cluster.ManagementToken = "secret" + 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)) } func (s *HandlerSuite) TestProxyDiscoveryDoc(c *check.C) { @@ -62,7 +93,7 @@ func (s *HandlerSuite) TestProxyDiscoveryDoc(c *check.C) { } func (s *HandlerSuite) TestRequestTimeout(c *check.C) { - s.cluster.HTTPRequestTimeout = arvados.Duration(time.Nanosecond) + s.cluster.API.RequestTimeout = arvados.Duration(time.Nanosecond) req := httptest.NewRequest("GET", "/discovery/v1/apis/arvados/v1/rest", nil) resp := httptest.NewRecorder() s.handler.ServeHTTP(resp, req) @@ -128,7 +159,7 @@ func (s *HandlerSuite) TestProxyRedirect(c *check.C) { 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=foo&?`) + 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) {