X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/36f8e449321e4fa02d88fee1fded14aa8ff81723..50cbdcbd67f8b0da06d3b188e7bfdea3963661a7:/lib/controller/handler_test.go diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go index 57bb13d959..eb947ea363 100644 --- a/lib/controller/handler_test.go +++ b/lib/controller/handler_test.go @@ -8,11 +8,15 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "net/url" "os" + "strings" "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/httpserver" check "gopkg.in/check.v1" ) @@ -31,14 +35,14 @@ type HandlerSuite struct { func (s *HandlerSuite) SetUpTest(c *check.C) { s.cluster = &arvados.Cluster{ ClusterID: "zzzzz", - SystemNodes: map[string]arvados.SystemNode{ + NodeProfiles: map[string]arvados.NodeProfile{ "*": { Controller: arvados.SystemServiceInstance{Listen: ":"}, - RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_API_HOST"), TLS: true}, + RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"), TLS: true}, }, }, } - node := s.cluster.SystemNodes["*"] + node := s.cluster.NodeProfiles["*"] s.handler = newHandler(s.cluster, &node) } @@ -56,6 +60,19 @@ func (s *HandlerSuite) TestProxyDiscoveryDoc(c *check.C) { c.Check(len(dd.Schemas), check.Not(check.Equals), 0) } +func (s *HandlerSuite) TestRequestTimeout(c *check.C) { + s.cluster.HTTPRequestTimeout = arvados.Duration(time.Nanosecond) + req := httptest.NewRequest("GET", "/discovery/v1/apis/arvados/v1/rest", nil) + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, req) + c.Check(resp.Code, check.Equals, http.StatusInternalServerError) + var jresp httpserver.ErrorResponse + err := json.Unmarshal(resp.Body.Bytes(), &jresp) + c.Check(err, check.IsNil) + c.Assert(len(jresp.Errors), check.Equals, 1) + c.Check(jresp.Errors[0], check.Matches, `.*context deadline exceeded`) +} + func (s *HandlerSuite) TestProxyWithoutToken(c *check.C) { req := httptest.NewRequest("GET", "/arvados/v1/users/current", nil) resp := httptest.NewRecorder() @@ -79,6 +96,20 @@ func (s *HandlerSuite) TestProxyWithToken(c *check.C) { c.Check(u.UUID, check.Equals, arvadostest.ActiveUserUUID) } +func (s *HandlerSuite) TestProxyWithTokenInRequestBody(c *check.C) { + req := httptest.NewRequest("POST", "/arvados/v1/users/current", strings.NewReader(url.Values{ + "_method": {"GET"}, + "api_token": {arvadostest.ActiveToken}, + }.Encode())) + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, req) + c.Check(resp.Code, check.Equals, http.StatusOK) + var u arvados.User + err := json.Unmarshal(resp.Body.Bytes(), &u) + c.Check(err, check.IsNil) + c.Check(u.UUID, check.Equals, arvadostest.ActiveUserUUID) +} + func (s *HandlerSuite) TestProxyNotFound(c *check.C) { req := httptest.NewRequest("GET", "/arvados/v1/xyzzy", nil) resp := httptest.NewRecorder() @@ -89,3 +120,11 @@ func (s *HandlerSuite) TestProxyNotFound(c *check.C) { c.Check(err, check.IsNil) c.Check(jresp["errors"], check.FitsTypeOf, []interface{}{}) } + +func (s *HandlerSuite) TestProxyRedirect(c *check.C) { + req := httptest.NewRequest("GET", "https://example.org:1234/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://example\.org:1234/auth/joshid\?return_to=foo&?`) +}