diff options
author | Daniel Lindsley <daniel@toastdriven.com> | 2014-01-16 15:00:29 -0800 |
---|---|---|
committer | Daniel Lindsley <daniel@toastdriven.com> | 2014-01-16 15:00:29 -0800 |
commit | 417223288b76566c039c869db68783e2122f98c5 (patch) | |
tree | c96462f3cd9a6f85f26a3105286d6aedc4562abd /tests/unit/s3/test_connection.py | |
parent | 19511fe9032192352de6578a98e71697cc55f78f (diff) | |
download | boto-417223288b76566c039c869db68783e2122f98c5.tar.gz |
Throw an exception if using SigV4 w/o a host.
Diffstat (limited to 'tests/unit/s3/test_connection.py')
-rw-r--r-- | tests/unit/s3/test_connection.py | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/unit/s3/test_connection.py b/tests/unit/s3/test_connection.py index 5fe47712..17c24dcc 100644 --- a/tests/unit/s3/test_connection.py +++ b/tests/unit/s3/test_connection.py @@ -19,10 +19,12 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # +import mock + from tests.unit import unittest from tests.unit import AWSMockServiceTestCase -from boto.s3.connection import S3Connection +from boto.s3.connection import S3Connection, HostRequiredError class TestSignatureAlteration(AWSMockServiceTestCase): @@ -46,6 +48,76 @@ class TestSignatureAlteration(AWSMockServiceTestCase): ) +class TestSigV4HostError(AWSMockServiceTestCase): + connection_class = S3Connection + + def setUp(self): + super(TestSigV4HostError, self).setUp() + self.config = {} + self.config_patch = mock.patch('boto.provider.config.get', + self.get_config) + self.has_config_patch = mock.patch('boto.provider.config.has_option', + self.has_config) + self.config_patch.start() + self.has_config_patch.start() + + def tearDown(self): + self.config_patch.stop() + self.has_config_patch.stop() + + def has_config(self, section_name, key): + try: + self.config[section_name][key] + return True + except KeyError: + return False + + def get_config(self, section_name, key, default=None): + try: + return self.config[section_name][key] + except KeyError: + return None + + def test_historical_behavior(self): + self.assertEqual( + self.service_connection._required_auth_capability(), + ['s3'] + ) + self.assertEqual(self.service_connection.host, 's3.amazonaws.com') + + def test_sigv4_opt_in(self): + # Switch it at the config, so we can check to see how the host is + # handled. + self.config = { + 's3': { + 'use-sigv4': True, + } + } + + with self.assertRaises(HostRequiredError): + # No host+SigV4 == KABOOM + self.connection_class( + aws_access_key_id='less', + aws_secret_access_key='more' + ) + + # Ensure passing a ``host`` still works. + conn = self.connection_class( + aws_access_key_id='less', + aws_secret_access_key='more', + host='s3.cn-north-1.amazonaws.com.cn' + ) + self.assertEqual( + conn._required_auth_capability(), + ['hmac-v4-s3'] + ) + self.assertEqual( + conn.host, + 's3.cn-north-1.amazonaws.com.cn' + ) + + + class TestUnicodeCallingFormat(AWSMockServiceTestCase): connection_class = S3Connection |