Exemplo n.º 1
0
 def test_generate_key_data_error(self):
     kms_client = boto3.client('kms')
     key_id = "test"
     encryption_context = {}
     with Stubber(kms_client) as stubber:
         stubber.add_client_error(
             'generate_key_data',
             'KeyUnavailableException',
             'The request was rejected because the specified CMK was not available. The request can be retried.',
             500,
             expected_params={
                 'KeyId': key_id,
                 'EncryptionContext': encryption_context,
                 'NumberOfBytes': 1
             })
         key_service = KeyService(kms_client, key_id, encryption_context)
         with self.assertRaises(KmsError) as e:
             key_service.generate_key_data(1)
             self.assertEqual(
                 e,
                 KmsError(
                     "Could not generate key using KMS key %s (Details: %s)"
                     %
                     (key_id,
                      'The request was rejected because the specified CMK was not available. The request can be retried.'
                      )))
Exemplo n.º 2
0
 def test_generate_key_data_success(self):
     kms_client = boto3.client('kms')
     key_id = "test"
     encryption_context = {}
     with Stubber(kms_client) as stubber:
         stubber.add_response('generate_data_key', {
             'CiphertextBlob': b'ciphertext',
             'Plaintext': b'plaintext',
             'KeyId': 'string'
         },
                              expected_params={
                                  'KeyId': key_id,
                                  'EncryptionContext': encryption_context,
                                  'NumberOfBytes': 1
                              })
         key_service = KeyService(kms_client, key_id, encryption_context)
         response = key_service.generate_key_data(1)
     self.assertEqual(response[0], b'plaintext')
     self.assertEqual(response[1], b'ciphertext')