1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
15 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
16 check "gopkg.in/check.v1"
19 type spiedRequest struct {
22 params map[string]interface{}
25 type spyingClient struct {
30 func (sc *spyingClient) RequestAndDecode(dst interface{}, method, path string, body io.Reader, params interface{}) error {
31 var paramsCopy map[string]interface{}
33 json.NewEncoder(&buf).Encode(params)
34 json.NewDecoder(&buf).Decode(¶msCopy)
35 sc.calls = append(sc.calls, spiedRequest{
40 return sc.Client.RequestAndDecode(dst, method, path, body, params)
43 func (s *SiteFSSuite) TestCurrentUserHome(c *check.C) {
44 s.fs.MountProject("home", "")
45 s.testHomeProject(c, "/home")
48 func (s *SiteFSSuite) TestUsersDir(c *check.C) {
49 s.testHomeProject(c, "/users/active")
52 func (s *SiteFSSuite) testHomeProject(c *check.C, path string) {
53 f, err := s.fs.Open(path)
54 c.Assert(err, check.IsNil)
55 fis, err := f.Readdir(-1)
56 c.Check(len(fis), check.Not(check.Equals), 0)
59 for _, fi := range fis {
60 c.Check(fi.Name(), check.Not(check.Equals), "")
61 if fi.Name() == "A Project" {
65 c.Check(ok, check.Equals, true)
67 f, err = s.fs.Open(path + "/A Project/..")
68 c.Assert(err, check.IsNil)
70 c.Assert(err, check.IsNil)
71 c.Check(fi.IsDir(), check.Equals, true)
72 _, basename := filepath.Split(path)
73 c.Check(fi.Name(), check.Equals, basename)
75 f, err = s.fs.Open(path + "/A Project/A Subproject")
76 c.Assert(err, check.IsNil)
78 c.Assert(err, check.IsNil)
79 c.Check(fi.IsDir(), check.Equals, true)
81 for _, nx := range []string{
82 path + "/Unrestricted public data",
83 path + "/Unrestricted public data/does not exist",
84 path + "/A Project/does not exist",
87 f, err = s.fs.Open(nx)
88 c.Check(err, check.NotNil)
89 c.Check(os.IsNotExist(err), check.Equals, true)
93 func (s *SiteFSSuite) TestProjectReaddirAfterLoadOne(c *check.C) {
94 f, err := s.fs.Open("/users/active/A Project/A Subproject")
95 c.Assert(err, check.IsNil)
97 f, err = s.fs.Open("/users/active/A Project/Project does not exist")
98 c.Assert(err, check.NotNil)
99 f, err = s.fs.Open("/users/active/A Project/A Subproject")
100 c.Assert(err, check.IsNil)
102 f, err = s.fs.Open("/users/active/A Project")
103 c.Assert(err, check.IsNil)
105 fis, err := f.Readdir(-1)
106 c.Assert(err, check.IsNil)
108 var foundSubproject, foundCollection bool
109 for _, fi := range fis {
112 foundSubproject = true
113 case "collection_to_move_around":
114 foundCollection = true
117 c.Check(foundSubproject, check.Equals, true)
118 c.Check(foundCollection, check.Equals, true)
121 func (s *SiteFSSuite) TestSlashInName(c *check.C) {
122 badCollection := Collection{
123 Name: "bad/collection",
124 OwnerUUID: arvadostest.AProjectUUID,
126 err := s.client.RequestAndDecode(&badCollection, "POST", "arvados/v1/collections", s.client.UpdateBody(&badCollection), nil)
127 c.Assert(err, check.IsNil)
128 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+badCollection.UUID, nil, nil)
132 GroupClass: "project",
133 OwnerUUID: arvadostest.AProjectUUID,
135 err = s.client.RequestAndDecode(&badProject, "POST", "arvados/v1/groups", s.client.UpdateBody(&badProject), nil)
136 c.Assert(err, check.IsNil)
137 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/groups/"+badProject.UUID, nil, nil)
139 dir, err := s.fs.Open("/users/active/A Project")
140 c.Assert(err, check.IsNil)
141 fis, err := dir.Readdir(-1)
142 c.Check(err, check.IsNil)
143 for _, fi := range fis {
144 c.Logf("fi.Name() == %q", fi.Name())
145 c.Check(strings.Contains(fi.Name(), "/"), check.Equals, false)
149 func (s *SiteFSSuite) TestProjectUpdatedByOther(c *check.C) {
150 s.fs.MountProject("home", "")
152 project, err := s.fs.OpenFile("/home/A Project", 0, 0)
153 c.Assert(err, check.IsNil)
155 _, err = s.fs.Open("/home/A Project/oob")
156 c.Check(err, check.NotNil)
160 OwnerUUID: arvadostest.AProjectUUID,
162 err = s.client.RequestAndDecode(&oob, "POST", "arvados/v1/collections", s.client.UpdateBody(&oob), nil)
163 c.Assert(err, check.IsNil)
164 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+oob.UUID, nil, nil)
167 c.Check(err, check.IsNil)
168 f, err := s.fs.Open("/home/A Project/oob")
169 c.Assert(err, check.IsNil)
171 c.Assert(err, check.IsNil)
172 c.Check(fi.IsDir(), check.Equals, true)
175 wf, err := s.fs.OpenFile("/home/A Project/oob/test.txt", os.O_CREATE|os.O_RDWR, 0700)
176 c.Assert(err, check.IsNil)
177 _, err = wf.Write([]byte("hello oob\n"))
178 c.Check(err, check.IsNil)
180 c.Check(err, check.IsNil)
182 // Delete test.txt behind s.fs's back by updating the
183 // collection record with the old (empty) ManifestText.
184 err = s.client.RequestAndDecode(nil, "PATCH", "arvados/v1/collections/"+oob.UUID, s.client.UpdateBody(&oob), nil)
185 c.Assert(err, check.IsNil)
188 c.Check(err, check.IsNil)
189 _, err = s.fs.Open("/home/A Project/oob/test.txt")
190 c.Check(err, check.NotNil)
191 _, err = s.fs.Open("/home/A Project/oob")
192 c.Check(err, check.IsNil)
194 err = s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+oob.UUID, nil, nil)
195 c.Assert(err, check.IsNil)
198 c.Check(err, check.IsNil)
199 _, err = s.fs.Open("/home/A Project/oob")
200 c.Check(err, check.NotNil)