X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/15043a6825ecd62ccb2272025384474a235b30cc..02199566253fabd839e61d30e510f58ceb87a16f:/lib/controller/handler_test.go diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go index a240b195ea..76eab9ca15 100644 --- a/lib/controller/handler_test.go +++ b/lib/controller/handler_test.go @@ -272,15 +272,16 @@ func (s *HandlerSuite) TestProxyNotFound(c *check.C) { } func (s *HandlerSuite) TestLogoutGoogle(c *check.C) { + s.cluster.Services.Workbench2.ExternalURL = arvados.URL{Scheme: "https", Host: "wb2.example", Path: "/"} s.cluster.Login.Google.Enable = true s.cluster.Login.Google.ClientID = "test" - req := httptest.NewRequest("GET", "https://0.0.0.0:1/logout?return_to=https://example.com/foo", nil) + req := httptest.NewRequest("GET", "https://0.0.0.0:1/logout?return_to=https://wb2.example/", nil) resp := httptest.NewRecorder() s.handler.ServeHTTP(resp, req) if !c.Check(resp.Code, check.Equals, http.StatusFound) { c.Log(resp.Body.String()) } - c.Check(resp.Header().Get("Location"), check.Equals, "https://example.com/foo") + c.Check(resp.Header().Get("Location"), check.Equals, "https://wb2.example/") } func (s *HandlerSuite) TestValidateV1APIToken(c *check.C) { @@ -562,3 +563,59 @@ func (s *HandlerSuite) TestLogActivity(c *check.C) { c.Check(rows, check.Equals, 1, check.Commentf("expect 1 row for user uuid %s", userUUID)) } } + +func (s *HandlerSuite) TestLogLimiting(c *check.C) { + s.handler.Cluster.API.MaxConcurrentRequests = 2 + s.handler.Cluster.API.LogCreateRequestFraction = 0.5 + + logreq := httptest.NewRequest("POST", "/arvados/v1/logs", strings.NewReader(`{ + "log": { + "event_type": "test" + } + }`)) + logreq.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken) + + // Log create succeeds + for i := 0; i < 2; i++ { + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, logreq) + c.Check(resp.Code, check.Equals, http.StatusOK) + var lg arvados.Log + err := json.Unmarshal(resp.Body.Bytes(), &lg) + c.Check(err, check.IsNil) + c.Check(lg.UUID, check.Matches, "zzzzz-57u5n-.*") + } + + // Pretend there's a log create in flight + s.handler.limitLogCreate <- struct{}{} + + // Log create should be rejected now + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, logreq) + c.Check(resp.Code, check.Equals, http.StatusServiceUnavailable) + + // Other requests still succeed + req := httptest.NewRequest("GET", "/arvados/v1/users/current", nil) + req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken) + 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) + + // log create still fails + resp = httptest.NewRecorder() + s.handler.ServeHTTP(resp, logreq) + c.Check(resp.Code, check.Equals, http.StatusServiceUnavailable) + + // Pretend in-flight log is done + <-s.handler.limitLogCreate + + // log create succeeds again + resp = httptest.NewRecorder() + s.handler.ServeHTTP(resp, logreq) + c.Check(resp.Code, check.Equals, http.StatusOK) + +}