1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.curoverse.com/arvados.git/sdk/go/arvados"
17 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
18 check "gopkg.in/check.v1"
21 func (s *IntegrationSuite) TestWebdavWithCadaver(c *check.C) {
22 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")
24 localfile, err := ioutil.TempFile("", "localfile")
25 c.Assert(err, check.IsNil)
26 defer os.Remove(localfile.Name())
27 localfile.Write(testdata)
29 emptyfile, err := ioutil.TempFile("", "emptyfile")
30 c.Assert(err, check.IsNil)
31 defer os.Remove(emptyfile.Name())
33 checkfile, err := ioutil.TempFile("", "checkfile")
34 c.Assert(err, check.IsNil)
35 defer os.Remove(checkfile.Name())
37 var newCollection arvados.Collection
38 arv := arvados.NewClientFromEnv()
39 arv.AuthToken = arvadostest.ActiveToken
40 err = arv.RequestAndDecode(&newCollection, "POST", "/arvados/v1/collections", bytes.NewBufferString(url.Values{"collection": {"{}"}}.Encode()), nil)
41 c.Assert(err, check.IsNil)
42 writePath := "/c=" + newCollection.UUID + "/t=" + arv.AuthToken + "/"
44 readPath := "/c=" + arvadostest.FooAndBarFilesInDirUUID + "/t=" + arvadostest.ActiveToken + "/"
45 type testcase struct {
51 for _, trial := range []testcase{
55 match: `(?ms).*dir1 *0 .*`,
60 match: `(?ms).*bar *3.*foo *3 .*`,
63 path: readPath + "_/dir1",
65 match: `(?ms).*bar *3.*foo *3 .*`,
68 path: readPath + "dir1/",
70 match: `(?ms).*bar *3.*foo *3 .*`,
74 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
75 match: `(?ms).*Not Found.*`,
79 cmd: "put '" + emptyfile.Name() + "' emptyfile\n",
80 match: `(?ms).*Uploading .* succeeded.*`,
84 cmd: "get emptyfile '" + checkfile.Name() + "'\n",
85 match: `(?ms).*Downloading .* succeeded.*`,
90 cmd: "put '" + localfile.Name() + "' testfile\n",
91 match: `(?ms).*Uploading .* succeeded.*`,
95 cmd: "get testfile '" + checkfile.Name() + "'\n",
96 match: `(?ms).*succeeded.*`,
101 cmd: "move testfile newdir0/\n",
102 match: `(?ms).*Moving .* succeeded.*`,
106 cmd: "move testfile newdir0/\n",
107 match: `(?ms).*Moving .* failed.*`,
112 match: `(?ms).*newdir0.* 0 .*`,
116 cmd: "move newdir0/testfile emptyfile/bogus/\n",
117 match: `(?ms).*Moving .* failed.*`,
121 cmd: "mkcol newdir1\n",
122 match: `(?ms).*Creating .* succeeded.*`,
126 cmd: "move newdir0/testfile newdir1/\n",
127 match: `(?ms).*Moving .* succeeded.*`,
131 cmd: "put '" + localfile.Name() + "' newdir1/testfile1\n",
132 match: `(?ms).*Uploading .* succeeded.*`,
136 cmd: "mkcol newdir2\n",
137 match: `(?ms).*Creating .* succeeded.*`,
141 cmd: "put '" + localfile.Name() + "' newdir2/testfile2\n",
142 match: `(?ms).*Uploading .* succeeded.*`,
146 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
147 match: `(?ms).*succeeded.*`,
152 cmd: "rmcol newdir2\n",
153 match: `(?ms).*Deleting collection .* succeeded.*`,
157 cmd: "get newdir2/testfile2 '" + checkfile.Name() + "'\n",
158 match: `(?ms).*Downloading .* failed.*`,
161 path: "/c=" + arvadostest.UserAgreementCollection + "/t=" + arv.AuthToken + "/",
162 cmd: "put '" + localfile.Name() + "' foo\n",
163 match: `(?ms).*Uploading .* failed:.*403 Forbidden.*`,
166 path: "/c=" + strings.Replace(arvadostest.FooAndBarFilesInDirPDH, "+", "-", -1) + "/t=" + arv.AuthToken + "/",
167 cmd: "put '" + localfile.Name() + "' foo\n",
168 match: `(?ms).*Uploading .* failed:.*405 Method Not Allowed.*`,
171 c.Logf("%s %+v", "http://"+s.testServer.Addr, trial)
173 os.Remove(checkfile.Name())
175 cmd := exec.Command("cadaver", "http://"+s.testServer.Addr+trial.path)
176 cmd.Stdin = bytes.NewBufferString(trial.cmd)
177 stdout, err := cmd.StdoutPipe()
178 c.Assert(err, check.Equals, nil)
179 cmd.Stderr = cmd.Stdout
183 _, err = io.Copy(&buf, stdout)
184 c.Check(err, check.Equals, nil)
186 c.Check(err, check.Equals, nil)
187 c.Check(buf.String(), check.Matches, trial.match)
189 if trial.data == nil {
192 checkfile, err = os.Open(checkfile.Name())
193 c.Assert(err, check.IsNil)
194 checkfile.Seek(0, os.SEEK_SET)
195 got, err := ioutil.ReadAll(checkfile)
196 c.Check(got, check.DeepEquals, trial.data)
197 c.Check(err, check.IsNil)