14716: Fixes config type init function naming.
[arvados.git] / services / keep-web / handler_test.go
index 3863265613f883b7c190584002b504f35fb43b44..1d264fc052772809534b0a2db174ca3e91fc3604 100644 (file)
@@ -31,14 +31,15 @@ type UnitSuite struct {
 }
 
 func (s *UnitSuite) SetUpTest(c *check.C) {
-       ldr := config.NewLoader(nil, nil)
-       cfg, err := ldr.LoadDefaults()
+       ldr := config.NewLoader(bytes.NewBufferString("Clusters: {zzzzz: {}}"), nil)
+       ldr.Path = "-"
+       cfg, err := ldr.Load()
        c.Assert(err, check.IsNil)
        s.Config = cfg
 }
 
 func (s *UnitSuite) TestCORSPreflight(c *check.C) {
-       h := handler{Config: DefaultConfig(s.Config)}
+       h := handler{Config: newConfig(s.Config)}
        u := mustParseURL("http://keep-web.example/c=" + arvadostest.FooCollection + "/foo")
        req := &http.Request{
                Method:     "OPTIONS",
@@ -88,7 +89,7 @@ func (s *UnitSuite) TestInvalidUUID(c *check.C) {
                        RequestURI: u.RequestURI(),
                }
                resp := httptest.NewRecorder()
-               cfg := DefaultConfig(s.Config)
+               cfg := newConfig(s.Config)
                cfg.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
                h := handler{Config: cfg}
                h.ServeHTTP(resp, req)
@@ -569,7 +570,17 @@ func (s *IntegrationSuite) testVhostRedirectTokenToCookie(c *check.C, method, ho
        return resp
 }
 
-func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
+func (s *IntegrationSuite) TestDirectoryListingWithAnonymousToken(c *check.C) {
+       s.testServer.Config.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
+       s.testDirectoryListing(c)
+}
+
+func (s *IntegrationSuite) TestDirectoryListingWithNoAnonymousToken(c *check.C) {
+       s.testServer.Config.cluster.Users.AnonymousUserToken = ""
+       s.testDirectoryListing(c)
+}
+
+func (s *IntegrationSuite) testDirectoryListing(c *check.C) {
        s.testServer.Config.cluster.Services.WebDAVDownload.ExternalURL.Host = "download.example.com"
        authHeader := http.Header{
                "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
@@ -593,13 +604,14 @@ func (s *IntegrationSuite) TestDirectoryListing(c *check.C) {
                        expect:  []string{"foo", "bar"},
                        cutDirs: 1,
                },
-               // This test case fails
-               // {
-               //      uri:     "download.example.com/collections/" + arvadostest.FooAndBarFilesInDirUUID + "/",
-               //      header:  authHeader,
-               //      expect:  []string{"dir1/foo", "dir1/bar"},
-               //      cutDirs: 2,
-               // },
+               {
+                       // URLs of this form ignore authHeader, and
+                       // FooAndBarFilesInDirUUID isn't public, so
+                       // this returns 404.
+                       uri:    "download.example.com/collections/" + arvadostest.FooAndBarFilesInDirUUID + "/",
+                       header: authHeader,
+                       expect: nil,
+               },
                {
                        uri:     "download.example.com/users/active/foo_file_in_dir/",
                        header:  authHeader,