Modify SSM put_parameter() to raise ValidationException if value is empty string (#3806)

* Modify put_parameter() to raise ValidationError when value is empty string

* Simplify empty string check

Co-authored-by: Tom Noble <tom.noble@bjss.com>
This commit is contained in:
Tom Noble 2021-03-28 14:45:57 +01:00 committed by GitHub
parent f549f1d087
commit a001c59f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -1284,6 +1284,11 @@ class SimpleSystemManagerBackend(BaseBackend):
def put_parameter(
self, name, description, value, type, allowed_pattern, keyid, overwrite, tags,
):
if not value:
raise ValidationException(
"1 validation error detected: Value '' at 'value' failed to satisfy"
" constraint: Member must have length greater than or equal to 1."
)
if name.lower().lstrip("/").startswith("aws") or name.lower().lstrip(
"/"
).startswith("ssm"):

View File

@ -299,6 +299,22 @@ def test_put_parameter():
)
@mock_ssm
def test_put_parameter_empty_string_value():
client = boto3.client("ssm", region_name="us-east-1")
with pytest.raises(ClientError) as e:
client.put_parameter(Name="test_name", Value="", Type="String")
ex = e.value
ex.operation_name.should.equal("PutParameter")
ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.response["Error"]["Code"].should.contain("ValidationException")
ex.response["Error"]["Message"].should.equal(
"1 validation error detected: "
"Value '' at 'value' failed to satisfy constraint: "
"Member must have length greater than or equal to 1."
)
@mock_ssm
def test_put_parameter_invalid_names():
client = boto3.client("ssm", region_name="us-east-1")