1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
23 "git.arvados.org/arvados.git/lib/config"
24 "git.arvados.org/arvados.git/sdk/go/arvados"
25 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
26 "git.arvados.org/arvados.git/sdk/go/arvadostest"
27 "git.arvados.org/arvados.git/sdk/go/auth"
28 "git.arvados.org/arvados.git/sdk/go/ctxlog"
29 "git.arvados.org/arvados.git/sdk/go/keepclient"
30 "github.com/prometheus/client_golang/prometheus"
31 "github.com/sirupsen/logrus"
32 check "gopkg.in/check.v1"
35 var _ = check.Suite(&UnitSuite{})
38 arvados.DebugLocksPanicMode = true
41 type UnitSuite struct {
42 cluster *arvados.Cluster
46 func (s *UnitSuite) SetUpTest(c *check.C) {
47 logger := ctxlog.TestLogger(c)
48 ldr := config.NewLoader(bytes.NewBufferString("Clusters: {zzzzz: {}}"), logger)
50 cfg, err := ldr.Load()
51 c.Assert(err, check.IsNil)
52 cc, err := cfg.GetCluster("")
53 c.Assert(err, check.IsNil)
60 registry: prometheus.NewRegistry(),
65 func (s *UnitSuite) TestCORSPreflight(c *check.C) {
67 u := mustParseURL("http://keep-web.example/c=" + arvadostest.FooCollection + "/foo")
72 RequestURI: u.RequestURI(),
74 "Origin": {"https://workbench.example"},
75 "Access-Control-Request-Method": {"POST"},
79 // Check preflight for an allowed request
80 resp := httptest.NewRecorder()
81 h.ServeHTTP(resp, req)
82 c.Check(resp.Code, check.Equals, http.StatusOK)
83 c.Check(resp.Body.String(), check.Equals, "")
84 c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, "*")
85 c.Check(resp.Header().Get("Access-Control-Allow-Methods"), check.Equals, "COPY, DELETE, GET, LOCK, MKCOL, MOVE, OPTIONS, POST, PROPFIND, PROPPATCH, PUT, RMCOL, UNLOCK")
86 c.Check(resp.Header().Get("Access-Control-Allow-Headers"), check.Equals, "Authorization, Content-Type, Range, Depth, Destination, If, Lock-Token, Overwrite, Timeout")
88 // Check preflight for a disallowed request
89 resp = httptest.NewRecorder()
90 req.Header.Set("Access-Control-Request-Method", "MAKE-COFFEE")
91 h.ServeHTTP(resp, req)
92 c.Check(resp.Body.String(), check.Equals, "")
93 c.Check(resp.Code, check.Equals, http.StatusMethodNotAllowed)
96 func (s *UnitSuite) TestEmptyResponse(c *check.C) {
97 for _, trial := range []struct {
103 // If we return no content due to a Keep read error,
104 // we should emit a log message.
105 {false, false, http.StatusOK, `(?ms).*only wrote 0 bytes.*`},
107 // If we return no content because the client sent an
108 // If-Modified-Since header, our response should be
109 // 304. We still expect a "File download" log since it
110 // counts as a file access for auditing.
111 {true, true, http.StatusNotModified, `(?ms).*msg="File download".*`},
113 c.Logf("trial: %+v", trial)
114 arvadostest.StartKeep(2, true)
115 if trial.dataExists {
116 arv, err := arvadosclient.MakeArvadosClient()
117 c.Assert(err, check.IsNil)
118 arv.ApiToken = arvadostest.ActiveToken
119 kc, err := keepclient.MakeKeepClient(arv)
120 c.Assert(err, check.IsNil)
121 _, _, err = kc.PutB([]byte("foo"))
122 c.Assert(err, check.IsNil)
125 u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo")
126 req := &http.Request{
130 RequestURI: u.RequestURI(),
132 "Authorization": {"Bearer " + arvadostest.ActiveToken},
135 if trial.sendIMSHeader {
136 req.Header.Set("If-Modified-Since", strings.Replace(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT", -1))
139 var logbuf bytes.Buffer
140 logger := logrus.New()
142 req = req.WithContext(ctxlog.Context(context.Background(), logger))
144 resp := httptest.NewRecorder()
145 s.handler.ServeHTTP(resp, req)
146 c.Check(resp.Code, check.Equals, trial.expectStatus)
147 c.Check(resp.Body.String(), check.Equals, "")
149 c.Log(logbuf.String())
150 c.Check(logbuf.String(), check.Matches, trial.logRegexp)
154 func (s *UnitSuite) TestInvalidUUID(c *check.C) {
155 bogusID := strings.Replace(arvadostest.FooCollectionPDH, "+", "-", 1) + "-"
156 token := arvadostest.ActiveToken
157 for _, trial := range []string{
158 "http://keep-web/c=" + bogusID + "/foo",
159 "http://keep-web/c=" + bogusID + "/t=" + token + "/foo",
160 "http://keep-web/collections/download/" + bogusID + "/" + token + "/foo",
161 "http://keep-web/collections/" + bogusID + "/foo",
162 "http://" + bogusID + ".keep-web/" + bogusID + "/foo",
163 "http://" + bogusID + ".keep-web/t=" + token + "/" + bogusID + "/foo",
166 u := mustParseURL(trial)
167 req := &http.Request{
171 RequestURI: u.RequestURI(),
173 resp := httptest.NewRecorder()
174 s.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
175 s.handler.ServeHTTP(resp, req)
176 c.Check(resp.Code, check.Equals, http.StatusNotFound)
180 func mustParseURL(s string) *url.URL {
181 r, err := url.Parse(s)
183 panic("parse URL: " + s)
188 func (s *IntegrationSuite) TestVhost404(c *check.C) {
189 for _, testURL := range []string{
190 arvadostest.NonexistentCollection + ".example.com/theperthcountyconspiracy",
191 arvadostest.NonexistentCollection + ".example.com/t=" + arvadostest.ActiveToken + "/theperthcountyconspiracy",
193 resp := httptest.NewRecorder()
194 u := mustParseURL(testURL)
195 req := &http.Request{
198 RequestURI: u.RequestURI(),
200 s.handler.ServeHTTP(resp, req)
201 c.Check(resp.Code, check.Equals, http.StatusNotFound)
202 c.Check(resp.Body.String(), check.Equals, notFoundMessage+"\n")
206 // An authorizer modifies an HTTP request to make use of the given
207 // token -- by adding it to a header, cookie, query param, or whatever
208 // -- and returns the HTTP status code we should expect from keep-web if
209 // the token is invalid.
210 type authorizer func(*http.Request, string) int
212 func (s *IntegrationSuite) TestVhostViaAuthzHeaderOAuth2(c *check.C) {
213 s.doVhostRequests(c, authzViaAuthzHeaderOAuth2)
215 func authzViaAuthzHeaderOAuth2(r *http.Request, tok string) int {
216 r.Header.Add("Authorization", "Bearer "+tok)
217 return http.StatusUnauthorized
219 func (s *IntegrationSuite) TestVhostViaAuthzHeaderBearer(c *check.C) {
220 s.doVhostRequests(c, authzViaAuthzHeaderBearer)
222 func authzViaAuthzHeaderBearer(r *http.Request, tok string) int {
223 r.Header.Add("Authorization", "Bearer "+tok)
224 return http.StatusUnauthorized
227 func (s *IntegrationSuite) TestVhostViaCookieValue(c *check.C) {
228 s.doVhostRequests(c, authzViaCookieValue)
230 func authzViaCookieValue(r *http.Request, tok string) int {
231 r.AddCookie(&http.Cookie{
232 Name: "arvados_api_token",
233 Value: auth.EncodeTokenCookie([]byte(tok)),
235 return http.StatusUnauthorized
238 func (s *IntegrationSuite) TestVhostViaPath(c *check.C) {
239 s.doVhostRequests(c, authzViaPath)
241 func authzViaPath(r *http.Request, tok string) int {
242 r.URL.Path = "/t=" + tok + r.URL.Path
243 return http.StatusNotFound
246 func (s *IntegrationSuite) TestVhostViaQueryString(c *check.C) {
247 s.doVhostRequests(c, authzViaQueryString)
249 func authzViaQueryString(r *http.Request, tok string) int {
250 r.URL.RawQuery = "api_token=" + tok
251 return http.StatusUnauthorized
254 func (s *IntegrationSuite) TestVhostViaPOST(c *check.C) {
255 s.doVhostRequests(c, authzViaPOST)
257 func authzViaPOST(r *http.Request, tok string) int {
259 r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
260 r.Body = ioutil.NopCloser(strings.NewReader(
261 url.Values{"api_token": {tok}}.Encode()))
262 return http.StatusUnauthorized
265 func (s *IntegrationSuite) TestVhostViaXHRPOST(c *check.C) {
266 s.doVhostRequests(c, authzViaPOST)
268 func authzViaXHRPOST(r *http.Request, tok string) int {
270 r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
271 r.Header.Add("Origin", "https://origin.example")
272 r.Body = ioutil.NopCloser(strings.NewReader(
275 "disposition": {"attachment"},
277 return http.StatusUnauthorized
280 // Try some combinations of {url, token} using the given authorization
281 // mechanism, and verify the result is correct.
282 func (s *IntegrationSuite) doVhostRequests(c *check.C, authz authorizer) {
283 for _, hostPath := range []string{
284 arvadostest.FooCollection + ".example.com/foo",
285 arvadostest.FooCollection + "--collections.example.com/foo",
286 arvadostest.FooCollection + "--collections.example.com/_/foo",
287 arvadostest.FooCollectionPDH + ".example.com/foo",
288 strings.Replace(arvadostest.FooCollectionPDH, "+", "-", -1) + "--collections.example.com/foo",
289 arvadostest.FooBarDirCollection + ".example.com/dir1/foo",
291 c.Log("doRequests: ", hostPath)
292 s.doVhostRequestsWithHostPath(c, authz, hostPath)
296 func (s *IntegrationSuite) doVhostRequestsWithHostPath(c *check.C, authz authorizer, hostPath string) {
297 for _, tok := range []string{
298 arvadostest.ActiveToken,
299 arvadostest.ActiveToken[:15],
300 arvadostest.SpectatorToken,
304 u := mustParseURL("http://" + hostPath)
305 req := &http.Request{
309 RequestURI: u.RequestURI(),
310 Header: http.Header{},
312 failCode := authz(req, tok)
313 req, resp := s.doReq(req)
314 code, body := resp.Code, resp.Body.String()
316 // If the initial request had a (non-empty) token
317 // showing in the query string, we should have been
318 // redirected in order to hide it in a cookie.
319 c.Check(req.URL.String(), check.Not(check.Matches), `.*api_token=.+`)
321 if tok == arvadostest.ActiveToken {
322 c.Check(code, check.Equals, http.StatusOK)
323 c.Check(body, check.Equals, "foo")
325 c.Check(code >= 400, check.Equals, true)
326 c.Check(code < 500, check.Equals, true)
327 if tok == arvadostest.SpectatorToken {
328 // Valid token never offers to retry
329 // with different credentials.
330 c.Check(code, check.Equals, http.StatusNotFound)
332 // Invalid token can ask to retry
333 // depending on the authz method.
334 c.Check(code, check.Equals, failCode)
337 c.Check(body, check.Equals, notFoundMessage+"\n")
339 c.Check(body, check.Equals, unauthorizedMessage+"\n")
345 func (s *IntegrationSuite) TestVhostPortMatch(c *check.C) {
346 for _, host := range []string{"download.example.com", "DOWNLOAD.EXAMPLE.COM"} {
347 for _, port := range []string{"80", "443", "8000"} {
348 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = fmt.Sprintf("download.example.com:%v", port)
349 u := mustParseURL(fmt.Sprintf("http://%v/by_id/%v/foo", host, arvadostest.FooCollection))
350 req := &http.Request{
354 RequestURI: u.RequestURI(),
355 Header: http.Header{"Authorization": []string{"Bearer " + arvadostest.ActiveToken}},
357 req, resp := s.doReq(req)
358 code, _ := resp.Code, resp.Body.String()
361 c.Check(code, check.Equals, 401)
363 c.Check(code, check.Equals, 200)
369 func (s *IntegrationSuite) doReq(req *http.Request) (*http.Request, *httptest.ResponseRecorder) {
370 resp := httptest.NewRecorder()
371 s.handler.ServeHTTP(resp, req)
372 if resp.Code != http.StatusSeeOther {
375 cookies := (&http.Response{Header: resp.Header()}).Cookies()
376 u, _ := req.URL.Parse(resp.Header().Get("Location"))
381 RequestURI: u.RequestURI(),
382 Header: http.Header{},
384 for _, c := range cookies {
390 func (s *IntegrationSuite) TestVhostRedirectQueryTokenToCookie(c *check.C) {
391 s.testVhostRedirectTokenToCookie(c, "GET",
392 arvadostest.FooCollection+".example.com/foo",
393 "?api_token="+arvadostest.ActiveToken,
401 func (s *IntegrationSuite) TestSingleOriginSecretLink(c *check.C) {
402 s.testVhostRedirectTokenToCookie(c, "GET",
403 "example.com/c="+arvadostest.FooCollection+"/t="+arvadostest.ActiveToken+"/foo",
412 // Bad token in URL is 404 Not Found because it doesn't make sense to
413 // retry the same URL with different authorization.
414 func (s *IntegrationSuite) TestSingleOriginSecretLinkBadToken(c *check.C) {
415 s.testVhostRedirectTokenToCookie(c, "GET",
416 "example.com/c="+arvadostest.FooCollection+"/t=bogus/foo",
421 notFoundMessage+"\n",
425 // Bad token in a cookie (even if it got there via our own
426 // query-string-to-cookie redirect) is, in principle, retryable via
427 // wb2-login-and-redirect flow.
428 func (s *IntegrationSuite) TestVhostRedirectQueryTokenToBogusCookie(c *check.C) {
430 resp := s.testVhostRedirectTokenToCookie(c, "GET",
431 arvadostest.FooCollection+".example.com/foo",
432 "?api_token=thisisabogustoken",
433 http.Header{"Sec-Fetch-Mode": {"navigate"}},
438 u, err := url.Parse(resp.Header().Get("Location"))
439 c.Assert(err, check.IsNil)
440 c.Logf("redirected to %s", u)
441 c.Check(u.Host, check.Equals, s.handler.Cluster.Services.Workbench2.ExternalURL.Host)
442 c.Check(u.Query().Get("redirectToPreview"), check.Equals, "/c="+arvadostest.FooCollection+"/foo")
443 c.Check(u.Query().Get("redirectToDownload"), check.Equals, "")
445 // Download/attachment indicated by ?disposition=attachment
446 resp = s.testVhostRedirectTokenToCookie(c, "GET",
447 arvadostest.FooCollection+".example.com/foo",
448 "?api_token=thisisabogustoken&disposition=attachment",
449 http.Header{"Sec-Fetch-Mode": {"navigate"}},
454 u, err = url.Parse(resp.Header().Get("Location"))
455 c.Assert(err, check.IsNil)
456 c.Logf("redirected to %s", u)
457 c.Check(u.Host, check.Equals, s.handler.Cluster.Services.Workbench2.ExternalURL.Host)
458 c.Check(u.Query().Get("redirectToPreview"), check.Equals, "")
459 c.Check(u.Query().Get("redirectToDownload"), check.Equals, "/c="+arvadostest.FooCollection+"/foo")
461 // Download/attachment indicated by vhost
462 resp = s.testVhostRedirectTokenToCookie(c, "GET",
463 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host+"/c="+arvadostest.FooCollection+"/foo",
464 "?api_token=thisisabogustoken",
465 http.Header{"Sec-Fetch-Mode": {"navigate"}},
470 u, err = url.Parse(resp.Header().Get("Location"))
471 c.Assert(err, check.IsNil)
472 c.Logf("redirected to %s", u)
473 c.Check(u.Host, check.Equals, s.handler.Cluster.Services.Workbench2.ExternalURL.Host)
474 c.Check(u.Query().Get("redirectToPreview"), check.Equals, "")
475 c.Check(u.Query().Get("redirectToDownload"), check.Equals, "/c="+arvadostest.FooCollection+"/foo")
477 // Without "Sec-Fetch-Mode: navigate" header, just 401.
478 s.testVhostRedirectTokenToCookie(c, "GET",
479 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host+"/c="+arvadostest.FooCollection+"/foo",
480 "?api_token=thisisabogustoken",
481 http.Header{"Sec-Fetch-Mode": {"cors"}},
483 http.StatusUnauthorized,
484 unauthorizedMessage+"\n",
486 s.testVhostRedirectTokenToCookie(c, "GET",
487 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host+"/c="+arvadostest.FooCollection+"/foo",
488 "?api_token=thisisabogustoken",
491 http.StatusUnauthorized,
492 unauthorizedMessage+"\n",
496 func (s *IntegrationSuite) TestVhostRedirectQueryTokenSingleOriginError(c *check.C) {
497 s.testVhostRedirectTokenToCookie(c, "GET",
498 "example.com/c="+arvadostest.FooCollection+"/foo",
499 "?api_token="+arvadostest.ActiveToken,
502 http.StatusBadRequest,
503 "cannot serve inline content at this URL (possible configuration error; see https://doc.arvados.org/install/install-keep-web.html#dns)\n",
507 // If client requests an attachment by putting ?disposition=attachment
508 // in the query string, and gets redirected, the redirect target
509 // should respond with an attachment.
510 func (s *IntegrationSuite) TestVhostRedirectQueryTokenRequestAttachment(c *check.C) {
511 resp := s.testVhostRedirectTokenToCookie(c, "GET",
512 arvadostest.FooCollection+".example.com/foo",
513 "?disposition=attachment&api_token="+arvadostest.ActiveToken,
519 c.Check(resp.Header().Get("Content-Disposition"), check.Matches, "attachment(;.*)?")
522 func (s *IntegrationSuite) TestVhostRedirectQueryTokenSiteFS(c *check.C) {
523 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
524 resp := s.testVhostRedirectTokenToCookie(c, "GET",
525 "download.example.com/by_id/"+arvadostest.FooCollection+"/foo",
526 "?api_token="+arvadostest.ActiveToken,
532 c.Check(resp.Header().Get("Content-Disposition"), check.Matches, "attachment(;.*)?")
535 func (s *IntegrationSuite) TestPastCollectionVersionFileAccess(c *check.C) {
536 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
537 resp := s.testVhostRedirectTokenToCookie(c, "GET",
538 "download.example.com/c="+arvadostest.WazVersion1Collection+"/waz",
539 "?api_token="+arvadostest.ActiveToken,
545 c.Check(resp.Header().Get("Content-Disposition"), check.Matches, "attachment(;.*)?")
546 resp = s.testVhostRedirectTokenToCookie(c, "GET",
547 "download.example.com/by_id/"+arvadostest.WazVersion1Collection+"/waz",
548 "?api_token="+arvadostest.ActiveToken,
554 c.Check(resp.Header().Get("Content-Disposition"), check.Matches, "attachment(;.*)?")
557 func (s *IntegrationSuite) TestVhostRedirectQueryTokenTrustAllContent(c *check.C) {
558 s.handler.Cluster.Collections.TrustAllContent = true
559 s.testVhostRedirectTokenToCookie(c, "GET",
560 "example.com/c="+arvadostest.FooCollection+"/foo",
561 "?api_token="+arvadostest.ActiveToken,
569 func (s *IntegrationSuite) TestVhostRedirectQueryTokenAttachmentOnlyHost(c *check.C) {
570 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "example.com:1234"
572 s.testVhostRedirectTokenToCookie(c, "GET",
573 "example.com/c="+arvadostest.FooCollection+"/foo",
574 "?api_token="+arvadostest.ActiveToken,
577 http.StatusBadRequest,
578 "cannot serve inline content at this URL (possible configuration error; see https://doc.arvados.org/install/install-keep-web.html#dns)\n",
581 resp := s.testVhostRedirectTokenToCookie(c, "GET",
582 "example.com:1234/c="+arvadostest.FooCollection+"/foo",
583 "?api_token="+arvadostest.ActiveToken,
589 c.Check(resp.Header().Get("Content-Disposition"), check.Equals, "attachment")
592 func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie(c *check.C) {
593 s.testVhostRedirectTokenToCookie(c, "POST",
594 arvadostest.FooCollection+".example.com/foo",
596 http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
597 url.Values{"api_token": {arvadostest.ActiveToken}}.Encode(),
603 func (s *IntegrationSuite) TestVhostRedirectPOSTFormTokenToCookie404(c *check.C) {
604 s.testVhostRedirectTokenToCookie(c, "POST",
605 arvadostest.FooCollection+".example.com/foo",
607 http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
608 url.Values{"api_token": {arvadostest.SpectatorToken}}.Encode(),
610 notFoundMessage+"\n",
614 func (s *IntegrationSuite) TestAnonymousTokenOK(c *check.C) {
615 s.handler.Cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
616 s.testVhostRedirectTokenToCookie(c, "GET",
617 "example.com/c="+arvadostest.HelloWorldCollection+"/Hello%20world.txt",
626 func (s *IntegrationSuite) TestAnonymousTokenError(c *check.C) {
627 s.handler.Cluster.Users.AnonymousUserToken = "anonymousTokenConfiguredButInvalid"
628 s.testVhostRedirectTokenToCookie(c, "GET",
629 "example.com/c="+arvadostest.HelloWorldCollection+"/Hello%20world.txt",
634 notFoundMessage+"\n",
638 func (s *IntegrationSuite) TestSpecialCharsInPath(c *check.C) {
639 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
641 client := arvados.NewClientFromEnv()
642 client.AuthToken = arvadostest.ActiveToken
643 fs, err := (&arvados.Collection{}).FileSystem(client, nil)
644 c.Assert(err, check.IsNil)
645 f, err := fs.OpenFile("https:\\\"odd' path chars", os.O_CREATE, 0777)
646 c.Assert(err, check.IsNil)
648 mtxt, err := fs.MarshalManifest(".")
649 c.Assert(err, check.IsNil)
650 var coll arvados.Collection
651 err = client.RequestAndDecode(&coll, "POST", "arvados/v1/collections", nil, map[string]interface{}{
652 "collection": map[string]string{
653 "manifest_text": mtxt,
656 c.Assert(err, check.IsNil)
658 u, _ := url.Parse("http://download.example.com/c=" + coll.UUID + "/")
659 req := &http.Request{
663 RequestURI: u.RequestURI(),
665 "Authorization": {"Bearer " + client.AuthToken},
668 resp := httptest.NewRecorder()
669 s.handler.ServeHTTP(resp, req)
670 c.Check(resp.Code, check.Equals, http.StatusOK)
671 c.Check(resp.Body.String(), check.Matches, `(?ms).*href="./https:%5c%22odd%27%20path%20chars"\S+https:\\"odd' path chars.*`)
674 func (s *IntegrationSuite) TestForwardSlashSubstitution(c *check.C) {
675 arv := arvados.NewClientFromEnv()
676 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
677 s.handler.Cluster.Collections.ForwardSlashNameSubstitution = "{SOLIDUS}"
678 name := "foo/bar/baz"
679 nameShown := strings.Replace(name, "/", "{SOLIDUS}", -1)
680 nameShownEscaped := strings.Replace(name, "/", "%7bSOLIDUS%7d", -1)
682 client := arvados.NewClientFromEnv()
683 client.AuthToken = arvadostest.ActiveToken
684 fs, err := (&arvados.Collection{}).FileSystem(client, nil)
685 c.Assert(err, check.IsNil)
686 f, err := fs.OpenFile("filename", os.O_CREATE, 0777)
687 c.Assert(err, check.IsNil)
689 mtxt, err := fs.MarshalManifest(".")
690 c.Assert(err, check.IsNil)
691 var coll arvados.Collection
692 err = client.RequestAndDecode(&coll, "POST", "arvados/v1/collections", nil, map[string]interface{}{
693 "collection": map[string]string{
694 "manifest_text": mtxt,
696 "owner_uuid": arvadostest.AProjectUUID,
699 c.Assert(err, check.IsNil)
700 defer arv.RequestAndDecode(&coll, "DELETE", "arvados/v1/collections/"+coll.UUID, nil, nil)
702 base := "http://download.example.com/by_id/" + coll.OwnerUUID + "/"
703 for tryURL, expectRegexp := range map[string]string{
704 base: `(?ms).*href="./` + nameShownEscaped + `/"\S+` + nameShown + `.*`,
705 base + nameShownEscaped + "/": `(?ms).*href="./filename"\S+filename.*`,
707 u, _ := url.Parse(tryURL)
708 req := &http.Request{
712 RequestURI: u.RequestURI(),
714 "Authorization": {"Bearer " + client.AuthToken},
717 resp := httptest.NewRecorder()
718 s.handler.ServeHTTP(resp, req)
719 c.Check(resp.Code, check.Equals, http.StatusOK)
720 c.Check(resp.Body.String(), check.Matches, expectRegexp)
724 // XHRs can't follow redirect-with-cookie so they rely on method=POST
725 // and disposition=attachment (telling us it's acceptable to respond
726 // with content instead of a redirect) and an Origin header that gets
727 // added automatically by the browser (telling us it's desirable to do
729 func (s *IntegrationSuite) TestXHRNoRedirect(c *check.C) {
730 u, _ := url.Parse("http://example.com/c=" + arvadostest.FooCollection + "/foo")
731 req := &http.Request{
735 RequestURI: u.RequestURI(),
737 "Origin": {"https://origin.example"},
738 "Content-Type": {"application/x-www-form-urlencoded"},
740 Body: ioutil.NopCloser(strings.NewReader(url.Values{
741 "api_token": {arvadostest.ActiveToken},
742 "disposition": {"attachment"},
745 resp := httptest.NewRecorder()
746 s.handler.ServeHTTP(resp, req)
747 c.Check(resp.Code, check.Equals, http.StatusOK)
748 c.Check(resp.Body.String(), check.Equals, "foo")
749 c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, "*")
751 // GET + Origin header is representative of both AJAX GET
752 // requests and inline images via <IMG crossorigin="anonymous"
754 u.RawQuery = "api_token=" + url.QueryEscape(arvadostest.ActiveTokenV2)
759 RequestURI: u.RequestURI(),
761 "Origin": {"https://origin.example"},
764 resp = httptest.NewRecorder()
765 s.handler.ServeHTTP(resp, req)
766 c.Check(resp.Code, check.Equals, http.StatusOK)
767 c.Check(resp.Body.String(), check.Equals, "foo")
768 c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, "*")
771 func (s *IntegrationSuite) testVhostRedirectTokenToCookie(c *check.C, method, hostPath, queryString string, reqHeader http.Header, reqBody string, expectStatus int, expectRespBody string) *httptest.ResponseRecorder {
772 if reqHeader == nil {
773 reqHeader = http.Header{}
775 u, _ := url.Parse(`http://` + hostPath + queryString)
776 c.Logf("requesting %s", u)
777 req := &http.Request{
781 RequestURI: u.RequestURI(),
783 Body: ioutil.NopCloser(strings.NewReader(reqBody)),
786 resp := httptest.NewRecorder()
788 c.Check(resp.Code, check.Equals, expectStatus)
789 c.Check(resp.Body.String(), check.Equals, expectRespBody)
792 s.handler.ServeHTTP(resp, req)
793 if resp.Code != http.StatusSeeOther {
796 c.Check(resp.Body.String(), check.Matches, `.*href="http://`+regexp.QuoteMeta(html.EscapeString(hostPath))+`(\?[^"]*)?".*`)
797 c.Check(strings.Split(resp.Header().Get("Location"), "?")[0], check.Equals, "http://"+hostPath)
798 cookies := (&http.Response{Header: resp.Header()}).Cookies()
800 u, err := u.Parse(resp.Header().Get("Location"))
801 c.Assert(err, check.IsNil)
802 c.Logf("following redirect to %s", u)
807 RequestURI: u.RequestURI(),
810 for _, c := range cookies {
814 resp = httptest.NewRecorder()
815 s.handler.ServeHTTP(resp, req)
817 if resp.Code != http.StatusSeeOther {
818 c.Check(resp.Header().Get("Location"), check.Equals, "")
823 func (s *IntegrationSuite) TestDirectoryListingWithAnonymousToken(c *check.C) {
824 s.handler.Cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
825 s.testDirectoryListing(c)
828 func (s *IntegrationSuite) TestDirectoryListingWithNoAnonymousToken(c *check.C) {
829 s.handler.Cluster.Users.AnonymousUserToken = ""
830 s.testDirectoryListing(c)
833 func (s *IntegrationSuite) testDirectoryListing(c *check.C) {
834 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
835 authHeader := http.Header{
836 "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
838 for _, trial := range []struct {
846 uri: strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/",
848 expect: []string{"dir1/foo", "dir1/bar"},
852 uri: strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + ".example.com/dir1/",
854 expect: []string{"foo", "bar"},
858 // URLs of this form ignore authHeader, and
859 // FooAndBarFilesInDirUUID isn't public, so
861 uri: "download.example.com/collections/" + arvadostest.FooAndBarFilesInDirUUID + "/",
866 uri: "download.example.com/users/active/foo_file_in_dir/",
868 expect: []string{"dir1/"},
872 uri: "download.example.com/users/active/foo_file_in_dir/dir1/",
874 expect: []string{"bar"},
878 uri: "download.example.com/",
880 expect: []string{"users/"},
884 uri: "download.example.com/users",
887 expect: []string{"active/"},
891 uri: "download.example.com/users/",
893 expect: []string{"active/"},
897 uri: "download.example.com/users/active",
899 redirect: "/users/active/",
900 expect: []string{"foo_file_in_dir/"},
904 uri: "download.example.com/users/active/",
906 expect: []string{"foo_file_in_dir/"},
910 uri: "collections.example.com/collections/download/" + arvadostest.FooAndBarFilesInDirUUID + "/" + arvadostest.ActiveToken + "/",
912 expect: []string{"dir1/foo", "dir1/bar"},
916 uri: "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/",
918 expect: []string{"dir1/foo", "dir1/bar"},
922 uri: "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken,
924 expect: []string{"dir1/foo", "dir1/bar"},
928 uri: "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID,
930 expect: []string{"dir1/foo", "dir1/bar"},
934 uri: "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/dir1",
936 redirect: "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/dir1/",
937 expect: []string{"foo", "bar"},
941 uri: "download.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/_/dir1/",
943 expect: []string{"foo", "bar"},
947 uri: arvadostest.FooAndBarFilesInDirUUID + ".example.com/dir1?api_token=" + arvadostest.ActiveToken,
950 expect: []string{"foo", "bar"},
954 uri: "collections.example.com/c=" + arvadostest.FooAndBarFilesInDirUUID + "/theperthcountyconspiracydoesnotexist/",
959 uri: "download.example.com/c=" + arvadostest.WazVersion1Collection,
961 expect: []string{"waz"},
965 uri: "download.example.com/by_id/" + arvadostest.WazVersion1Collection,
967 expect: []string{"waz"},
971 comment := check.Commentf("HTML: %q => %q", trial.uri, trial.expect)
972 resp := httptest.NewRecorder()
973 u := mustParseURL("//" + trial.uri)
974 req := &http.Request{
978 RequestURI: u.RequestURI(),
979 Header: copyHeader(trial.header),
981 s.handler.ServeHTTP(resp, req)
982 var cookies []*http.Cookie
983 for resp.Code == http.StatusSeeOther {
984 u, _ := req.URL.Parse(resp.Header().Get("Location"))
989 RequestURI: u.RequestURI(),
990 Header: copyHeader(trial.header),
992 cookies = append(cookies, (&http.Response{Header: resp.Header()}).Cookies()...)
993 for _, c := range cookies {
996 resp = httptest.NewRecorder()
997 s.handler.ServeHTTP(resp, req)
999 if trial.redirect != "" {
1000 c.Check(req.URL.Path, check.Equals, trial.redirect, comment)
1002 if trial.expect == nil {
1003 if s.handler.Cluster.Users.AnonymousUserToken == "" {
1004 c.Check(resp.Code, check.Equals, http.StatusUnauthorized, comment)
1006 c.Check(resp.Code, check.Equals, http.StatusNotFound, comment)
1009 c.Check(resp.Code, check.Equals, http.StatusOK, comment)
1010 for _, e := range trial.expect {
1011 c.Check(resp.Body.String(), check.Matches, `(?ms).*href="./`+e+`".*`, comment)
1013 c.Check(resp.Body.String(), check.Matches, `(?ms).*--cut-dirs=`+fmt.Sprintf("%d", trial.cutDirs)+` .*`, comment)
1016 comment = check.Commentf("WebDAV: %q => %q", trial.uri, trial.expect)
1017 req = &http.Request{
1021 RequestURI: u.RequestURI(),
1022 Header: copyHeader(trial.header),
1023 Body: ioutil.NopCloser(&bytes.Buffer{}),
1025 resp = httptest.NewRecorder()
1026 s.handler.ServeHTTP(resp, req)
1027 if trial.expect == nil {
1028 if s.handler.Cluster.Users.AnonymousUserToken == "" {
1029 c.Check(resp.Code, check.Equals, http.StatusUnauthorized, comment)
1031 c.Check(resp.Code, check.Equals, http.StatusNotFound, comment)
1034 c.Check(resp.Code, check.Equals, http.StatusOK, comment)
1037 req = &http.Request{
1041 RequestURI: u.RequestURI(),
1042 Header: copyHeader(trial.header),
1043 Body: ioutil.NopCloser(&bytes.Buffer{}),
1045 resp = httptest.NewRecorder()
1046 s.handler.ServeHTTP(resp, req)
1047 if trial.expect == nil {
1048 if s.handler.Cluster.Users.AnonymousUserToken == "" {
1049 c.Check(resp.Code, check.Equals, http.StatusUnauthorized, comment)
1051 c.Check(resp.Code, check.Equals, http.StatusNotFound, comment)
1054 c.Check(resp.Code, check.Equals, http.StatusMultiStatus, comment)
1055 for _, e := range trial.expect {
1056 if strings.HasSuffix(e, "/") {
1057 e = filepath.Join(u.Path, e) + "/"
1059 e = filepath.Join(u.Path, e)
1061 c.Check(resp.Body.String(), check.Matches, `(?ms).*<D:href>`+e+`</D:href>.*`, comment)
1067 func (s *IntegrationSuite) TestDeleteLastFile(c *check.C) {
1068 arv := arvados.NewClientFromEnv()
1069 var newCollection arvados.Collection
1070 err := arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{
1071 "collection": map[string]string{
1072 "owner_uuid": arvadostest.ActiveUserUUID,
1073 "manifest_text": ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt 0:3:bar.txt\n",
1074 "name": "keep-web test collection",
1076 "ensure_unique_name": true,
1078 c.Assert(err, check.IsNil)
1079 defer arv.RequestAndDecode(&newCollection, "DELETE", "arvados/v1/collections/"+newCollection.UUID, nil, nil)
1081 var updated arvados.Collection
1082 for _, fnm := range []string{"foo.txt", "bar.txt"} {
1083 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "example.com"
1084 u, _ := url.Parse("http://example.com/c=" + newCollection.UUID + "/" + fnm)
1085 req := &http.Request{
1089 RequestURI: u.RequestURI(),
1090 Header: http.Header{
1091 "Authorization": {"Bearer " + arvadostest.ActiveToken},
1094 resp := httptest.NewRecorder()
1095 s.handler.ServeHTTP(resp, req)
1096 c.Check(resp.Code, check.Equals, http.StatusNoContent)
1098 updated = arvados.Collection{}
1099 err = arv.RequestAndDecode(&updated, "GET", "arvados/v1/collections/"+newCollection.UUID, nil, nil)
1100 c.Check(err, check.IsNil)
1101 c.Check(updated.ManifestText, check.Not(check.Matches), `(?ms).*\Q`+fnm+`\E.*`)
1102 c.Logf("updated manifest_text %q", updated.ManifestText)
1104 c.Check(updated.ManifestText, check.Equals, "")
1107 func (s *IntegrationSuite) TestFileContentType(c *check.C) {
1108 s.handler.Cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
1110 client := arvados.NewClientFromEnv()
1111 client.AuthToken = arvadostest.ActiveToken
1112 arv, err := arvadosclient.New(client)
1113 c.Assert(err, check.Equals, nil)
1114 kc, err := keepclient.MakeKeepClient(arv)
1115 c.Assert(err, check.Equals, nil)
1117 fs, err := (&arvados.Collection{}).FileSystem(client, kc)
1118 c.Assert(err, check.IsNil)
1120 trials := []struct {
1125 {"picture.txt", "BMX bikes are small this year\n", "text/plain; charset=utf-8"},
1126 {"picture.bmp", "BMX bikes are small this year\n", "image/(x-ms-)?bmp"},
1127 {"picture.jpg", "BMX bikes are small this year\n", "image/jpeg"},
1128 {"picture1", "BMX bikes are small this year\n", "image/bmp"}, // content sniff; "BM" is the magic signature for .bmp
1129 {"picture2", "Cars are small this year\n", "text/plain; charset=utf-8"}, // content sniff
1131 for _, trial := range trials {
1132 f, err := fs.OpenFile(trial.filename, os.O_CREATE|os.O_WRONLY, 0777)
1133 c.Assert(err, check.IsNil)
1134 _, err = f.Write([]byte(trial.content))
1135 c.Assert(err, check.IsNil)
1136 c.Assert(f.Close(), check.IsNil)
1138 mtxt, err := fs.MarshalManifest(".")
1139 c.Assert(err, check.IsNil)
1140 var coll arvados.Collection
1141 err = client.RequestAndDecode(&coll, "POST", "arvados/v1/collections", nil, map[string]interface{}{
1142 "collection": map[string]string{
1143 "manifest_text": mtxt,
1146 c.Assert(err, check.IsNil)
1148 for _, trial := range trials {
1149 u, _ := url.Parse("http://download.example.com/by_id/" + coll.UUID + "/" + trial.filename)
1150 req := &http.Request{
1154 RequestURI: u.RequestURI(),
1155 Header: http.Header{
1156 "Authorization": {"Bearer " + client.AuthToken},
1159 resp := httptest.NewRecorder()
1160 s.handler.ServeHTTP(resp, req)
1161 c.Check(resp.Code, check.Equals, http.StatusOK)
1162 c.Check(resp.Header().Get("Content-Type"), check.Matches, trial.contentType)
1163 c.Check(resp.Body.String(), check.Equals, trial.content)
1167 func (s *IntegrationSuite) TestKeepClientBlockCache(c *check.C) {
1168 s.handler.Cluster.Collections.WebDAVCache.MaxBlockEntries = 42
1169 c.Check(keepclient.DefaultBlockCache.MaxBlocks, check.Not(check.Equals), 42)
1170 u := mustParseURL("http://keep-web.example/c=" + arvadostest.FooCollection + "/t=" + arvadostest.ActiveToken + "/foo")
1171 req := &http.Request{
1175 RequestURI: u.RequestURI(),
1177 resp := httptest.NewRecorder()
1178 s.handler.ServeHTTP(resp, req)
1179 c.Check(resp.Code, check.Equals, http.StatusOK)
1180 c.Check(keepclient.DefaultBlockCache.MaxBlocks, check.Equals, 42)
1183 // Writing to a collection shouldn't affect its entry in the
1184 // PDH-to-manifest cache.
1185 func (s *IntegrationSuite) TestCacheWriteCollectionSamePDH(c *check.C) {
1186 arv, err := arvadosclient.MakeArvadosClient()
1187 c.Assert(err, check.Equals, nil)
1188 arv.ApiToken = arvadostest.ActiveToken
1190 u := mustParseURL("http://x.example/testfile")
1191 req := &http.Request{
1195 RequestURI: u.RequestURI(),
1196 Header: http.Header{"Authorization": {"Bearer " + arv.ApiToken}},
1199 checkWithID := func(id string, status int) {
1200 req.URL.Host = strings.Replace(id, "+", "-", -1) + ".example"
1201 req.Host = req.URL.Host
1202 resp := httptest.NewRecorder()
1203 s.handler.ServeHTTP(resp, req)
1204 c.Check(resp.Code, check.Equals, status)
1207 var colls [2]arvados.Collection
1208 for i := range colls {
1209 err := arv.Create("collections",
1210 map[string]interface{}{
1211 "ensure_unique_name": true,
1212 "collection": map[string]interface{}{
1213 "name": "test collection",
1216 c.Assert(err, check.Equals, nil)
1219 // Populate cache with empty collection
1220 checkWithID(colls[0].PortableDataHash, http.StatusNotFound)
1222 // write a file to colls[0]
1224 reqPut.Method = "PUT"
1225 reqPut.URL.Host = colls[0].UUID + ".example"
1226 reqPut.Host = req.URL.Host
1227 reqPut.Body = ioutil.NopCloser(bytes.NewBufferString("testdata"))
1228 resp := httptest.NewRecorder()
1229 s.handler.ServeHTTP(resp, &reqPut)
1230 c.Check(resp.Code, check.Equals, http.StatusCreated)
1232 // new file should not appear in colls[1]
1233 checkWithID(colls[1].PortableDataHash, http.StatusNotFound)
1234 checkWithID(colls[1].UUID, http.StatusNotFound)
1236 checkWithID(colls[0].UUID, http.StatusOK)
1239 func copyHeader(h http.Header) http.Header {
1241 for k, v := range h {
1242 hc[k] = append([]string(nil), v...)
1247 func (s *IntegrationSuite) checkUploadDownloadRequest(c *check.C, req *http.Request,
1248 successCode int, direction string, perm bool, userUuid string, collectionUuid string, filepath string) {
1250 client := arvados.NewClientFromEnv()
1251 client.AuthToken = arvadostest.AdminToken
1252 var logentries arvados.LogList
1254 err := client.RequestAndDecode(&logentries, "GET", "arvados/v1/logs", nil,
1255 arvados.ResourceListParams{
1257 Order: "created_at desc"})
1258 c.Check(err, check.IsNil)
1259 c.Check(logentries.Items, check.HasLen, 1)
1260 lastLogId := logentries.Items[0].ID
1262 var logbuf bytes.Buffer
1263 logger := logrus.New()
1264 logger.Out = &logbuf
1265 resp := httptest.NewRecorder()
1266 req = req.WithContext(ctxlog.Context(context.Background(), logger))
1267 s.handler.ServeHTTP(resp, req)
1270 c.Check(resp.Result().StatusCode, check.Equals, successCode)
1271 c.Check(logbuf.String(), check.Matches, `(?ms).*msg="File `+direction+`".*`)
1272 c.Check(logbuf.String(), check.Not(check.Matches), `(?ms).*level=error.*`)
1274 deadline := time.Now().Add(time.Second)
1276 c.Assert(time.Now().After(deadline), check.Equals, false, check.Commentf("timed out waiting for log entry"))
1277 err = client.RequestAndDecode(&logentries, "GET", "arvados/v1/logs", nil,
1278 arvados.ResourceListParams{
1279 Filters: []arvados.Filter{
1280 {Attr: "event_type", Operator: "=", Operand: "file_" + direction},
1281 {Attr: "object_uuid", Operator: "=", Operand: userUuid},
1284 Order: "created_at desc",
1286 c.Assert(err, check.IsNil)
1287 if len(logentries.Items) > 0 &&
1288 logentries.Items[0].ID > lastLogId &&
1289 logentries.Items[0].ObjectUUID == userUuid &&
1290 logentries.Items[0].Properties["collection_uuid"] == collectionUuid &&
1291 logentries.Items[0].Properties["collection_file_path"] == filepath {
1294 c.Logf("logentries.Items: %+v", logentries.Items)
1295 time.Sleep(50 * time.Millisecond)
1298 c.Check(resp.Result().StatusCode, check.Equals, http.StatusForbidden)
1299 c.Check(logbuf.String(), check.Equals, "")
1303 func (s *IntegrationSuite) TestDownloadLoggingPermission(c *check.C) {
1304 u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo")
1306 s.handler.Cluster.Collections.TrustAllContent = true
1308 for _, adminperm := range []bool{true, false} {
1309 for _, userperm := range []bool{true, false} {
1310 s.handler.Cluster.Collections.WebDAVPermission.Admin.Download = adminperm
1311 s.handler.Cluster.Collections.WebDAVPermission.User.Download = userperm
1313 // Test admin permission
1314 req := &http.Request{
1318 RequestURI: u.RequestURI(),
1319 Header: http.Header{
1320 "Authorization": {"Bearer " + arvadostest.AdminToken},
1323 s.checkUploadDownloadRequest(c, req, http.StatusOK, "download", adminperm,
1324 arvadostest.AdminUserUUID, arvadostest.FooCollection, "foo")
1326 // Test user permission
1327 req = &http.Request{
1331 RequestURI: u.RequestURI(),
1332 Header: http.Header{
1333 "Authorization": {"Bearer " + arvadostest.ActiveToken},
1336 s.checkUploadDownloadRequest(c, req, http.StatusOK, "download", userperm,
1337 arvadostest.ActiveUserUUID, arvadostest.FooCollection, "foo")
1341 s.handler.Cluster.Collections.WebDAVPermission.User.Download = true
1343 for _, tryurl := range []string{"http://" + arvadostest.MultilevelCollection1 + ".keep-web.example/dir1/subdir/file1",
1344 "http://keep-web/users/active/multilevel_collection_1/dir1/subdir/file1"} {
1346 u = mustParseURL(tryurl)
1347 req := &http.Request{
1351 RequestURI: u.RequestURI(),
1352 Header: http.Header{
1353 "Authorization": {"Bearer " + arvadostest.ActiveToken},
1356 s.checkUploadDownloadRequest(c, req, http.StatusOK, "download", true,
1357 arvadostest.ActiveUserUUID, arvadostest.MultilevelCollection1, "dir1/subdir/file1")
1360 u = mustParseURL("http://" + strings.Replace(arvadostest.FooCollectionPDH, "+", "-", 1) + ".keep-web.example/foo")
1361 req := &http.Request{
1365 RequestURI: u.RequestURI(),
1366 Header: http.Header{
1367 "Authorization": {"Bearer " + arvadostest.ActiveToken},
1370 s.checkUploadDownloadRequest(c, req, http.StatusOK, "download", true,
1371 arvadostest.ActiveUserUUID, arvadostest.FooCollection, "foo")
1374 func (s *IntegrationSuite) TestUploadLoggingPermission(c *check.C) {
1375 for _, adminperm := range []bool{true, false} {
1376 for _, userperm := range []bool{true, false} {
1378 arv := arvados.NewClientFromEnv()
1379 arv.AuthToken = arvadostest.ActiveToken
1381 var coll arvados.Collection
1382 err := arv.RequestAndDecode(&coll,
1384 "/arvados/v1/collections",
1386 map[string]interface{}{
1387 "ensure_unique_name": true,
1388 "collection": map[string]interface{}{
1389 "name": "test collection",
1392 c.Assert(err, check.Equals, nil)
1394 u := mustParseURL("http://" + coll.UUID + ".keep-web.example/bar")
1396 s.handler.Cluster.Collections.WebDAVPermission.Admin.Upload = adminperm
1397 s.handler.Cluster.Collections.WebDAVPermission.User.Upload = userperm
1399 // Test admin permission
1400 req := &http.Request{
1404 RequestURI: u.RequestURI(),
1405 Header: http.Header{
1406 "Authorization": {"Bearer " + arvadostest.AdminToken},
1408 Body: io.NopCloser(bytes.NewReader([]byte("bar"))),
1410 s.checkUploadDownloadRequest(c, req, http.StatusCreated, "upload", adminperm,
1411 arvadostest.AdminUserUUID, coll.UUID, "bar")
1413 // Test user permission
1414 req = &http.Request{
1418 RequestURI: u.RequestURI(),
1419 Header: http.Header{
1420 "Authorization": {"Bearer " + arvadostest.ActiveToken},
1422 Body: io.NopCloser(bytes.NewReader([]byte("bar"))),
1424 s.checkUploadDownloadRequest(c, req, http.StatusCreated, "upload", userperm,
1425 arvadostest.ActiveUserUUID, coll.UUID, "bar")