From c0853aa99d1897ef8f3b85160b86f44d6aed68d6 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sat, 18 Sep 2021 21:12:18 +0000 Subject: [PATCH] KMS - CreateKey without desc should return empty desc (#4305) --- moto/kms/models.py | 2 +- tests/test_kms/test_kms_boto3.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/moto/kms/models.py b/moto/kms/models.py index 54bf37231..b4eeb638d 100644 --- a/moto/kms/models.py +++ b/moto/kms/models.py @@ -24,7 +24,7 @@ class Key(CloudFormationModel): self.policy = policy or self.generate_default_policy() self.key_usage = key_usage self.key_state = "Enabled" - self.description = description + self.description = description or "" self.enabled = True self.region = region self.account_id = ACCOUNT_ID diff --git a/tests/test_kms/test_kms_boto3.py b/tests/test_kms/test_kms_boto3.py index 4e2f348b8..8b29ad748 100644 --- a/tests/test_kms/test_kms_boto3.py +++ b/tests/test_kms/test_kms_boto3.py @@ -30,6 +30,17 @@ def _get_encoded_value(plaintext): return plaintext.encode("utf-8") +@mock_kms +def test_create_key_without_description(): + conn = boto3.client("kms", region_name="us-east-1") + metadata = conn.create_key(Policy="my policy")["KeyMetadata"] + + metadata.should.have.key("AWSAccountId").equals(ACCOUNT_ID) + metadata.should.have.key("KeyId") + metadata.should.have.key("Arn") + metadata.should.have.key("Description").equal("") + + @mock_kms def test_create_key(): conn = boto3.client("kms", region_name="us-east-1") @@ -41,9 +52,11 @@ def test_create_key(): ) key["KeyMetadata"]["Arn"].should.equal( - "arn:aws:kms:us-east-1:123456789012:key/{}".format(key["KeyMetadata"]["KeyId"]) + "arn:aws:kms:us-east-1:{}:key/{}".format( + ACCOUNT_ID, key["KeyMetadata"]["KeyId"] + ) ) - key["KeyMetadata"]["AWSAccountId"].should.equal("123456789012") + key["KeyMetadata"]["AWSAccountId"].should.equal(ACCOUNT_ID) key["KeyMetadata"]["CreationDate"].should.be.a(datetime) key["KeyMetadata"]["CustomerMasterKeySpec"].should.equal("SYMMETRIC_DEFAULT") key["KeyMetadata"]["Description"].should.equal("my key")