From 061c609a8f24bd84d0d0892a78074aad5c35b42a Mon Sep 17 00:00:00 2001 From: Ninh Khong Date: Mon, 3 Aug 2020 19:42:42 +0700 Subject: [PATCH] Fix secretsmanager random password wrong length (#3213) * Enhance function get_parameter by parameter name, version or labels * Fix random password with exclude characters return wrong length --- moto/secretsmanager/utils.py | 3 ++- tests/test_secretsmanager/test_secretsmanager.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/moto/secretsmanager/utils.py b/moto/secretsmanager/utils.py index 6033db613..ab0f584f0 100644 --- a/moto/secretsmanager/utils.py +++ b/moto/secretsmanager/utils.py @@ -51,6 +51,8 @@ def random_password( if include_space: password += " " required_characters += " " + if exclude_characters: + password = _exclude_characters(password, exclude_characters) password = "".join( six.text_type(random.choice(password)) for x in range(password_length) @@ -61,7 +63,6 @@ def random_password( password, required_characters ) - password = _exclude_characters(password, exclude_characters) return password diff --git a/tests/test_secretsmanager/test_secretsmanager.py b/tests/test_secretsmanager/test_secretsmanager.py index 0bd66b128..69e055bb2 100644 --- a/tests/test_secretsmanager/test_secretsmanager.py +++ b/tests/test_secretsmanager/test_secretsmanager.py @@ -338,6 +338,7 @@ def test_get_random_exclude_characters_and_symbols(): PasswordLength=20, ExcludeCharacters="xyzDje@?!." ) assert any(c in "xyzDje@?!." for c in random_password["RandomPassword"]) == False + assert len(random_password["RandomPassword"]) == 20 @mock_secretsmanager