Fix:SecretsManager :Error on Invalid secretID (#3413)
* Fix:SecretsManager :Error on Invalid secretID * Fixed tests Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
parent
9970be2309
commit
53c3eb6240
@ -342,13 +342,12 @@ class SecretsManagerBackend(BaseBackend):
|
||||
|
||||
def put_secret_value(self, secret_id, secret_string, secret_binary, version_stages):
|
||||
|
||||
if secret_id in self.secrets.keys():
|
||||
if not self._is_valid_identifier(secret_id):
|
||||
raise SecretNotFoundException()
|
||||
else:
|
||||
secret = self.secrets[secret_id]
|
||||
tags = secret.tags
|
||||
description = secret.description
|
||||
else:
|
||||
tags = []
|
||||
description = ""
|
||||
|
||||
secret = self._add_secret(
|
||||
secret_id,
|
||||
|
@ -641,9 +641,26 @@ def test_rotate_secret_rotation_period_too_long():
|
||||
)
|
||||
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_put_secret_value_on_non_existing_secret():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
with assert_raises(ClientError) as cm:
|
||||
conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="foosecret",
|
||||
VersionStages=["AWSCURRENT"],
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
"Secrets Manager can't find the specified secret.",
|
||||
cm.exception.response["Error"]["Message"],
|
||||
)
|
||||
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_put_secret_value_puts_new_secret():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.create_secret(Name=DEFAULT_SECRET_NAME, SecretBinary=b("foosecret"))
|
||||
put_secret_value_dict = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="foosecret",
|
||||
@ -662,6 +679,7 @@ def test_put_secret_value_puts_new_secret():
|
||||
@mock_secretsmanager
|
||||
def test_put_secret_binary_value_puts_new_secret():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.create_secret(Name=DEFAULT_SECRET_NAME, SecretBinary=b("foosecret"))
|
||||
put_secret_value_dict = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretBinary=b("foosecret"),
|
||||
@ -706,6 +724,7 @@ def test_put_secret_binary_requires_either_string_or_binary():
|
||||
@mock_secretsmanager
|
||||
def test_put_secret_value_can_get_first_version_if_put_twice():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.create_secret(Name=DEFAULT_SECRET_NAME, SecretBinary=b("foosecret"))
|
||||
put_secret_value_dict = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="first_secret",
|
||||
@ -729,6 +748,7 @@ def test_put_secret_value_can_get_first_version_if_put_twice():
|
||||
@mock_secretsmanager
|
||||
def test_put_secret_value_versions_differ_if_same_secret_put_twice():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.create_secret(Name=DEFAULT_SECRET_NAME, SecretBinary="foosecret")
|
||||
put_secret_value_dict = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="dupe_secret",
|
||||
@ -781,6 +801,7 @@ def test_put_secret_value_maintains_description_and_tags():
|
||||
@mock_secretsmanager
|
||||
def test_can_list_secret_version_ids():
|
||||
conn = boto3.client("secretsmanager", region_name="us-west-2")
|
||||
conn.create_secret(Name=DEFAULT_SECRET_NAME, SecretBinary="foosecret")
|
||||
put_secret_value_dict = conn.put_secret_value(
|
||||
SecretId=DEFAULT_SECRET_NAME,
|
||||
SecretString="dupe_secret",
|
||||
|
@ -408,7 +408,11 @@ def test_rotate_secret_rotation_lambda_arn_too_long():
|
||||
def test_put_secret_value_puts_new_secret():
|
||||
backend = server.create_backend_app("secretsmanager")
|
||||
test_client = backend.test_client()
|
||||
|
||||
test_client.post(
|
||||
"/",
|
||||
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
|
||||
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
|
||||
)
|
||||
test_client.post(
|
||||
"/",
|
||||
data={
|
||||
@ -458,6 +462,12 @@ def test_put_secret_value_can_get_first_version_if_put_twice():
|
||||
first_secret_string = "first_secret"
|
||||
second_secret_string = "second_secret"
|
||||
|
||||
test_client.post(
|
||||
"/",
|
||||
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
|
||||
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
|
||||
)
|
||||
|
||||
put_first_secret_value_json = test_client.post(
|
||||
"/",
|
||||
data={
|
||||
@ -507,6 +517,11 @@ def test_put_secret_value_versions_differ_if_same_secret_put_twice():
|
||||
backend = server.create_backend_app("secretsmanager")
|
||||
test_client = backend.test_client()
|
||||
|
||||
test_client.post(
|
||||
"/",
|
||||
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
|
||||
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
|
||||
)
|
||||
put_first_secret_value_json = test_client.post(
|
||||
"/",
|
||||
data={
|
||||
@ -543,6 +558,11 @@ def test_can_list_secret_version_ids():
|
||||
backend = server.create_backend_app("secretsmanager")
|
||||
test_client = backend.test_client()
|
||||
|
||||
test_client.post(
|
||||
"/",
|
||||
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
|
||||
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
|
||||
)
|
||||
put_first_secret_value_json = test_client.post(
|
||||
"/",
|
||||
data={
|
||||
|
Loading…
Reference in New Issue
Block a user