X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c69d271455a0550cda8e56ab6a4685fe3d7d91ea..da58ec28659f5167f9658be5714731acee57dfb1:/services/keep-web/cadaver_test.go?ds=sidebyside diff --git a/services/keep-web/cadaver_test.go b/services/keep-web/cadaver_test.go index 843a8e89d3..e965a6e8c2 100644 --- a/services/keep-web/cadaver_test.go +++ b/services/keep-web/cadaver_test.go @@ -9,15 +9,14 @@ import ( "fmt" "io" "io/ioutil" - "net/url" "os" "os/exec" "path/filepath" "strings" "time" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" ) @@ -53,6 +52,8 @@ func (s *IntegrationSuite) TestCadaverUserProject(c *check.C) { } func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc func(arvados.Collection) (string, string, string), skip func(string) bool) { + s.testServer.Config.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken + testdata := []byte("the human tragedy consists in the necessity of living with the consequences of actions performed under the pressure of compulsions we do not understand") tempdir, err := ioutil.TempDir("", "keep-web-test-") @@ -72,7 +73,7 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun var newCollection arvados.Collection arv := arvados.NewClientFromEnv() arv.AuthToken = arvadostest.ActiveToken - err = arv.RequestAndDecode(&newCollection, "POST", "/arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil) + err = arv.RequestAndDecode(&newCollection, "POST", "arvados/v1/collections", nil, map[string]interface{}{"collection": map[string]interface{}{}}) c.Assert(err, check.IsNil) readPath, writePath, pdhPath := pathFunc(newCollection) @@ -133,6 +134,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun match: `(?ms).*succeeded.*`, data: testdata, }, + { + path: writePath, + cmd: "move testfile \"test &#!%20 file\"\n", + match: `(?ms).*Moving .* succeeded.*`, + }, + { + path: writePath, + cmd: "move \"test &#!%20 file\" testfile\n", + match: `(?ms).*Moving .* succeeded.*`, + }, { path: writePath, cmd: "move testfile newdir0/\n", @@ -143,6 +154,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun cmd: "move testfile newdir0/\n", match: `(?ms).*Moving .* failed.*`, }, + { + path: writePath, + cmd: "lock newdir0/testfile\n", + match: `(?ms).*Locking .* succeeded.*`, + }, + { + path: writePath, + cmd: "unlock newdir0/testfile\nasdf\n", + match: `(?ms).*Unlocking .* succeeded.*`, + }, { path: writePath, cmd: "ls\n", @@ -158,6 +179,16 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun cmd: "mkcol newdir1\n", match: `(?ms).*Creating .* succeeded.*`, }, + { + path: writePath, + cmd: "move newdir1/ newdir1x/\n", + match: `(?ms).*Moving .* succeeded.*`, + }, + { + path: writePath, + cmd: "move newdir1x newdir1\n", + match: `(?ms).*Moving .* succeeded.*`, + }, { path: writePath, cmd: "move newdir0/testfile newdir1/\n", @@ -241,6 +272,11 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun cmd: "delete foo\n", match: `(?ms).*Deleting .* failed:.*405 Method Not Allowed.*`, }, + { + path: pdhPath, + cmd: "lock foo\n", + match: `(?ms).*Locking .* failed:.*405 Method Not Allowed.*`, + }, } { c.Logf("%s %+v", "http://"+s.testServer.Addr, trial) if skip != nil && skip(trial.path) { @@ -250,35 +286,8 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun os.Remove(checkfile.Name()) - cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path) - if password != "" { - // cadaver won't try username/password - // authentication unless the server responds - // 401 to an unauthenticated request, which it - // only does in AttachmentOnlyHost, - // TrustAllContent, and per-collection vhost - // cases. - s.testServer.Config.AttachmentOnlyHost = s.testServer.Addr - - cmd.Env = append(os.Environ(), "HOME="+tempdir) - f, err := os.OpenFile(filepath.Join(tempdir, ".netrc"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) - c.Assert(err, check.IsNil) - _, err = fmt.Fprintf(f, "default login none password %s\n", password) - c.Assert(err, check.IsNil) - c.Assert(f.Close(), check.IsNil) - } - cmd.Stdin = bytes.NewBufferString(trial.cmd) - stdout, err := cmd.StdoutPipe() - c.Assert(err, check.Equals, nil) - cmd.Stderr = cmd.Stdout - go cmd.Start() - - var buf bytes.Buffer - _, err = io.Copy(&buf, stdout) - c.Check(err, check.Equals, nil) - err = cmd.Wait() - c.Check(err, check.Equals, nil) - c.Check(buf.String(), check.Matches, trial.match) + stdout := s.runCadaver(c, password, trial.path, trial.cmd) + c.Check(stdout, check.Matches, trial.match) if trial.data == nil { continue @@ -291,3 +300,75 @@ func (s *IntegrationSuite) testCadaver(c *check.C, password string, pathFunc fun c.Check(err, check.IsNil) } } + +func (s *IntegrationSuite) TestCadaverByID(c *check.C) { + for _, path := range []string{"/by_id", "/by_id/"} { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*collection is empty.*`) + } + for _, path := range []string{ + "/by_id/" + arvadostest.FooCollectionPDH, + "/by_id/" + arvadostest.FooCollectionPDH + "/", + "/by_id/" + arvadostest.FooCollection, + "/by_id/" + arvadostest.FooCollection + "/", + } { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*\s+foo\s+3 .*`) + } +} + +func (s *IntegrationSuite) TestCadaverUsersDir(c *check.C) { + for _, path := range []string{"/"} { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*Coll:\s+by_id\s+0 .*`) + c.Check(stdout, check.Matches, `(?ms).*Coll:\s+users\s+0 .*`) + } + for _, path := range []string{"/users", "/users/"} { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*Coll:\s+active.*`) + } + for _, path := range []string{"/users/active", "/users/active/"} { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*Coll:\s+A Project\s+0 .*`) + c.Check(stdout, check.Matches, `(?ms).*Coll:\s+bar_file\s+0 .*`) + } + for _, path := range []string{"/users/admin", "/users/doesnotexist", "/users/doesnotexist/"} { + stdout := s.runCadaver(c, arvadostest.ActiveToken, path, "ls") + c.Check(stdout, check.Matches, `(?ms).*404 Not Found.*`) + } +} + +func (s *IntegrationSuite) runCadaver(c *check.C, password, path, stdin string) string { + tempdir, err := ioutil.TempDir("", "keep-web-test-") + c.Assert(err, check.IsNil) + defer os.RemoveAll(tempdir) + + cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+path) + if password != "" { + // cadaver won't try username/password authentication + // unless the server responds 401 to an + // unauthenticated request, which it only does in + // AttachmentOnlyHost, TrustAllContent, and + // per-collection vhost cases. + s.testServer.Config.cluster.Services.WebDAVDownload.ExternalURL.Host = s.testServer.Addr + + cmd.Env = append(os.Environ(), "HOME="+tempdir) + f, err := os.OpenFile(filepath.Join(tempdir, ".netrc"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) + c.Assert(err, check.IsNil) + _, err = fmt.Fprintf(f, "default login none password %s\n", password) + c.Assert(err, check.IsNil) + c.Assert(f.Close(), check.IsNil) + } + cmd.Stdin = bytes.NewBufferString(stdin) + stdout, err := cmd.StdoutPipe() + c.Assert(err, check.Equals, nil) + cmd.Stderr = cmd.Stdout + go cmd.Start() + + var buf bytes.Buffer + _, err = io.Copy(&buf, stdout) + c.Check(err, check.Equals, nil) + err = cmd.Wait() + c.Check(err, check.Equals, nil) + return buf.String() +}