|
8 | 8 |
|
9 | 9 | import pytest
|
10 | 10 | import unittest
|
| 11 | +from unittest import mock |
11 | 12 |
|
12 | 13 | try:
|
13 | 14 | boto3 = importlib.import_module('boto3')
|
@@ -181,3 +182,37 @@ def test_sts_external_storage_location(self):
|
181 | 182 | retrieved_file_entity = self.syn.get(file_entity['id'])
|
182 | 183 | with open(retrieved_file_entity.path, 'r') as f:
|
183 | 184 | assert file_contents == f.read()
|
| 185 | + |
| 186 | + def test_boto_upload__acl(self): |
| 187 | + """Verify when we store a Synapse object using boto we apply a bucket-owner-full-control ACL to the object""" |
| 188 | + bucket_name, _ = get_aws_env() |
| 189 | + _, folder, storage_location_id = self._configure_storage_location(sts_enabled=True) |
| 190 | + |
| 191 | + file_contents = str(uuid.uuid4()) |
| 192 | + upload_file = self._make_temp_file(contents=file_contents) |
| 193 | + |
| 194 | + # mock the sts setting so that we upload this file using boto regardless of test configuration |
| 195 | + with mock.patch.object(self.syn, 'use_boto_sts_transfers', new_callable=mock.PropertyMock(return_value=True)): |
| 196 | + file = self.syn.store(File(path=upload_file.name, parent=folder)) |
| 197 | + |
| 198 | + s3_read_client = boto3.client('s3', **get_aws_env()[1]) |
| 199 | + bucket_acl = s3_read_client.get_bucket_acl(Bucket=bucket_name) |
| 200 | + bucket_grantee = bucket_acl['Grants'][0]['Grantee'] |
| 201 | + assert bucket_grantee['Type'] == 'CanonicalUser' |
| 202 | + bucket_owner_id = bucket_grantee['ID'] |
| 203 | + |
| 204 | + # with_retry to avoid acidity issues of an S3 put |
| 205 | + object_acl = with_retry( |
| 206 | + lambda: s3_read_client.get_object_acl( |
| 207 | + Bucket=bucket_name, |
| 208 | + Key=file['_file_handle']['key'] |
| 209 | + ), |
| 210 | + retry_exceptions=[s3_read_client.exceptions.NoSuchKey] |
| 211 | + ) |
| 212 | + grants = object_acl['Grants'] |
| 213 | + assert len(grants) == 1 |
| 214 | + grant = grants[0] |
| 215 | + grantee = grant['Grantee'] |
| 216 | + assert grantee['Type'] == 'CanonicalUser' |
| 217 | + assert grantee['ID'] == bucket_owner_id |
| 218 | + assert grant['Permission'] == 'FULL_CONTROL' |
0 commit comments