1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
17 "git.curoverse.com/arvados.git/sdk/go/arvados"
18 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
19 check "gopkg.in/check.v1"
22 func (s *IntegrationSuite) TestWebdavWithCadaver(c *check.C) {
23 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")
25 localfile, err := ioutil.TempFile("", "localfile")
26 c.Assert(err, check.IsNil)
27 defer os.Remove(localfile.Name())
28 localfile.Write(testdata)
30 emptyfile, err := ioutil.TempFile("", "emptyfile")
31 c.Assert(err, check.IsNil)
32 defer os.Remove(emptyfile.Name())
34 checkfile, err := ioutil.TempFile("", "checkfile")
35 c.Assert(err, check.IsNil)
36 defer os.Remove(checkfile.Name())
38 var newCollection arvados.Collection
39 arv := arvados.NewClientFromEnv()
40 arv.AuthToken = arvadostest.ActiveToken
41 err = arv.RequestAndDecode(&newCollection, "POST", "/arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil)
42 c.Assert(err, check.IsNil)
43 writePath := "/c=" + newCollection.UUID + "/t=" + arv.AuthToken + "/"
45 pdhPath := "/c=" + strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + "/t=" + arv.AuthToken + "/"
47 matchToday := time.Now().Format("Jan +2")
49 readPath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/"
50 type testcase struct {
56 for _, trial := range []testcase{
60 match: `(?ms).*dir1 *0 .*`,
65 match: `(?ms).*bar *3.*foo *3 .*`,
68 path: readPath + "_/dir1",
70 match: `(?ms).*bar *3.*foo *3 .*`,
73 path: readPath + "dir1/",
75 match: `(?ms).*bar *3.*foo +3 +Feb +\d+ +2014.*`,
79 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
80 match: `(?ms).*Not Found.*`,
84 cmd: "put '" + emptyfile.Name() + "' emptyfile\n",
85 match: `(?ms).*Uploading .* succeeded.*`,
89 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
90 match: `(?ms).*Downloading .* succeeded.*`,
95 cmd: "put '" + localfile.Name() + "' testfile\n",
96 match: `(?ms).*Uploading .* succeeded.*`,
100 cmd: "get testfile '" + checkfile.Name() + "'\n",
101 match: `(?ms).*succeeded.*`,
106 cmd: "move testfile newdir0/\n",
107 match: `(?ms).*Moving .* succeeded.*`,
111 cmd: "move testfile newdir0/\n",
112 match: `(?ms).*Moving .* failed.*`,
117 match: `(?ms).*newdir0.* 0 +` + matchToday + ` \d+:\d+\n.*`,
121 cmd: "move newdir0/testfile emptyfile/bogus/\n",
122 match: `(?ms).*Moving .* failed.*`,
126 cmd: "mkcol newdir1\n",
127 match: `(?ms).*Creating .* succeeded.*`,
131 cmd: "move newdir0/testfile newdir1/\n",
132 match: `(?ms).*Moving .* succeeded.*`,
136 cmd: "move newdir1 newdir1/\n",
137 match: `(?ms).*Moving .* failed.*`,
141 cmd: "get newdir1/testfile '" + checkfile.Name() + "'\n",
142 match: `(?ms).*succeeded.*`,
147 cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n",
148 match: `(?ms).*Uploading .* succeeded.*`,
152 cmd: "mkcol newdir2\n",
153 match: `(?ms).*Creating .* succeeded.*`,
157 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
158 match: `(?ms).*Uploading .* succeeded.*`,
162 cmd: "copy newdir2/testfile2 testfile3\n",
163 match: `(?ms).*succeeded.*`,
167 cmd: "get testfile3 '" + checkfile.Name() + "'\n",
168 match: `(?ms).*succeeded.*`,
173 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
174 match: `(?ms).*succeeded.*`,
179 cmd: "rmcol newdir2\n",
180 match: `(?ms).*Deleting collection .* succeeded.*`,
184 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
185 match: `(?ms).*Downloading .* failed.*`,
188 path: "/c=" + arvadostest.UserAgreementCollection + "/t=" + arv.AuthToken + "/",
189 cmd: "put '" + localfile.Name() + "' foo\n",
190 match: `(?ms).*Uploading .* failed:.*403 Forbidden.*`,
194 cmd: "put '" + localfile.Name() + "' foo\n",
195 match: `(?ms).*Uploading .* failed:.*405 Method Not Allowed.*`,
199 cmd: "move foo bar\n",
200 match: `(?ms).*Moving .* failed:.*405 Method Not Allowed.*`,
204 cmd: "copy foo bar\n",
205 match: `(?ms).*Copying .* failed:.*405 Method Not Allowed.*`,
210 match: `(?ms).*Deleting .* failed:.*405 Method Not Allowed.*`,
213 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
215 os.Remove(checkfile.Name())
217 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
218 cmd.Stdin = bytes.NewBufferString(trial.cmd)
219 stdout, err := cmd.StdoutPipe()
220 c.Assert(err, check.Equals, nil)
221 cmd.Stderr = cmd.Stdout
225 _, err = io.Copy(&buf, stdout)
226 c.Check(err, check.Equals, nil)
228 c.Check(err, check.Equals, nil)
229 c.Check(buf.String(), check.Matches, trial.match)
231 if trial.data == nil {
234 checkfile, err = os.Open(checkfile.Name())
235 c.Assert(err, check.IsNil)
236 checkfile.Seek(0, os.SEEK_SET)
237 got, err := ioutil.ReadAll(checkfile)
238 c.Check(got, check.DeepEquals, trial.data)
239 c.Check(err, check.IsNil)