X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e67d0f5d43c56f78694ea4a5f93acec5c93cd0fb..bcf069c6a726e219bc40224653268d87776e54aa:/services/keep-web/cadaver_test.go diff --git a/services/keep-web/cadaver_test.go b/services/keep-web/cadaver_test.go index 87a712f04c..d4a89c844b 100644 --- a/services/keep-web/cadaver_test.go +++ b/services/keep-web/cadaver_test.go @@ -7,42 +7,202 @@ package main import ( "bytes" "io" + "io/ioutil" + "net/url" + "os" "os/exec" + "strings" + "time" + "git.curoverse.com/arvados.git/sdk/go/arvados" "git.curoverse.com/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" ) func (s *IntegrationSuite) TestWebdavWithCadaver(c *check.C) { - basePath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/" + 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") + + localfile, err := ioutil.TempFile("", "localfile") + c.Assert(err, check.IsNil) + defer os.Remove(localfile.Name()) + localfile.Write(testdata) + + emptyfile, err := ioutil.TempFile("", "emptyfile") + c.Assert(err, check.IsNil) + defer os.Remove(emptyfile.Name()) + + checkfile, err := ioutil.TempFile("", "checkfile") + c.Assert(err, check.IsNil) + defer os.Remove(checkfile.Name()) + + 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) + c.Assert(err, check.IsNil) + writePath := "/c=" + newCollection.UUID + "/t=" + arv.AuthToken + "/" + + pdhPath := "/c=" + strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + "/t=" + arv.AuthToken + "/" + + matchToday := time.Now().Format("Jan +2") + + readPath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/" type testcase struct { path string cmd string match string + data []byte } for _, trial := range []testcase{ { - path: basePath, + path: readPath, cmd: "ls\n", match: `(?ms).*dir1 *0 .*`, }, { - path: basePath, + path: readPath, cmd: "ls dir1\n", match: `(?ms).*bar *3.*foo *3 .*`, }, { - path: basePath + "_/dir1", + path: readPath + "_/dir1", cmd: "ls\n", match: `(?ms).*bar *3.*foo *3 .*`, }, { - path: basePath + "dir1/", + path: readPath + "dir1/", cmd: "ls\n", - match: `(?ms).*bar *3.*foo *3 .*`, + match: `(?ms).*bar *3.*foo +3 +Feb +\d+ +2014.*`, + }, + { + path: writePath, + cmd: "get emptyfile '" + checkfile.Name() + "'\n", + match: `(?ms).*Not Found.*`, + }, + { + path: writePath, + cmd: "put '" + emptyfile.Name() + "' emptyfile\n", + match: `(?ms).*Uploading .* succeeded.*`, + }, + { + path: writePath, + cmd: "get emptyfile '" + checkfile.Name() + "'\n", + match: `(?ms).*Downloading .* succeeded.*`, + data: []byte{}, + }, + { + path: writePath, + cmd: "put '" + localfile.Name() + "' testfile\n", + match: `(?ms).*Uploading .* succeeded.*`, + }, + { + path: writePath, + cmd: "get testfile '" + checkfile.Name() + "'\n", + match: `(?ms).*succeeded.*`, + data: testdata, + }, + { + path: writePath, + cmd: "move testfile newdir0/\n", + match: `(?ms).*Moving .* succeeded.*`, + }, + { + path: writePath, + cmd: "move testfile newdir0/\n", + match: `(?ms).*Moving .* failed.*`, + }, + { + path: writePath, + cmd: "ls\n", + match: `(?ms).*newdir0.* 0 +` + matchToday + ` \d+:\d+\n.*`, + }, + { + path: writePath, + cmd: "move newdir0/testfile emptyfile/bogus/\n", + match: `(?ms).*Moving .* failed.*`, + }, + { + path: writePath, + cmd: "mkcol newdir1\n", + match: `(?ms).*Creating .* succeeded.*`, + }, + { + path: writePath, + cmd: "move newdir0/testfile newdir1/\n", + match: `(?ms).*Moving .* succeeded.*`, + }, + { + path: writePath, + cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n", + match: `(?ms).*Uploading .* succeeded.*`, + }, + { + path: writePath, + cmd: "mkcol newdir2\n", + match: `(?ms).*Creating .* succeeded.*`, + }, + { + path: writePath, + cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n", + match: `(?ms).*Uploading .* succeeded.*`, + }, + { + path: writePath, + cmd: "copy newdir2/testfile2 testfile3\n", + match: `(?ms).*succeeded.*`, + }, + { + path: writePath, + cmd: "get testfile3 '" + checkfile.Name() + "'\n", + match: `(?ms).*succeeded.*`, + data: testdata, + }, + { + path: writePath, + cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n", + match: `(?ms).*succeeded.*`, + data: testdata, + }, + { + path: writePath, + cmd: "rmcol newdir2\n", + match: `(?ms).*Deleting collection .* succeeded.*`, + }, + { + path: writePath, + cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n", + match: `(?ms).*Downloading .* failed.*`, + }, + { + path: "/c=" + arvadostest.UserAgreementCollection + "/t=" + arv.AuthToken + "/", + cmd: "put '" + localfile.Name() + "' foo\n", + match: `(?ms).*Uploading .* failed:.*403 Forbidden.*`, + }, + { + path: pdhPath, + cmd: "put '" + localfile.Name() + "' foo\n", + match: `(?ms).*Uploading .* failed:.*405 Method Not Allowed.*`, + }, + { + path: pdhPath, + cmd: "move foo bar\n", + match: `(?ms).*Moving .* failed:.*405 Method Not Allowed.*`, + }, + { + path: pdhPath, + cmd: "copy foo bar\n", + match: `(?ms).*Copying .* failed:.*405 Method Not Allowed.*`, + }, + { + path: pdhPath, + cmd: "delete foo\n", + match: `(?ms).*Deleting .* failed:.*405 Method Not Allowed.*`, }, } { - c.Logf("%s %#v", "http://"+s.testServer.Addr, trial) + c.Logf("%s %+v", "http://"+s.testServer.Addr, trial) + + os.Remove(checkfile.Name()) + cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path) cmd.Stdin = bytes.NewBufferString(trial.cmd) stdout, err := cmd.StdoutPipe() @@ -56,5 +216,15 @@ func (s *IntegrationSuite) TestWebdavWithCadaver(c *check.C) { err = cmd.Wait() c.Check(err, check.Equals, nil) c.Check(buf.String(), check.Matches, trial.match) + + if trial.data == nil { + continue + } + checkfile, err = os.Open(checkfile.Name()) + c.Assert(err, check.IsNil) + checkfile.Seek(0, os.SEEK_SET) + got, err := ioutil.ReadAll(checkfile) + c.Check(got, check.DeepEquals, trial.data) + c.Check(err, check.IsNil) } }