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(ibm_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')
def test_sign_with_custom_signing_name(self): request = mock.Mock() auth = mock.Mock() auth_types = {'v4': auth} with mock.patch.dict(ibm_botocore.auth.AUTH_TYPE_MAPS, auth_types): self.signer.sign('operation_name', request, signing_name='foo') auth.assert_called_with(credentials=ReadOnlyCredentials( 'key', 'secret', None), service_name='foo', region_name='region_name')
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(ibm_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)
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(ibm_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')
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(ibm_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')
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(ibm_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)
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', 'context': {} } with mock.patch.dict(ibm_botocore.auth.AUTH_TYPE_MAPS, {'v4-query': auth}): presigned_url = self.signer.generate_presigned_url( request_dict, operation_name='operation_name') auth.assert_called_with( credentials=self.fixed_credentials, region_name='region_name', service_name='signing_name', expires=3600) self.assertEqual(presigned_url, 'https://foo.com')