def test_generate_data_key_with_grant_tokens(self): test = KMSMasterKey(config=self.mock_kms_mkc_2) test._generate_data_key(self.mock_algorithm) self.mock_client.generate_data_key.assert_called_once_with( KeyId=VALUES["arn_str"], NumberOfBytes=sentinel.kdf_input_len, GrantTokens=self.mock_grant_tokens)
def test_generate_data_key_unsuccessful_keyerror(self): self.mock_client.generate_data_key.side_effect = KeyError test = KMSMasterKey(config=self.mock_kms_mkc_3) with six.assertRaisesRegex( self, GenerateKeyError, 'Master Key .* unable to generate data key'): test._generate_data_key(self.mock_algorithm)
def test_generate_data_key_unsuccessful_clienterror(self): self.mock_client.generate_data_key.side_effect = ClientError( {"Error": {}}, "This is an error!") test = KMSMasterKey(config=self.mock_kms_mkc_3) with pytest.raises(GenerateKeyError) as excinfo: test._generate_data_key(self.mock_algorithm) excinfo.match("Master Key .* unable to generate data key")
def test_generate_data_key_with_encryption_context(self): test = KMSMasterKey(config=self.mock_kms_mkc_1) test._generate_data_key(self.mock_algorithm, VALUES['encryption_context']) self.mock_client.generate_data_key.assert_called_once_with( KeyId=VALUES['arn_str'], NumberOfBytes=sentinel.kdf_input_len, EncryptionContext=VALUES['encryption_context'])
def test_generate_data_key_unsuccessful_clienterror(self): self.mock_client.generate_data_key.side_effect = ClientError( {"Error": {}}, "This is an error!") test = KMSMasterKey(config=self.mock_kms_mkc_3) with six.assertRaisesRegex( self, GenerateKeyError, "Master Key .* unable to generate data key"): test._generate_data_key(self.mock_algorithm)
def test_generate_data_key(self): test = KMSMasterKey(config=self.mock_kms_mkc_3) generated_key = test._generate_data_key(self.mock_algorithm) self.mock_client.generate_data_key.assert_called_once_with( KeyId='ex_key_info', NumberOfBytes=sentinel.kdf_input_len) assert generated_key == DataKey( key_provider=MasterKeyInfo(provider_id=test.provider_id, key_info=VALUES['arn']), data_key=VALUES['data_key'], encrypted_data_key=VALUES['encrypted_data_key'])