Merge pull request #2481 from aacampbell/fix_getsecretmananger_error

Fix getsecretmananger error
This commit is contained in:
Mike Grima 2019-10-18 09:50:43 -07:00 committed by GitHub
commit 382fe5bd68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 19 deletions

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import boto3
@ -8,7 +9,7 @@ import string
import pytz
from datetime import datetime
import sure # noqa
from nose.tools import assert_raises
from nose.tools import assert_raises, assert_equal
from six import b
DEFAULT_SECRET_NAME = 'test-secret'
@ -38,9 +39,14 @@ def test_get_secret_value_binary():
def test_get_secret_that_does_not_exist():
conn = boto3.client('secretsmanager', region_name='us-west-2')
with assert_raises(ClientError):
with assert_raises(ClientError) as cm:
result = conn.get_secret_value(SecretId='i-dont-exist')
assert_equal(
u"Secrets Manager can\u2019t find the specified secret.",
cm.exception.response['Error']['Message']
)
@mock_secretsmanager
def test_get_secret_that_does_not_match():
@ -48,9 +54,14 @@ def test_get_secret_that_does_not_match():
create_secret = conn.create_secret(Name='java-util-test-password',
SecretString="foosecret")
with assert_raises(ClientError):
with assert_raises(ClientError) as cm:
result = conn.get_secret_value(SecretId='i-dont-match')
assert_equal(
u"Secrets Manager can\u2019t find the specified secret.",
cm.exception.response['Error']['Message']
)
@mock_secretsmanager
def test_get_secret_value_that_is_marked_deleted():
@ -65,6 +76,21 @@ def test_get_secret_value_that_is_marked_deleted():
result = conn.get_secret_value(SecretId='test-secret')
@mock_secretsmanager
def test_get_secret_that_has_no_value():
conn = boto3.client('secretsmanager', region_name='us-west-2')
create_secret = conn.create_secret(Name="java-util-test-password")
with assert_raises(ClientError) as cm:
result = conn.get_secret_value(SecretId='java-util-test-password')
assert_equal(
u"Secrets Manager can\u2019t find the specified secret value for staging label: AWSCURRENT",
cm.exception.response['Error']['Message']
)
@mock_secretsmanager
def test_create_secret():
conn = boto3.client('secretsmanager', region_name='us-east-1')

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
@ -49,7 +50,7 @@ def test_get_secret_that_does_not_exist():
"X-Amz-Target": "secretsmanager.GetSecretValue"},
)
json_data = json.loads(get_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
@ -70,7 +71,27 @@ def test_get_secret_that_does_not_match():
"X-Amz-Target": "secretsmanager.GetSecretValue"},
)
json_data = json.loads(get_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
def test_get_secret_that_has_no_value():
backend = server.create_backend_app('secretsmanager')
test_client = backend.test_client()
create_secret = test_client.post('/',
data={"Name": DEFAULT_SECRET_NAME},
headers={
"X-Amz-Target": "secretsmanager.CreateSecret"},
)
get_secret = test_client.post('/',
data={"SecretId": DEFAULT_SECRET_NAME},
headers={
"X-Amz-Target": "secretsmanager.GetSecretValue"},
)
json_data = json.loads(get_secret.data.decode("utf-8"))
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret value for staging label: AWSCURRENT"
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
@ -158,7 +179,7 @@ def test_describe_secret_that_does_not_exist():
)
json_data = json.loads(describe_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
@ -182,7 +203,7 @@ def test_describe_secret_that_does_not_match():
)
json_data = json.loads(describe_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
@ -283,7 +304,7 @@ def test_rotate_secret_that_does_not_exist():
)
json_data = json.loads(rotate_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager
@ -307,7 +328,7 @@ def test_rotate_secret_that_does_not_match():
)
json_data = json.loads(rotate_secret.data.decode("utf-8"))
assert json_data['message'] == "Secrets Manager can't find the specified secret"
assert json_data['message'] == u"Secrets Manager can\u2019t find the specified secret."
assert json_data['__type'] == 'ResourceNotFoundException'
@mock_secretsmanager