add proper KMS encrypt, decrypt, and generate_data_key functionality and tests
This commit is contained in:
parent
3fe8afaa60
commit
98581b9196
4 changed files with 550 additions and 558 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
from parameterized import parameterized
|
||||
|
||||
|
|
@ -104,26 +105,23 @@ def test_encrypt_decrypt_cycle(encryption_context):
|
|||
|
||||
|
||||
def test_encrypt_unknown_key_id():
|
||||
assert_raises(
|
||||
NotFoundException, encrypt, master_keys={}, key_id="anything", plaintext=b"secrets", encryption_context={}
|
||||
)
|
||||
with assert_raises(NotFoundException):
|
||||
encrypt(master_keys={}, key_id="anything", plaintext=b"secrets", encryption_context={})
|
||||
|
||||
|
||||
def test_decrypt_invalid_ciphertext_format():
|
||||
master_key = Key("nop", "nop", "nop", [], "nop")
|
||||
master_key_map = {master_key.id: master_key}
|
||||
|
||||
assert_raises(
|
||||
InvalidCiphertextException, decrypt, master_keys=master_key_map, ciphertext_blob=b"", encryption_context={}
|
||||
)
|
||||
with assert_raises(InvalidCiphertextException):
|
||||
decrypt(master_keys=master_key_map, ciphertext_blob=b"", encryption_context={})
|
||||
|
||||
|
||||
def test_decrypt_unknwown_key_id():
|
||||
ciphertext_blob = b"d25652e4-d2d2-49f7-929a-671ccda580c6" b"123456789012" b"1234567890123456" b"some ciphertext"
|
||||
|
||||
assert_raises(
|
||||
AccessDeniedException, decrypt, master_keys={}, ciphertext_blob=ciphertext_blob, encryption_context={}
|
||||
)
|
||||
with assert_raises(AccessDeniedException):
|
||||
decrypt(master_keys={}, ciphertext_blob=ciphertext_blob, encryption_context={})
|
||||
|
||||
|
||||
def test_decrypt_invalid_ciphertext():
|
||||
|
|
@ -131,13 +129,12 @@ def test_decrypt_invalid_ciphertext():
|
|||
master_key_map = {master_key.id: master_key}
|
||||
ciphertext_blob = master_key.id.encode("utf-8") + b"123456789012" b"1234567890123456" b"some ciphertext"
|
||||
|
||||
assert_raises(
|
||||
InvalidCiphertextException,
|
||||
decrypt,
|
||||
master_keys=master_key_map,
|
||||
ciphertext_blob=ciphertext_blob,
|
||||
encryption_context={},
|
||||
)
|
||||
with assert_raises(InvalidCiphertextException):
|
||||
decrypt(
|
||||
master_keys=master_key_map,
|
||||
ciphertext_blob=ciphertext_blob,
|
||||
encryption_context={},
|
||||
)
|
||||
|
||||
|
||||
def test_decrypt_invalid_encryption_context():
|
||||
|
|
@ -152,10 +149,9 @@ def test_decrypt_invalid_encryption_context():
|
|||
encryption_context={"some": "encryption", "context": "here"},
|
||||
)
|
||||
|
||||
assert_raises(
|
||||
InvalidCiphertextException,
|
||||
decrypt,
|
||||
master_keys=master_key_map,
|
||||
ciphertext_blob=ciphertext_blob,
|
||||
encryption_context={},
|
||||
)
|
||||
with assert_raises(InvalidCiphertextException):
|
||||
decrypt(
|
||||
master_keys=master_key_map,
|
||||
ciphertext_blob=ciphertext_blob,
|
||||
encryption_context={},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue