Example #1
0
    def test_generate_presigned_url_fixes_s3_host(self):
        self.signer = RequestSigner(
            'service_name', 'region_name', 'signing_name',
            's3', self.credentials, self.emitter)

        auth = mock.Mock()
        auth.REQUIRES_REGION = True

        request_dict = {
            'headers': {},
            'url': 'https://s3.amazonaws.com/mybucket/myobject',
            'body': b'',
            'url_path': '/',
            'method': 'GET',
            'context': {}
        }
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'s3-query': auth}):
            presigned_url = self.signer.generate_presigned_url(
                request_dict, expires_in=900)
        auth.assert_called_with(
            credentials=self.fixed_credentials, region_name='region_name',
            expires=900, service_name='signing_name')
        self.assertEqual(presigned_url,
                         'https://mybucket.s3.amazonaws.com/myobject')
Example #2
0
 def test_sign_with_region_name(self):
     auth = mock.Mock()
     auth_types = {'v4': auth}
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.sign('operation_name', self.request, region_name='foo')
     auth.assert_called_with(credentials=ReadOnlyCredentials(
         'key', 'secret', None),
                             service_name='signing_name',
                             region_name='foo')
Example #3
0
 def test_sign_override_signing_name_from_context(self):
     auth = mock.Mock()
     auth_types = {'v4': auth}
     self.request.context = {'signing': {'signing_name': 'override_name'}}
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.sign('operation_name', self.request)
     auth.assert_called_with(credentials=ReadOnlyCredentials(
         'key', 'secret', None),
                             service_name='override_name',
                             region_name='region_name')
Example #4
0
    def test_choose_signer_override(self):
        auth = mock.Mock()
        auth.REQUIRES_REGION = False
        self.emitter.emit_until_response.return_value = (None, 'custom')

        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, {'custom': auth}):
            self.signer.sign('operation_name', self.request)

        auth.assert_called_with(credentials=self.fixed_credentials)
        auth.return_value.add_auth.assert_called_with(self.request)
Example #5
0
 def test_generate_presigned_post_choose_signer_override(self):
     auth = mock.Mock()
     self.emitter.emit_until_response.return_value = (None, 'custom')
     auth_types = {
         's3v4-presign-post': self.auth,
         'custom-presign-post': auth
     }
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.generate_presigned_post(self.request_dict)
     auth.assert_called_with(
         credentials=self.fixed_credentials, region_name='region_name',
         service_name='signing_name')
Example #6
0
    def test_choose_signer_override(self):
        request = mock.Mock()
        auth = mock.Mock()
        auth.REQUIRES_REGION = False
        self.emitter.emit_until_response.return_value = (None, 'custom')

        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'custom': auth}):
            self.signer.sign('operation_name', request)

        auth.assert_called_with(credentials=self.fixed_credentials)
        auth.return_value.add_auth.assert_called_with(request)
Example #7
0
 def test_generate_presigned_post_choose_signer_override(self):
     auth = mock.Mock()
     self.emitter.emit_until_response.return_value = (None, 'custom')
     auth_types = {
         's3v4-presign-post': self.auth,
         'custom-presign-post': auth
     }
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.generate_presigned_post(self.request_dict)
     auth.assert_called_with(
         credentials=self.fixed_credentials, region_name='region_name',
         service_name='signing_name')
Example #8
0
 def test_sign_with_region_name(self):
     request = mock.Mock()
     auth = mock.Mock()
     auth_types = {
         'v4': auth
     }
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.sign('operation_name', request, region_name='foo')
     auth.assert_called_with(
         credentials=ReadOnlyCredentials('key', 'secret', None),
         service_name='signing_name',
         region_name='foo'
     )
Example #9
0
    def test_generate_presigned_url(self):
        auth = mock.Mock()
        auth.REQUIRES_REGION = True

        request_dict = {
            'headers': {},
            'url': 'https://foo.com',
            'body': b'',
            'url_path': '/',
            'method': 'GET'
        }
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'v4-query': auth}):
            presigned_url = self.signer.generate_presigned_url(request_dict)
        auth.assert_called_with(
            credentials=self.credentials, region_name='region_name',
            service_name='signing_name', expires=3600)
        self.assertEqual(presigned_url, 'https://foo.com')
Example #10
0
    def test_generate_presigned_url(self):
        auth = mock.Mock()
        auth.REQUIRES_REGION = True

        request_dict = {
            'headers': {},
            'url': 'https://foo.com',
            'body': b'',
            'url_path': '/',
            'method': 'GET'
        }
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'v4-query': auth}):
            presigned_url = self.signer.generate_presigned_url(request_dict)
        auth.assert_called_with(
            credentials=self.credentials, region_name='region_name',
            service_name='signing_name', expires=3600)
        self.assertEqual(presigned_url, 'https://foo.com')
Example #11
0
    def test_generate_url_choose_signer_override(self):
        request_dict = {
            'headers': {},
            'url': 'https://foo.com',
            'body': b'',
            'url_path': '/',
            'method': 'GET',
            'context': {}
        }
        auth = mock.Mock()
        auth.REQUIRES_REGION = False
        self.emitter.emit_until_response.return_value = (None, 'custom')

        auth_types_map = {'custom': mock.Mock(), 'custom-query': auth}
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types_map):
            self.signer.generate_presigned_url(request_dict, 'operation_name')

        auth.assert_called_with(credentials=self.fixed_credentials,
                                expires=3600)
Example #12
0
 def test_sign_with_signing_type_standard(self):
     auth = mock.Mock()
     post_auth = mock.Mock()
     query_auth = mock.Mock()
     auth_types = {
         'v4-presign-post': post_auth,
         'v4-query': query_auth,
         'v4': auth
     }
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.sign('operation_name', self.request,
                          signing_type='standard')
     self.assertFalse(post_auth.called)
     self.assertFalse(query_auth.called)
     auth.assert_called_with(
         credentials=ReadOnlyCredentials('key', 'secret', None),
         service_name='signing_name',
         region_name='region_name'
     )
Example #13
0
    def test_generate_url_choose_signer_override(self):
        request_dict = {
            'headers': {},
            'url': 'https://foo.com',
            'body': b'',
            'url_path': '/',
            'method': 'GET',
            'context': {}
        }
        auth = mock.Mock()
        auth.REQUIRES_REGION = False
        self.emitter.emit_until_response.return_value = (None, 'custom')

        auth_types_map = {'custom': mock.Mock(), 'custom-query': auth}
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types_map):
            self.signer.generate_presigned_url(request_dict, 'operation_name')

        auth.assert_called_with(credentials=self.fixed_credentials,
                                expires=3600)
Example #14
0
 def test_sign_with_signing_type_standard(self):
     auth = mock.Mock()
     post_auth = mock.Mock()
     query_auth = mock.Mock()
     request = mock.Mock()
     auth_types = {
         'v4-presign-post': post_auth,
         'v4-query': query_auth,
         'v4': auth
     }
     with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS, auth_types):
         self.signer.sign('operation_name', request,
                          signing_type='standard')
     self.assertFalse(post_auth.called)
     self.assertFalse(query_auth.called)
     auth.assert_called_with(
         credentials=ReadOnlyCredentials('key', 'secret', None),
         service_name='signing_name',
         region_name='region_name'
     )
Example #15
0
    def test_generate_presigned_url_fixes_s3_host(self):
        self.signer = RequestSigner(
            'service_name', 'region_name', 'signing_name',
            's3', self.credentials, self.emitter)

        auth = mock.Mock()
        auth.REQUIRES_REGION = True

        request_dict = {
            'headers': {},
            'url': 'https://s3.amazonaws.com/mybucket/myobject',
            'body': b'',
            'url_path': '/',
            'method': 'GET'
        }
        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'s3-query': auth}):
            presigned_url = self.signer.generate_presigned_url(
                request_dict, expires_in=900)
        auth.assert_called_with(
            credentials=self.credentials, region_name='region_name',
            expires=900, service_name='signing_name')
        self.assertEqual(presigned_url,
                         'https://mybucket.s3.amazonaws.com/myobject')