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 matchToday := time.Now().Format("Jan +2")
47 readPath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/"
48 type testcase struct {
54 for _, trial := range []testcase{
58 match: `(?ms).*dir1 *0 .*`,
63 match: `(?ms).*bar *3.*foo *3 .*`,
66 path: readPath + "_/dir1",
68 match: `(?ms).*bar *3.*foo *3 .*`,
71 path: readPath + "dir1/",
73 match: `(?ms).*bar *3.*foo +3 +Feb +\d+ +2014.*`,
77 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
78 match: `(?ms).*Not Found.*`,
82 cmd: "put '" + emptyfile.Name() + "' emptyfile\n",
83 match: `(?ms).*Uploading .* succeeded.*`,
87 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
88 match: `(?ms).*Downloading .* succeeded.*`,
93 cmd: "put '" + localfile.Name() + "' testfile\n",
94 match: `(?ms).*Uploading .* succeeded.*`,
98 cmd: "get testfile '" + checkfile.Name() + "'\n",
99 match: `(?ms).*succeeded.*`,
104 cmd: "move testfile newdir0/\n",
105 match: `(?ms).*Moving .* succeeded.*`,
109 cmd: "move testfile newdir0/\n",
110 match: `(?ms).*Moving .* failed.*`,
115 match: `(?ms).*newdir0.* 0 +` + matchToday + ` \d+:\d+\n.*`,
119 cmd: "move newdir0/testfile emptyfile/bogus/\n",
120 match: `(?ms).*Moving .* failed.*`,
124 cmd: "mkcol newdir1\n",
125 match: `(?ms).*Creating .* succeeded.*`,
129 cmd: "move newdir0/testfile newdir1/\n",
130 match: `(?ms).*Moving .* succeeded.*`,
134 cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n",
135 match: `(?ms).*Uploading .* succeeded.*`,
139 cmd: "mkcol newdir2\n",
140 match: `(?ms).*Creating .* succeeded.*`,
144 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
145 match: `(?ms).*Uploading .* succeeded.*`,
149 cmd: "copy newdir2/testfile2 testfile3\n",
150 match: `(?ms).*succeeded.*`,
154 cmd: "get testfile3 '" + checkfile.Name() + "'\n",
155 match: `(?ms).*succeeded.*`,
160 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
161 match: `(?ms).*succeeded.*`,
166 cmd: "rmcol newdir2\n",
167 match: `(?ms).*Deleting collection .* succeeded.*`,
171 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
172 match: `(?ms).*Downloading .* failed.*`,
175 path: "/c=" + arvadostest.UserAgreementCollection + "/t=" + arv.AuthToken + "/",
176 cmd: "put '" + localfile.Name() + "' foo\n",
177 match: `(?ms).*Uploading .* failed:.*403 Forbidden.*`,
180 path: "/c=" + strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + "/t=" + arv.AuthToken + "/",
181 cmd: "put '" + localfile.Name() + "' foo\n",
182 match: `(?ms).*Uploading .* failed:.*405 Method Not Allowed.*`,
185 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
187 os.Remove(checkfile.Name())
189 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
190 cmd.Stdin = bytes.NewBufferString(trial.cmd)
191 stdout, err := cmd.StdoutPipe()
192 c.Assert(err, check.Equals, nil)
193 cmd.Stderr = cmd.Stdout
197 _, err = io.Copy(&buf, stdout)
198 c.Check(err, check.Equals, nil)
200 c.Check(err, check.Equals, nil)
201 c.Check(buf.String(), check.Matches, trial.match)
203 if trial.data == nil {
206 checkfile, err = os.Open(checkfile.Name())
207 c.Assert(err, check.IsNil)
208 checkfile.Seek(0, os.SEEK_SET)
209 got, err := ioutil.ReadAll(checkfile)
210 c.Check(got, check.DeepEquals, trial.data)
211 c.Check(err, check.IsNil)