From 5d870854353ebcaf4b9a4fd8364cf49a21e226e0 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 24 Feb 2023 13:54:17 -0100 Subject: [PATCH] KMS: re_encrypt() should accept alias (#5969) --- moto/kms/responses.py | 2 +- tests/test_kms/test_kms_encrypt.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/moto/kms/responses.py b/moto/kms/responses.py index cf354d5c4..8e3d595eb 100644 --- a/moto/kms/responses.py +++ b/moto/kms/responses.py @@ -451,7 +451,7 @@ class KmsResponse(BaseResponse): "DestinationEncryptionContext", {} ) - self._validate_cmk_id(destination_key_id) + self._validate_key_id(destination_key_id) ( new_ciphertext_blob, diff --git a/tests/test_kms/test_kms_encrypt.py b/tests/test_kms/test_kms_encrypt.py index 6db34dcc3..a1b4c8aea 100644 --- a/tests/test_kms/test_kms_encrypt.py +++ b/tests/test_kms/test_kms_encrypt.py @@ -76,6 +76,24 @@ def test_encrypt_using_key_arn(): kms.encrypt(KeyId=key_details["KeyMetadata"]["Arn"], Plaintext="hello") +@mock_kms +def test_re_encrypt_using_aliases(): + client = boto3.client("kms", region_name="us-west-2") + + key_1_id = client.create_key(Description="key 1")["KeyMetadata"]["KeyId"] + key_2_arn = client.create_key(Description="key 2")["KeyMetadata"]["Arn"] + + key_alias = "alias/examplekey" + client.create_alias(AliasName=key_alias, TargetKeyId=key_2_arn) + + encrypt_response = client.encrypt(KeyId=key_1_id, Plaintext="data") + + client.re_encrypt( + CiphertextBlob=encrypt_response["CiphertextBlob"], + DestinationKeyId=key_alias, + ) + + @pytest.mark.parametrize("plaintext", PLAINTEXT_VECTORS) @mock_kms def test_decrypt(plaintext):