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: "put '" + localfile.Name() + "' newdir1/testfile1\n",
137 match: `(?ms).*Uploading .* succeeded.*`,
141 cmd: "mkcol newdir2\n",
142 match: `(?ms).*Creating .* succeeded.*`,
146 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
147 match: `(?ms).*Uploading .* succeeded.*`,
151 cmd: "copy newdir2/testfile2 testfile3\n",
152 match: `(?ms).*succeeded.*`,
156 cmd: "get testfile3 '" + checkfile.Name() + "'\n",
157 match: `(?ms).*succeeded.*`,
162 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
163 match: `(?ms).*succeeded.*`,
168 cmd: "rmcol newdir2\n",
169 match: `(?ms).*Deleting collection .* succeeded.*`,
173 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
174 match: `(?ms).*Downloading .* failed.*`,
177 path: "/c=" + arvadostest.UserAgreementCollection + "/t=" + arv.AuthToken + "/",
178 cmd: "put '" + localfile.Name() + "' foo\n",
179 match: `(?ms).*Uploading .* failed:.*403 Forbidden.*`,
183 cmd: "put '" + localfile.Name() + "' foo\n",
184 match: `(?ms).*Uploading .* failed:.*405 Method Not Allowed.*`,
188 cmd: "move foo bar\n",
189 match: `(?ms).*Moving .* failed:.*405 Method Not Allowed.*`,
193 cmd: "copy foo bar\n",
194 match: `(?ms).*Copying .* failed:.*405 Method Not Allowed.*`,
199 match: `(?ms).*Deleting .* failed:.*405 Method Not Allowed.*`,
202 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
204 os.Remove(checkfile.Name())
206 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
207 cmd.Stdin = bytes.NewBufferString(trial.cmd)
208 stdout, err := cmd.StdoutPipe()
209 c.Assert(err, check.Equals, nil)
210 cmd.Stderr = cmd.Stdout
214 _, err = io.Copy(&buf, stdout)
215 c.Check(err, check.Equals, nil)
217 c.Check(err, check.Equals, nil)
218 c.Check(buf.String(), check.Matches, trial.match)
220 if trial.data == nil {
223 checkfile, err = os.Open(checkfile.Name())
224 c.Assert(err, check.IsNil)
225 checkfile.Seek(0, os.SEEK_SET)
226 got, err := ioutil.ReadAll(checkfile)
227 c.Check(got, check.DeepEquals, trial.data)
228 c.Check(err, check.IsNil)