def test_encrypt_data_key_unsuccessful_clienterror(self): self.mock_client.encrypt.side_effect = ClientError({'Error': {}}, 'This is an error!') test = KMSMasterKey(config=self.mock_kms_mkc_3) with six.assertRaisesRegex(self, EncryptKeyError, 'Master Key .* unable to encrypt data key'): test._encrypt_data_key(self.mock_data_key, self.mock_algorithm)
def test_encrypt_data_key_with_grant_tokens(self): test = KMSMasterKey(config=self.mock_kms_mkc_2) test._encrypt_data_key(self.mock_data_key, self.mock_algorithm) self.mock_client.encrypt.assert_called_once_with( KeyId=VALUES['arn_str'], Plaintext=VALUES['data_key'], GrantTokens=self.mock_grant_tokens)
def test_encrypt_data_key_unsuccessful_clienterror(self): self.mock_client.encrypt.side_effect = ClientError({"Error": {}}, "This is an error!") test = KMSMasterKey(config=self.mock_kms_mkc_3) with pytest.raises(EncryptKeyError) as excinfo: test._encrypt_data_key(self.mock_data_key, self.mock_algorithm) excinfo.match("Master Key .* unable to encrypt data key")
def test_encrypt_data_key_with_encryption_context(self): test = KMSMasterKey(config=self.mock_kms_mkc_1) test._encrypt_data_key(self.mock_data_key, self.mock_algorithm, VALUES['encryption_context']) self.mock_client.encrypt.assert_called_once_with( KeyId=VALUES['arn_str'], Plaintext=VALUES['data_key'], EncryptionContext=VALUES['encryption_context'])
def test_encrypt_data_key(self): test = KMSMasterKey(config=self.mock_kms_mkc_3) encrypted_key = test._encrypt_data_key(self.mock_data_key, self.mock_algorithm) self.mock_client.encrypt.assert_called_once_with( KeyId='ex_key_info', Plaintext=VALUES['data_key']) assert encrypted_key == EncryptedDataKey( key_provider=MasterKeyInfo(provider_id=test.provider_id, key_info=VALUES['arn']), encrypted_data_key=VALUES['encrypted_data_key'])
def test_encrypt_data_key_unsuccessful_keyerror(self): self.mock_client.encrypt.side_effect = KeyError test = KMSMasterKey(config=self.mock_kms_mkc_3) with six.assertRaisesRegex(self, EncryptKeyError, "Master Key .* unable to encrypt data key"): test._encrypt_data_key(self.mock_data_key, self.mock_algorithm)