Escape Hyphen in Regular Expression (#4006)

* Escape Hyphen in Regular Expression

* Add Test

* Fix Linting Errors

* Use Pytest Parameterize Marker

* Fix Black Formatting Errors

* Interpolate / Use Raw String

* fixes string formatting

Co-authored-by: Correna Sprowls <correna.sprowls@joinroot.com>
This commit is contained in:
Kyle Decot 2021-06-11 16:54:43 -04:00 committed by GitHub
parent 479ce861a7
commit 8d4007f2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 21 deletions

View File

@ -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 "/". '

View File

@ -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,