Repository: getmoto/moto

Issue:
kms.create_key response is missing description, when not specified
Hi,

Thanks for developing moto!

I am using version 2.2.6.  Working on adding tests to code that does:

```
        key_metadata = client.create_key(KeyUsage=key_usage,
                                         CustomerMasterKeySpec=customer_master_key_spec,
                                         Origin=origin)['KeyMetadata']
```

As you see, no description is given.

I expect the metadata to contain the `Description` field as to an empty string.

Actual behaviour: the dict does not contain the `Description` field.

--

I believe this is a bug. Quoting the boto3 `kms.create_key` parameter docs :

(tldr; default value is an empty string.)

> Description (string) --
A description of the KMS key.
Use a description that helps you decide whether the KMS key is appropriate for a task. The default value is an empty string (no description).

Same doc section says the response will contain the field:

```
{
    'KeyMetadata': {
        .....
        'Description': 'string',
        .....
```

--

Obviously, the workaround is to pass `Description=''`, but I assume moto is supposed to work without requiring code changed to code-under-test.

Thanks, again






Discussion:
Thanks for raising this @rtoma! Will mark it as a bug

Resolving patch:
diff --git a/moto/kms/models.py b/moto/kms/models.py
--- a/moto/kms/models.py
+++ b/moto/kms/models.py
@@ -24,7 +24,7 @@ def __init__(
         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


Test patch:
diff --git a/tests/test_kms/test_kms_boto3.py b/tests/test_kms/test_kms_boto3.py
--- 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")