Platform independent KMS timestamp generation (#2193)

* Platform independent KMS timestamp generation

Fixes #2192

* Switch to moto.core.unix_time

Fixes #2192
This commit is contained in:
James Bungard 2019-05-22 02:46:22 +10:00 committed by Terry Cain
parent 9bf8fd3417
commit 796dd71c0c
2 changed files with 9 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import os
import boto.kms
from moto.core import BaseBackend, BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds
from moto.core.utils import iso_8601_datetime_without_milliseconds, unix_time
from .utils import generate_key_id
from collections import defaultdict
from datetime import datetime, timedelta
@ -37,7 +37,7 @@ class Key(BaseModel):
"KeyMetadata": {
"AWSAccountId": self.account_id,
"Arn": self.arn,
"CreationDate": datetime.strftime(datetime.utcnow(), "%s"),
"CreationDate": "%d" % unix_time(),
"Description": self.description,
"Enabled": self.enabled,
"KeyId": self.id,

View File

@ -18,13 +18,14 @@ from dateutil.tz import tzutc
@mock_kms_deprecated
def test_create_key():
conn = boto.kms.connect_to_region("us-west-2")
with freeze_time("2015-01-01 00:00:00"):
key = conn.create_key(policy="my policy",
description="my key", key_usage='ENCRYPT_DECRYPT')
key = conn.create_key(policy="my policy",
description="my key", key_usage='ENCRYPT_DECRYPT')
key['KeyMetadata']['Description'].should.equal("my key")
key['KeyMetadata']['KeyUsage'].should.equal("ENCRYPT_DECRYPT")
key['KeyMetadata']['Enabled'].should.equal(True)
key['KeyMetadata']['Description'].should.equal("my key")
key['KeyMetadata']['KeyUsage'].should.equal("ENCRYPT_DECRYPT")
key['KeyMetadata']['Enabled'].should.equal(True)
key['KeyMetadata']['CreationDate'].should.equal("1420070400")
@mock_kms_deprecated
@ -980,5 +981,3 @@ def test_put_key_policy_key_not_found():
PolicyName='default',
Policy='new policy'
)