From dcdaca898437dc88bc00ddb53db69ed579460f3f Mon Sep 17 00:00:00 2001 From: Nate Peterson Date: Fri, 13 Jul 2018 03:24:11 -0600 Subject: [PATCH] parameters return from root path (#1701) --- moto/ssm/models.py | 2 +- tests/test_ssm/test_ssm_boto3.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/moto/ssm/models.py b/moto/ssm/models.py index aaeccc887..bdc98e61b 100644 --- a/moto/ssm/models.py +++ b/moto/ssm/models.py @@ -100,7 +100,7 @@ class SimpleSystemManagerBackend(BaseBackend): # difference here. path = path.rstrip('/') + '/' for param in self._parameters: - if not param.startswith(path): + if path != '/' and not param.startswith(path): continue if '/' in param[len(path) + 1:] and not recursive: continue diff --git a/tests/test_ssm/test_ssm_boto3.py b/tests/test_ssm/test_ssm_boto3.py index ad48fd7ed..e58879bc7 100644 --- a/tests/test_ssm/test_ssm_boto3.py +++ b/tests/test_ssm/test_ssm_boto3.py @@ -95,6 +95,27 @@ def test_get_parameters_by_path(): Type='SecureString', KeyId='alias/aws/ssm') + client.put_parameter( + Name='foo', + Description='A test parameter', + Value='bar', + Type='String') + + client.put_parameter( + Name='baz', + Description='A test parameter', + Value='qux', + Type='String') + + response = client.get_parameters_by_path(Path='/', Recursive=False) + len(response['Parameters']).should.equal(2) + {p['Value'] for p in response['Parameters']}.should.equal( + set(['bar', 'qux']) + ) + + response = client.get_parameters_by_path(Path='/', Recursive=True) + len(response['Parameters']).should.equal(9) + response = client.get_parameters_by_path(Path='/foo') len(response['Parameters']).should.equal(2) {p['Value'] for p in response['Parameters']}.should.equal( @@ -417,6 +438,7 @@ def test_describe_parameters_filter_keyid(): response['Parameters'][0]['Type'].should.equal('SecureString') ''.should.equal(response.get('NextToken', '')) + @mock_ssm def test_describe_parameters_attributes(): client = boto3.client('ssm', region_name='us-east-1') @@ -445,6 +467,7 @@ def test_describe_parameters_attributes(): response['Parameters'][1].get('Description').should.be.none response['Parameters'][1]['Version'].should.equal(1) + @mock_ssm def test_get_parameter_invalid(): client = client = boto3.client('ssm', region_name='us-east-1')