@@ -52,7 +52,7 @@ def test_upload(client, default_filepath, insert_default_sample, default_sample)
52
52
)
53
53
assert isinstance (response .json ["file_id" ], str )
54
54
assert response .json ["file_information" ]
55
- assert response .json ["status" ], "success"
55
+ assert response .json ["status" ] == "success"
56
56
assert response .status_code == 201
57
57
58
58
@@ -99,6 +99,7 @@ def test_get_file_and_delete(client, default_filepath, default_sample):
99
99
assert not response .json ["files_data" ]
100
100
101
101
102
+ @pytest .mark .dependency (depends = ["test_get_file_and_delete" ])
102
103
def test_upload_new_version (
103
104
client , default_filepath , insert_default_sample , default_sample , tmpdir
104
105
): # pylint: disable=unused-argument
@@ -120,7 +121,7 @@ def test_upload_new_version(
120
121
file_id = response .json ["file_id" ]
121
122
assert file_id
122
123
assert response .json ["file_information" ]
123
- assert response .json ["status" ], "success"
124
+ assert response .json ["status" ] == "success"
124
125
assert response .status_code == 201
125
126
126
127
# Copy the file to a new temp directory so its fs metadata changes
@@ -142,10 +143,61 @@ def test_upload_new_version(
142
143
)
143
144
assert isinstance (response_reup .json ["file_id" ], str )
144
145
assert response_reup .json ["file_information" ]
145
- assert response_reup .json ["status" ], "success"
146
+ assert response_reup .json ["status" ] == "success"
146
147
assert response_reup .status_code == 201
147
148
assert (
148
149
response_reup .json ["file_information" ]["location" ]
149
150
== response .json ["file_information" ]["location" ]
150
151
)
151
152
assert response_reup .json ["file_id" ] == response .json ["file_id" ]
153
+
154
+
155
+ @pytest .mark .dependency (depends = ["test_upload_new_version" ])
156
+ def test_file_permissions (
157
+ client ,
158
+ another_client ,
159
+ another_user_id ,
160
+ default_filepath ,
161
+ insert_default_sample ,
162
+ default_sample ,
163
+ tmpdir ,
164
+ ): # pylint: disable=unused-argument
165
+ """Upload a file as one user, then test access as two different users."""
166
+ filename = "my_secret_file.txt"
167
+ with open (default_filepath , "rb" ) as f :
168
+ response = client .post (
169
+ "/upload-file/" ,
170
+ buffered = True ,
171
+ content_type = "multipart/form-data" ,
172
+ data = {
173
+ "item_id" : default_sample .item_id ,
174
+ "file" : [(f , filename )],
175
+ "type" : "application/octet-stream" ,
176
+ "replace_file" : "null" ,
177
+ "relativePath" : "null" ,
178
+ },
179
+ )
180
+
181
+ assert response .status_code == 201
182
+ resp_json = response .json
183
+ assert resp_json ["status" ] == "success"
184
+ file_id = resp_json ["file_id" ]
185
+
186
+ # Test that a random user cannot access the file directly
187
+ response = another_client .get (f"/files/{ file_id } /{ filename } " )
188
+ assert response .status_code == 401
189
+ assert response .json ["status" ] == "error"
190
+
191
+ # Give the user access to the item, then check again
192
+ # First get refcode for item ID
193
+ response = client .get (f"/get-item-data/{ default_sample .item_id } " )
194
+ refcode = response .json ["item_data" ]["refcode" ]
195
+
196
+ # Add normal user to the item
197
+ response = client .patch (
198
+ f"/items/{ refcode } /permissions" , json = {"creators" : [{"immutable_id" : str (another_user_id )}]}
199
+ )
200
+
201
+ # Now check they have access to the file
202
+ response = another_client .get (f"/files/{ file_id } /{ filename } " )
203
+ assert response .status_code == 200
0 commit comments