need datetime for tests since thats what boto3 returns and add default for PendingWindowInDays
This commit is contained in:
parent
59c233f431
commit
9b25d56a35
@ -160,7 +160,7 @@ class KmsBackend(BaseBackend):
|
||||
self.keys[key_id].key_state = 'Disabled'
|
||||
self.keys[key_id].deletion_date = None
|
||||
|
||||
def schedule_key_deletion(self, key_id, pending_window_in_days=30):
|
||||
def schedule_key_deletion(self, key_id, pending_window_in_days):
|
||||
if key_id in self.keys:
|
||||
if 7 <= pending_window_in_days <= 30:
|
||||
self.keys[key_id].enabled = False
|
||||
|
@ -269,7 +269,10 @@ class KmsResponse(BaseResponse):
|
||||
|
||||
def schedule_key_deletion(self):
|
||||
key_id = self.parameters.get('KeyId')
|
||||
pending_window_in_days = self.parameters.get('PendingWindowInDays')
|
||||
if self.parameters.get('PendingWindowInDays') is None:
|
||||
pending_window_in_days = 30
|
||||
else:
|
||||
pending_window_in_days = self.parameters.get('PendingWindowInDays')
|
||||
_assert_valid_key_id(self.kms_backend.get_key_id(key_id))
|
||||
try:
|
||||
return json.dumps({
|
||||
|
@ -9,6 +9,7 @@ import sure # noqa
|
||||
from moto import mock_kms, mock_kms_deprecated
|
||||
from nose.tools import assert_raises
|
||||
from freezegun import freeze_time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
@mock_kms_deprecated
|
||||
@ -658,7 +659,7 @@ def test_schedule_key_deletion():
|
||||
KeyId=key['KeyMetadata']['KeyId']
|
||||
)
|
||||
assert response['KeyId'] == key['KeyMetadata']['KeyId']
|
||||
assert response['DeletionDate'] == '2015-01-31T12:00:00.000Z'
|
||||
assert response['DeletionDate'] == datetime(2015, 1, 31, 12, 0, tzinfo=tzlocal())
|
||||
|
||||
result = client.describe_key(KeyId=key['KeyMetadata']['KeyId'])
|
||||
assert result["KeyMetadata"]["Enabled"] == False
|
||||
@ -676,7 +677,7 @@ def test_schedule_key_deletion_custom():
|
||||
PendingWindowInDays=7
|
||||
)
|
||||
assert response['KeyId'] == key['KeyMetadata']['KeyId']
|
||||
assert response['DeletionDate'] == '2015-01-08T12:00:00.000Z'
|
||||
assert response['DeletionDate'] == datetime(2015, 1, 8, 12, 0, tzinfo=tzlocal())
|
||||
|
||||
result = client.describe_key(KeyId=key['KeyMetadata']['KeyId'])
|
||||
assert result["KeyMetadata"]["Enabled"] == False
|
||||
|
Loading…
Reference in New Issue
Block a user