KMS - Validate plaintext-parameter for length (#4441)
This commit is contained in:
parent
789d878421
commit
9a55ed717f
@ -11,6 +11,7 @@ from .exceptions import (
|
|||||||
InvalidCiphertextException,
|
InvalidCiphertextException,
|
||||||
AccessDeniedException,
|
AccessDeniedException,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
|
ValidationException,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -102,6 +103,11 @@ def encrypt(master_keys, key_id, plaintext, encryption_context):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if plaintext == b"":
|
||||||
|
raise ValidationException(
|
||||||
|
"1 validation error detected: Value at 'plaintext' failed to satisfy constraint: Member must have length greater than or equal to 1"
|
||||||
|
)
|
||||||
|
|
||||||
iv = os.urandom(IV_LEN)
|
iv = os.urandom(IV_LEN)
|
||||||
aad = _serialize_encryption_context(encryption_context=encryption_context)
|
aad = _serialize_encryption_context(encryption_context=encryption_context)
|
||||||
|
|
||||||
|
@ -40,6 +40,19 @@ def test_create_key_without_description():
|
|||||||
metadata.should.have.key("Description").equal("")
|
metadata.should.have.key("Description").equal("")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_kms
|
||||||
|
def test_create_key_with_empty_content():
|
||||||
|
client_kms = boto3.client("kms", region_name="ap-northeast-1")
|
||||||
|
metadata = client_kms.create_key(Policy="my policy")["KeyMetadata"]
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client_kms.encrypt(KeyId=metadata["KeyId"], Plaintext="")
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ValidationException")
|
||||||
|
err["Message"].should.equal(
|
||||||
|
"1 validation error detected: Value at 'plaintext' failed to satisfy constraint: Member must have length greater than or equal to 1"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_kms
|
@mock_kms
|
||||||
def test_create_key():
|
def test_create_key():
|
||||||
conn = boto3.client("kms", region_name="us-east-1")
|
conn = boto3.client("kms", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user