Skip to content

Commit

Permalink
Add back support for sigv4 overrides
Browse files Browse the repository at this point in the history
This allows you to change the signature version used when
signing requests for a particular service.

This isn't strictly needed to communicate with various endpoints,
any region specific signature versions are captured in _endpoints.json.
However, with S3 we sometimes need to switch to sigv4 even if it
otherwise wouldn't be required.
  • Loading branch information
jamesls committed Nov 18, 2014
1 parent 133261e commit c7945d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def signature_overrides(service_data, service_name, session, **kwargs):
logger.debug("Switching signature version for service %s "
"to version %s based on config file override.",
service_name, signature_version_override)
service_data['signature_version'] = signature_version_override
service_metadata = service_data['metadata']
service_metadata['signatureVersion'] = signature_version_override


def add_expect_header(model, params, **kwargs):
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,26 @@ def test_can_get_bucket_location(self):
self.assertEqual(response[1]['LocationConstraint'], 'eu-central-1')


class TestCanSwitchToSigV4(unittest.TestCase):
def setUp(self):
self.session = botocore.session.get_session()

def test_verify_can_switch_sigv4(self):
self.session.set_config_variable('s3', {'signature_version': 's3v4'})
# We need to verify this option for service/operation objects so we're
# not using client objects now (though we should add a test for client
# objects eventually).
service = self.session.get_service('s3')
endpoint = service.get_endpoint('us-east-1')
# The set_config_variable should ensure that we use sigv4 for s3.
self.assertIsInstance(endpoint.auth, botocore.auth.S3SigV4Auth)

# And just to be sure, we'll go ahead and make a basic S3
# call and verify it works with sigv4.
operation = service.get_operation('ListBuckets')
http, response = operation.call(endpoint)
self.assertEqual(http.status_code, 200)


if __name__ == '__main__':
unittest.main()
12 changes: 8 additions & 4 deletions tests/unit/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,23 @@ def test_switch_to_sigv4(self):
mock_session.get_scoped_config.return_value = {
's3': {'signature_version': 's3v4'}
}
kwargs = {'service_data': {'signature_version': 's3'},
kwargs = {'service_data': {'metadata': {'signatureVersion': 's3'}},
'service_name': 's3', 'session': mock_session}
self.session.emit(event, **kwargs)
self.assertEqual(kwargs['service_data']['signature_version'], 's3v4')
self.assertEqual(
kwargs['service_data']['metadata']['signatureVersion'],
's3v4')

def test_noswitch_to_sigv4(self):
event = self.session.create_event('service-data-loaded', 's3')
mock_session = mock.Mock()
mock_session.get_scoped_config.return_value = {}
kwargs = {'service_data': {'signature_version': 's3'},
kwargs = {'service_data': {'metadata': {'signatureVersion': 's3'}},
'service_name': 's3', 'session': mock_session}
self.session.emit(event, **kwargs)
self.assertEqual(kwargs['service_data']['signature_version'], 's3')
self.assertEqual(
kwargs['service_data']['metadata']['signatureVersion'],
's3')

def test_quote_source_header(self):
for op in ('UploadPartCopy', 'CopyObject'):
Expand Down

0 comments on commit c7945d9

Please sign in to comment.