X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/572e375e1c950f35d7e159bac031de5205354590..da58ec28659f5167f9658be5714731acee57dfb1:/services/keep-web/handler_test.go diff --git a/services/keep-web/handler_test.go b/services/keep-web/handler_test.go index 65dfb4312f..6412789ff9 100644 --- a/services/keep-web/handler_test.go +++ b/services/keep-web/handler_test.go @@ -50,7 +50,7 @@ func (s *UnitSuite) SetUpTest(c *check.C) { } func (s *UnitSuite) TestCORSPreflight(c *check.C) { - h := handler{Config: newConfig(s.Config)} + h := handler{Config: newConfig(ctxlog.TestLogger(c), s.Config)} u := mustParseURL("http://keep-web.example/c=" + arvadostest.FooCollection + "/foo") req := &http.Request{ Method: "OPTIONS", @@ -109,7 +109,7 @@ func (s *UnitSuite) TestEmptyResponse(c *check.C) { c.Assert(err, check.IsNil) } - h := handler{Config: newConfig(s.Config)} + h := handler{Config: newConfig(ctxlog.TestLogger(c), s.Config)} u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo") req := &http.Request{ Method: "GET", @@ -159,7 +159,7 @@ func (s *UnitSuite) TestInvalidUUID(c *check.C) { RequestURI: u.RequestURI(), } resp := httptest.NewRecorder() - cfg := newConfig(s.Config) + cfg := newConfig(ctxlog.TestLogger(c), s.Config) cfg.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken h := handler{Config: cfg} h.ServeHTTP(resp, req) @@ -1067,7 +1067,7 @@ func (s *IntegrationSuite) TestFileContentType(c *check.C) { contentType string }{ {"picture.txt", "BMX bikes are small this year\n", "text/plain; charset=utf-8"}, - {"picture.bmp", "BMX bikes are small this year\n", "image/x-ms-bmp"}, + {"picture.bmp", "BMX bikes are small this year\n", "image/(x-ms-)?bmp"}, {"picture.jpg", "BMX bikes are small this year\n", "image/jpeg"}, {"picture1", "BMX bikes are small this year\n", "image/bmp"}, // content sniff; "BM" is the magic signature for .bmp {"picture2", "Cars are small this year\n", "text/plain; charset=utf-8"}, // content sniff @@ -1103,7 +1103,7 @@ func (s *IntegrationSuite) TestFileContentType(c *check.C) { resp := httptest.NewRecorder() s.testServer.Handler.ServeHTTP(resp, req) c.Check(resp.Code, check.Equals, http.StatusOK) - c.Check(resp.Header().Get("Content-Type"), check.Equals, trial.contentType) + c.Check(resp.Header().Get("Content-Type"), check.Matches, trial.contentType) c.Check(resp.Body.String(), check.Equals, trial.content) } } @@ -1202,7 +1202,6 @@ func (s *IntegrationSuite) checkUploadDownloadRequest(c *check.C, h *handler, re c.Check(err, check.IsNil) c.Check(logentries.Items, check.HasLen, 1) lastLogId := logentries.Items[0].ID - nextLogId := lastLogId var logbuf bytes.Buffer logger := logrus.New() @@ -1216,23 +1215,29 @@ func (s *IntegrationSuite) checkUploadDownloadRequest(c *check.C, h *handler, re c.Check(logbuf.String(), check.Matches, `(?ms).*msg="File `+direction+`".*`) c.Check(logbuf.String(), check.Not(check.Matches), `(?ms).*level=error.*`) - for nextLogId == lastLogId { - time.Sleep(50 * time.Millisecond) + deadline := time.Now().Add(time.Second) + for { + c.Assert(time.Now().After(deadline), check.Equals, false, check.Commentf("timed out waiting for log entry")) err = client.RequestAndDecode(&logentries, "GET", "arvados/v1/logs", nil, arvados.ResourceListParams{ - Filters: []arvados.Filter{arvados.Filter{Attr: "event_type", Operator: "=", Operand: "file_" + direction}}, - Limit: &limit1, - Order: "created_at desc", + Filters: []arvados.Filter{ + {Attr: "event_type", Operator: "=", Operand: "file_" + direction}, + {Attr: "object_uuid", Operator: "=", Operand: userUuid}, + }, + Limit: &limit1, + Order: "created_at desc", }) - c.Check(err, check.IsNil) - if len(logentries.Items) > 0 { - nextLogId = logentries.Items[0].ID + c.Assert(err, check.IsNil) + if len(logentries.Items) > 0 && + logentries.Items[0].ID > lastLogId && + logentries.Items[0].ObjectUUID == userUuid && + logentries.Items[0].Properties["collection_uuid"] == collectionUuid && + logentries.Items[0].Properties["collection_file_path"] == filepath { + break } + c.Logf("logentries.Items: %+v", logentries.Items) + time.Sleep(50 * time.Millisecond) } - - c.Check(logentries.Items[0].ObjectUUID, check.Equals, userUuid) - c.Check(logentries.Items[0].Properties["collection_uuid"], check.Equals, collectionUuid) - c.Check(logentries.Items[0].Properties["collection_file_path"], check.Equals, filepath) } else { c.Check(resp.Result().StatusCode, check.Equals, http.StatusForbidden) c.Check(logbuf.String(), check.Equals, "") @@ -1240,10 +1245,12 @@ func (s *IntegrationSuite) checkUploadDownloadRequest(c *check.C, h *handler, re } func (s *IntegrationSuite) TestDownloadLoggingPermission(c *check.C) { - config := newConfig(s.ArvConfig) + config := newConfig(ctxlog.TestLogger(c), s.ArvConfig) h := handler{Config: config} u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo") + config.cluster.Collections.TrustAllContent = true + for _, adminperm := range []bool{true, false} { for _, userperm := range []bool{true, false} { config.cluster.Collections.WebDAVPermission.Admin.Download = adminperm @@ -1276,10 +1283,42 @@ func (s *IntegrationSuite) TestDownloadLoggingPermission(c *check.C) { arvadostest.ActiveUserUUID, arvadostest.FooCollection, "foo") } } + + config.cluster.Collections.WebDAVPermission.User.Download = true + + for _, tryurl := range []string{"http://" + arvadostest.MultilevelCollection1 + ".keep-web.example/dir1/subdir/file1", + "http://keep-web/users/active/multilevel_collection_1/dir1/subdir/file1"} { + + u = mustParseURL(tryurl) + req := &http.Request{ + Method: "GET", + Host: u.Host, + URL: u, + RequestURI: u.RequestURI(), + Header: http.Header{ + "Authorization": {"Bearer " + arvadostest.ActiveToken}, + }, + } + s.checkUploadDownloadRequest(c, &h, req, http.StatusOK, "download", true, + arvadostest.ActiveUserUUID, arvadostest.MultilevelCollection1, "dir1/subdir/file1") + } + + u = mustParseURL("http://" + strings.Replace(arvadostest.FooCollectionPDH, "+", "-", 1) + ".keep-web.example/foo") + req := &http.Request{ + Method: "GET", + Host: u.Host, + URL: u, + RequestURI: u.RequestURI(), + Header: http.Header{ + "Authorization": {"Bearer " + arvadostest.ActiveToken}, + }, + } + s.checkUploadDownloadRequest(c, &h, req, http.StatusOK, "download", true, + arvadostest.ActiveUserUUID, arvadostest.FooCollection, "foo") } func (s *IntegrationSuite) TestUploadLoggingPermission(c *check.C) { - config := newConfig(s.ArvConfig) + config := newConfig(ctxlog.TestLogger(c), s.ArvConfig) h := handler{Config: config} for _, adminperm := range []bool{true, false} {