From a001c59f7e7c3710e92a1d9e2a915fcaad0ffeff Mon Sep 17 00:00:00 2001 From: Tom Noble <53005340+TSNoble@users.noreply.github.com> Date: Sun, 28 Mar 2021 14:45:57 +0100 Subject: [PATCH] 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 --- moto/ssm/models.py | 5 +++++ tests/test_ssm/test_ssm_boto3.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/moto/ssm/models.py b/moto/ssm/models.py index 8743e129c..5d378c499 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -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"): diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 6c4a20025..2b3a7c731 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -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")