updates kms to use tagging service and support untag_resource
This commit is contained in:
parent
445f474534
commit
d1efedec29
3 changed files with 53 additions and 23 deletions
|
|
@ -680,3 +680,46 @@ def test__assert_default_policy():
|
|||
_assert_default_policy.when.called_with("default").should_not.throw(
|
||||
MotoNotFoundException
|
||||
)
|
||||
|
||||
|
||||
@mock_kms
|
||||
def test_key_tagging_happy():
|
||||
client = boto3.client("kms", region_name="us-east-1")
|
||||
key = client.create_key(Description="test-key-tagging")
|
||||
key_id = key["KeyMetadata"]["KeyId"]
|
||||
|
||||
tags = [{"TagKey": "key1", "TagValue": "value1"}, {"TagKey": "key2", "TagValue": "value2"}]
|
||||
client.tag_resource(KeyId=key_id, Tags=tags)
|
||||
|
||||
result = client.list_resource_tags(KeyId=key_id)
|
||||
actual = result.get("Tags", [])
|
||||
assert tags == actual
|
||||
|
||||
client.untag_resource(KeyId=key_id, TagKeys=["key1"])
|
||||
|
||||
actual = client.list_resource_tags(KeyId=key_id).get("Tags", [])
|
||||
expected = [{"TagKey": "key2", "TagValue": "value2"}]
|
||||
assert expected == actual
|
||||
|
||||
|
||||
@mock_kms
|
||||
def test_key_tagging_sad():
|
||||
b = KmsBackend()
|
||||
|
||||
try:
|
||||
b.tag_resource('unknown', [])
|
||||
raise 'tag_resource should fail if KeyId is not known'
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
||||
try:
|
||||
b.untag_resource('unknown', [])
|
||||
raise 'untag_resource should fail if KeyId is not known'
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
||||
try:
|
||||
b.list_resource_tags('unknown')
|
||||
raise 'list_resource_tags should fail if KeyId is not known'
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ def test_deserialize_ciphertext_blob(raw, serialized):
|
|||
@parameterized(((ec[0],) for ec in ENCRYPTION_CONTEXT_VECTORS))
|
||||
def test_encrypt_decrypt_cycle(encryption_context):
|
||||
plaintext = b"some secret plaintext"
|
||||
master_key = Key("nop", "nop", "nop", "nop", [], "nop")
|
||||
master_key = Key("nop", "nop", "nop", "nop", "nop")
|
||||
master_key_map = {master_key.id: master_key}
|
||||
|
||||
ciphertext_blob = encrypt(
|
||||
|
|
@ -133,7 +133,7 @@ def test_encrypt_unknown_key_id():
|
|||
|
||||
|
||||
def test_decrypt_invalid_ciphertext_format():
|
||||
master_key = Key("nop", "nop", "nop", "nop", [], "nop")
|
||||
master_key = Key("nop", "nop", "nop", "nop", "nop")
|
||||
master_key_map = {master_key.id: master_key}
|
||||
|
||||
with assert_raises(InvalidCiphertextException):
|
||||
|
|
@ -153,7 +153,7 @@ def test_decrypt_unknwown_key_id():
|
|||
|
||||
|
||||
def test_decrypt_invalid_ciphertext():
|
||||
master_key = Key("nop", "nop", "nop", "nop", [], "nop")
|
||||
master_key = Key("nop", "nop", "nop", "nop", "nop")
|
||||
master_key_map = {master_key.id: master_key}
|
||||
ciphertext_blob = (
|
||||
master_key.id.encode("utf-8") + b"123456789012"
|
||||
|
|
@ -171,7 +171,7 @@ def test_decrypt_invalid_ciphertext():
|
|||
|
||||
def test_decrypt_invalid_encryption_context():
|
||||
plaintext = b"some secret plaintext"
|
||||
master_key = Key("nop", "nop", "nop", "nop", [], "nop")
|
||||
master_key = Key("nop", "nop", "nop", "nop", "nop")
|
||||
master_key_map = {master_key.id: master_key}
|
||||
|
||||
ciphertext_blob = encrypt(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue