Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ExpectedSourceBucketOwner support for copy operation #234

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion s3transfer/copies.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CopySubmissionTask(SubmissionTask):
'CopySourceSSECustomerAlgorithm': 'SSECustomerAlgorithm',
'CopySourceSSECustomerKeyMD5': 'SSECustomerKeyMD5',
'RequestPayer': 'RequestPayer',
'ExpectedBucketOwner': 'ExpectedBucketOwner',
'ExpectedSourceBucketOwner': 'ExpectedBucketOwner',
}

UPLOAD_PART_COPY_ARGS = [
Expand All @@ -55,6 +55,7 @@ class CopySubmissionTask(SubmissionTask):
'SSECustomerKeyMD5',
'RequestPayer',
'ExpectedBucketOwner',
'ExpectedSourceBucketOwner',
]

CREATE_MULTIPART_ARGS_BLACKLIST = [
Expand All @@ -67,6 +68,7 @@ class CopySubmissionTask(SubmissionTask):
'CopySourceSSECustomerKeyMD5',
'MetadataDirective',
'TaggingDirective',
'ExpectedSourceBucketOwner',
]

COMPLETE_MULTIPART_ARGS = ['RequestPayer', 'ExpectedBucketOwner']
Expand Down
1 change: 1 addition & 0 deletions s3transfer/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class TransferManager:
'CopySourceSSECustomerKeyMD5',
'MetadataDirective',
'TaggingDirective',
'ExpectedSourceBucketOwner',
]

ALLOWED_DELETE_ARGS = [
Expand Down
23 changes: 22 additions & 1 deletion tests/functional/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,24 @@ def test_copy_with_extra_args(self):

def test_copy_maps_extra_args_to_head_object(self):
self.extra_args['CopySourceSSECustomerAlgorithm'] = 'AES256'
self.extra_args[
'ExpectedSourceBucketOwner'
] = 'expectedsourcebucketowner'
self.extra_args['ExpectedBucketOwner'] = 'expectedbucketowner'

expected_head_params = {
'Bucket': 'mysourcebucket',
'Key': 'mysourcekey',
'SSECustomerAlgorithm': 'AES256',
'ExpectedBucketOwner': 'expectedsourcebucketowner',
}
expected_copy_object = {
'Bucket': self.bucket,
'Key': self.key,
'CopySource': self.copy_source,
'CopySourceSSECustomerAlgorithm': 'AES256',
'ExpectedSourceBucketOwner': 'expectedsourcebucketowner',
'ExpectedBucketOwner': 'expectedbucketowner',
}

self.add_head_object_response(expected_params=expected_head_params)
Expand Down Expand Up @@ -423,9 +430,10 @@ def test_copy_with_extra_args(self):
# This extra argument should be added to the head object,
# the create multipart upload, and upload part copy.
self.extra_args['RequestPayer'] = 'requester'
self.extra_args['ExpectedBucketOwner'] = 'expectedbucketowner'

head_params, add_copy_kwargs = self._get_expected_params()
head_params.update(self.extra_args)
head_params['RequestPayer'] = 'requester'
self.add_head_object_response(expected_params=head_params)

self._add_params_to_expected_params(
Expand All @@ -444,8 +452,17 @@ def test_copy_with_extra_args(self):
def test_copy_blacklists_args_to_create_multipart(self):
# This argument can never be used for multipart uploads
self.extra_args['MetadataDirective'] = 'COPY'
self.extra_args[
'ExpectedSourceBucketOwner'
] = 'expectedsourcebucketowner'

head_params, add_copy_kwargs = self._get_expected_params()
head_params['ExpectedBucketOwner'] = 'expectedsourcebucketowner'
self._add_params_to_expected_params(
add_copy_kwargs,
['copy'],
{'ExpectedSourceBucketOwner': 'expectedsourcebucketowner'},
)
self.add_head_object_response(expected_params=head_params)
self.add_successful_copy_responses(**add_copy_kwargs)

Expand Down Expand Up @@ -493,12 +510,16 @@ def test_copy_passes_args_to_create_multipart_and_upload_part(self):

def test_copy_maps_extra_args_to_head_object(self):
self.extra_args['CopySourceSSECustomerAlgorithm'] = 'AES256'
self.extra_args[
'ExpectedSourceBucketOwner'
] = 'expectedsourcebucketowner'

head_params, add_copy_kwargs = self._get_expected_params()

# The CopySourceSSECustomerAlgorithm needs to get mapped to
# SSECustomerAlgorithm for HeadObject
head_params['SSECustomerAlgorithm'] = 'AES256'
head_params['ExpectedBucketOwner'] = 'expectedsourcebucketowner'
self.add_head_object_response(expected_params=head_params)

# However, it needs to remain the same for UploadPartCopy.
Expand Down