Fix ssm.get_parameters missing validation
This commit is contained in:
parent
323877c15d
commit
3b8c8fafe2
@ -514,6 +514,16 @@ class SimpleSystemManagerBackend(BaseBackend):
|
|||||||
|
|
||||||
def get_parameters(self, names, with_decryption):
|
def get_parameters(self, names, with_decryption):
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
if len(names) > 10:
|
||||||
|
raise ValidationException(
|
||||||
|
"1 validation error detected: "
|
||||||
|
"Value '[{}]' at 'names' failed to satisfy constraint: "
|
||||||
|
"Member must have length less than or equal to 10.".format(
|
||||||
|
", ".join(names)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
if name in self._parameters:
|
if name in self._parameters:
|
||||||
result.append(self.get_parameter(name, with_decryption))
|
result.append(self.get_parameter(name, with_decryption))
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import string
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import botocore.exceptions
|
import botocore.exceptions
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
@ -300,6 +302,31 @@ def test_get_parameter():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ssm
|
||||||
|
def test_get_parameters_errors():
|
||||||
|
client = boto3.client("ssm", region_name="us-east-1")
|
||||||
|
|
||||||
|
ssm_parameters = {name: "value" for name in string.ascii_lowercase[:11]}
|
||||||
|
|
||||||
|
for name, value in ssm_parameters.items():
|
||||||
|
client.put_parameter(Name=name, Value=value, Type="String")
|
||||||
|
|
||||||
|
with assert_raises(ClientError) as e:
|
||||||
|
client.get_parameters(Names=list(ssm_parameters.keys()))
|
||||||
|
ex = e.exception
|
||||||
|
ex.operation_name.should.equal("GetParameters")
|
||||||
|
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 'names' failed to satisfy constraint: "
|
||||||
|
"Member must have length less than or equal to 10.".format(
|
||||||
|
", ".join(ssm_parameters.keys())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print(ex.response["Error"]["Message"])
|
||||||
|
|
||||||
|
|
||||||
@mock_ssm
|
@mock_ssm
|
||||||
def test_get_nonexistant_parameter():
|
def test_get_nonexistant_parameter():
|
||||||
client = boto3.client("ssm", region_name="us-east-1")
|
client = boto3.client("ssm", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user