diff --git a/moto/ssm/models.py b/moto/ssm/models.py index 5c2a5cce7..775219ee1 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -1007,7 +1007,7 @@ class SimpleSystemManagerBackend(BaseBackend): if ( "//" in value or not value.startswith("/") - or not re.match("^[a-zA-Z0-9_.-/]*$", value) + or not re.match(r"^[a-zA-Z0-9_.\-/]*$", value) ): raise ValidationException( 'The parameter doesn\'t meet the parameter name requirements. The parameter name must begin with a forward slash "/". ' diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index 73b80c893..b1dc63709 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -227,43 +227,46 @@ def test_get_parameters_by_path(): ) +@pytest.mark.parametrize("name", ["test", "my-cool-parameter"]) @mock_ssm -def test_put_parameter(): +def test_put_parameter(name): client = boto3.client("ssm", region_name="us-east-1") response = client.put_parameter( - Name="test", Description="A test parameter", Value="value", Type="String" + Name=name, Description="A test parameter", Value="value", Type="String" ) response["Version"].should.equal(1) - response = client.get_parameters(Names=["test"], WithDecryption=False) + response = client.get_parameters(Names=[name], WithDecryption=False) len(response["Parameters"]).should.equal(1) - response["Parameters"][0]["Name"].should.equal("test") + response["Parameters"][0]["Name"].should.equal(name) response["Parameters"][0]["Value"].should.equal("value") response["Parameters"][0]["Type"].should.equal("String") response["Parameters"][0]["Version"].should.equal(1) response["Parameters"][0]["LastModifiedDate"].should.be.a(datetime.datetime) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test" + "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) ) initial_modification_date = response["Parameters"][0]["LastModifiedDate"] try: client.put_parameter( - Name="test", Description="desc 2", Value="value 2", Type="String" + Name=name, Description="desc 2", Value="value 2", Type="String" ) raise RuntimeError("Should fail") except botocore.exceptions.ClientError as err: err.operation_name.should.equal("PutParameter") - err.response["Error"]["Message"].should.equal("Parameter test already exists.") + err.response["Error"]["Message"].should.equal( + "Parameter {} already exists.".format(name) + ) - response = client.get_parameters(Names=["test"], WithDecryption=False) + response = client.get_parameters(Names=[name], WithDecryption=False) # without overwrite nothing change len(response["Parameters"]).should.equal(1) - response["Parameters"][0]["Name"].should.equal("test") + response["Parameters"][0]["Name"].should.equal(name) response["Parameters"][0]["Value"].should.equal("value") response["Parameters"][0]["Type"].should.equal("String") response["Parameters"][0]["Version"].should.equal(1) @@ -271,24 +274,20 @@ def test_put_parameter(): initial_modification_date ) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test" + "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) ) response = client.put_parameter( - Name="test", - Description="desc 3", - Value="value 3", - Type="String", - Overwrite=True, + Name=name, Description="desc 3", Value="value 3", Type="String", Overwrite=True, ) response["Version"].should.equal(2) - response = client.get_parameters(Names=["test"], WithDecryption=False) + response = client.get_parameters(Names=[name], WithDecryption=False) # without overwrite nothing change len(response["Parameters"]).should.equal(1) - response["Parameters"][0]["Name"].should.equal("test") + response["Parameters"][0]["Name"].should.equal(name) response["Parameters"][0]["Value"].should.equal("value 3") response["Parameters"][0]["Type"].should.equal("String") response["Parameters"][0]["Version"].should.equal(2) @@ -296,7 +295,7 @@ def test_put_parameter(): initial_modification_date ) response["Parameters"][0]["ARN"].should.equal( - "arn:aws:ssm:us-east-1:1234567890:parameter/test" + "arn:aws:ssm:us-east-1:1234567890:parameter/{}".format(name) ) @@ -1393,7 +1392,7 @@ def test_label_parameter_version_invalid_name(): test_parameter_name = "test" - response = client.label_parameter_version.when.called_with( + client.label_parameter_version.when.called_with( Name=test_parameter_name, Labels=["test-label"] ).should.throw( ClientError, @@ -1414,7 +1413,7 @@ def test_label_parameter_version_invalid_parameter_version(): Type="String", ) - response = client.label_parameter_version.when.called_with( + client.label_parameter_version.when.called_with( Name=test_parameter_name, Labels=["test-label"], ParameterVersion=5 ).should.throw( ClientError,