Enforce parameter naming (#3190)

* Enforce parameter naming

Parameters are not allowed to start with `ssm` or `aws`. This commit adds error messages which
correspond exactly to the error messages returned by boto3.

* Fix for Python 2 compatibility

f-strings not supported in Python 2.7
This commit is contained in:
Jordan Reiter 2020-07-28 10:26:59 -04:00 committed by GitHub
commit 28d1d762af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 0 deletions

View file

@ -299,6 +299,73 @@ def test_put_parameter():
)
@mock_ssm
def test_put_parameter_invalid_names():
client = boto3.client("ssm", region_name="us-east-1")
invalid_prefix_err = (
'Parameter name: can\'t be prefixed with "aws" or "ssm" (case-insensitive).'
)
client.put_parameter.when.called_with(
Name="ssm_test", Value="value", Type="String"
).should.throw(
ClientError, invalid_prefix_err,
)
client.put_parameter.when.called_with(
Name="SSM_TEST", Value="value", Type="String"
).should.throw(
ClientError, invalid_prefix_err,
)
client.put_parameter.when.called_with(
Name="aws_test", Value="value", Type="String"
).should.throw(
ClientError, invalid_prefix_err,
)
client.put_parameter.when.called_with(
Name="AWS_TEST", Value="value", Type="String"
).should.throw(
ClientError, invalid_prefix_err,
)
ssm_path = "/ssm_test/path/to/var"
client.put_parameter.when.called_with(
Name=ssm_path, Value="value", Type="String"
).should.throw(
ClientError,
'Parameter name: can\'t be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of '
"sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following "
"3 symbols .-_",
)
ssm_path = "/SSM/PATH/TO/VAR"
client.put_parameter.when.called_with(
Name=ssm_path, Value="value", Type="String"
).should.throw(
ClientError,
'Parameter name: can\'t be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of '
"sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following "
"3 symbols .-_",
)
aws_path = "/aws_test/path/to/var"
client.put_parameter.when.called_with(
Name=aws_path, Value="value", Type="String"
).should.throw(
ClientError, "No access to reserved parameter name: {}.".format(aws_path),
)
aws_path = "/AWS/PATH/TO/VAR"
client.put_parameter.when.called_with(
Name=aws_path, Value="value", Type="String"
).should.throw(
ClientError, "No access to reserved parameter name: {}.".format(aws_path),
)
@mock_ssm
def test_put_parameter_china():
client = boto3.client("ssm", region_name="cn-north-1")