1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
15 check "gopkg.in/check.v1"
18 type spiedRequest struct {
21 params map[string]interface{}
24 type spyingClient struct {
29 func (sc *spyingClient) RequestAndDecode(dst interface{}, method, path string, body io.Reader, params interface{}) error {
30 var paramsCopy map[string]interface{}
32 json.NewEncoder(&buf).Encode(params)
33 json.NewDecoder(&buf).Decode(¶msCopy)
34 sc.calls = append(sc.calls, spiedRequest{
39 return sc.Client.RequestAndDecode(dst, method, path, body, params)
42 func (s *SiteFSSuite) TestCurrentUserHome(c *check.C) {
43 s.fs.MountProject("home", "")
44 s.testHomeProject(c, "/home")
47 func (s *SiteFSSuite) TestUsersDir(c *check.C) {
48 s.testHomeProject(c, "/users/active")
51 func (s *SiteFSSuite) testHomeProject(c *check.C, path string) {
52 f, err := s.fs.Open(path)
53 c.Assert(err, check.IsNil)
54 fis, err := f.Readdir(-1)
55 c.Check(len(fis), check.Not(check.Equals), 0)
58 for _, fi := range fis {
59 c.Check(fi.Name(), check.Not(check.Equals), "")
60 if fi.Name() == "A Project" {
64 c.Check(ok, check.Equals, true)
66 f, err = s.fs.Open(path + "/A Project/..")
67 c.Assert(err, check.IsNil)
69 c.Assert(err, check.IsNil)
70 c.Check(fi.IsDir(), check.Equals, true)
71 _, basename := filepath.Split(path)
72 c.Check(fi.Name(), check.Equals, basename)
74 f, err = s.fs.Open(path + "/A Project/A Subproject")
75 c.Assert(err, check.IsNil)
77 c.Assert(err, check.IsNil)
78 c.Check(fi.IsDir(), check.Equals, true)
80 for _, nx := range []string{
81 path + "/Unrestricted public data",
82 path + "/Unrestricted public data/does not exist",
83 path + "/A Project/does not exist",
86 f, err = s.fs.Open(nx)
87 c.Check(err, check.NotNil)
88 c.Check(os.IsNotExist(err), check.Equals, true)
92 func (s *SiteFSSuite) TestProjectReaddirAfterLoadOne(c *check.C) {
93 f, err := s.fs.Open("/users/active/A Project/A Subproject")
94 c.Assert(err, check.IsNil)
96 f, err = s.fs.Open("/users/active/A Project/Project does not exist")
97 c.Assert(err, check.NotNil)
98 f, err = s.fs.Open("/users/active/A Project/A Subproject")
99 c.Assert(err, check.IsNil)
101 f, err = s.fs.Open("/users/active/A Project")
102 c.Assert(err, check.IsNil)
104 fis, err := f.Readdir(-1)
105 c.Assert(err, check.IsNil)
107 var foundSubproject, foundCollection bool
108 for _, fi := range fis {
111 foundSubproject = true
112 case "collection_to_move_around":
113 foundCollection = true
116 c.Check(foundSubproject, check.Equals, true)
117 c.Check(foundCollection, check.Equals, true)
120 func (s *SiteFSSuite) TestSlashInName(c *check.C) {
121 badCollection := Collection{
122 Name: "bad/collection",
123 OwnerUUID: fixtureAProjectUUID,
125 err := s.client.RequestAndDecode(&badCollection, "POST", "arvados/v1/collections", s.client.UpdateBody(&badCollection), nil)
126 c.Assert(err, check.IsNil)
127 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+badCollection.UUID, nil, nil)
131 GroupClass: "project",
132 OwnerUUID: fixtureAProjectUUID,
134 err = s.client.RequestAndDecode(&badProject, "POST", "arvados/v1/groups", s.client.UpdateBody(&badProject), nil)
135 c.Assert(err, check.IsNil)
136 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/groups/"+badProject.UUID, nil, nil)
138 dir, err := s.fs.Open("/users/active/A Project")
139 c.Assert(err, check.IsNil)
140 fis, err := dir.Readdir(-1)
141 c.Check(err, check.IsNil)
142 for _, fi := range fis {
143 c.Logf("fi.Name() == %q", fi.Name())
144 c.Check(strings.Contains(fi.Name(), "/"), check.Equals, false)
148 func (s *SiteFSSuite) TestProjectUpdatedByOther(c *check.C) {
149 s.fs.MountProject("home", "")
151 project, err := s.fs.OpenFile("/home/A Project", 0, 0)
152 c.Assert(err, check.IsNil)
154 _, err = s.fs.Open("/home/A Project/oob")
155 c.Check(err, check.NotNil)
159 OwnerUUID: fixtureAProjectUUID,
161 err = s.client.RequestAndDecode(&oob, "POST", "arvados/v1/collections", s.client.UpdateBody(&oob), nil)
162 c.Assert(err, check.IsNil)
163 defer s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+oob.UUID, nil, nil)
166 c.Check(err, check.IsNil)
167 f, err := s.fs.Open("/home/A Project/oob")
168 c.Assert(err, check.IsNil)
170 c.Assert(err, check.IsNil)
171 c.Check(fi.IsDir(), check.Equals, true)
174 wf, err := s.fs.OpenFile("/home/A Project/oob/test.txt", os.O_CREATE|os.O_RDWR, 0700)
175 c.Assert(err, check.IsNil)
176 _, err = wf.Write([]byte("hello oob\n"))
177 c.Check(err, check.IsNil)
179 c.Check(err, check.IsNil)
181 // Delete test.txt behind s.fs's back by updating the
182 // collection record with the old (empty) ManifestText.
183 err = s.client.RequestAndDecode(nil, "PATCH", "arvados/v1/collections/"+oob.UUID, s.client.UpdateBody(&oob), nil)
184 c.Assert(err, check.IsNil)
187 c.Check(err, check.IsNil)
188 _, err = s.fs.Open("/home/A Project/oob/test.txt")
189 c.Check(err, check.NotNil)
190 _, err = s.fs.Open("/home/A Project/oob")
191 c.Check(err, check.IsNil)
193 err = s.client.RequestAndDecode(nil, "DELETE", "arvados/v1/collections/"+oob.UUID, nil, nil)
194 c.Assert(err, check.IsNil)
197 c.Check(err, check.IsNil)
198 _, err = s.fs.Open("/home/A Project/oob")
199 c.Check(err, check.NotNil)