Moto-1781: Implement server unit tests.
*** Includes 2 commented out tests that generate errors pointing deeper in the code. ***
This commit is contained in:
parent
4ced0ce0db
commit
71ed78141a
@ -154,3 +154,211 @@ 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['__type'] == 'ResourceNotFoundException'
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
create_secret = test_client.post('/',
|
||||
data={"Name": "test-secret",
|
||||
"SecretString": "foosecret"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
client_request_token = "EXAMPLE2-90ab-cdef-fedc-ba987SECRET2"
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "test-secret",
|
||||
"ClientRequestToken": client_request_token},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
assert json_data # Returned dict is not empty
|
||||
assert json_data['ARN'] == (
|
||||
'arn:aws:secretsmanager:us-east-1:1234567890:secret:test-secret-rIjad'
|
||||
)
|
||||
assert json_data['Name'] == 'test-secret'
|
||||
assert json_data['VersionId'] == client_request_token
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret_that_does_not_exist():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "i-dont-exist"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
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['__type'] == 'ResourceNotFoundException'
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret_that_does_not_match():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
create_secret = test_client.post('/',
|
||||
data={"Name": "test-secret",
|
||||
"SecretString": "foosecret"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "i-dont-match"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
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['__type'] == 'ResourceNotFoundException'
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret_client_request_token_too_short():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
create_secret = test_client.post('/',
|
||||
data={"Name": "test-secret",
|
||||
"SecretString": "foosecret"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
client_request_token = "ED9F8B6C-85B7-B7E4-38F2A3BEB13C"
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "test-secret",
|
||||
"ClientRequestToken": client_request_token},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
assert json_data['message'] == "ClientRequestToken must be 32-64 characters long."
|
||||
assert json_data['__type'] == 'InvalidParameterException'
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret_client_request_token_too_long():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
create_secret = test_client.post('/',
|
||||
data={"Name": "test-secret",
|
||||
"SecretString": "foosecret"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
client_request_token = (
|
||||
'ED9F8B6C-85B7-446A-B7E4-38F2A3BEB13C-'
|
||||
'ED9F8B6C-85B7-446A-B7E4-38F2A3BEB13C'
|
||||
)
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "test-secret",
|
||||
"ClientRequestToken": client_request_token},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
assert json_data['message'] == "ClientRequestToken must be 32-64 characters long."
|
||||
assert json_data['__type'] == 'InvalidParameterException'
|
||||
|
||||
@mock_secretsmanager
|
||||
def test_rotate_secret_rotation_lambda_arn_too_long():
|
||||
backend = server.create_backend_app('secretsmanager')
|
||||
test_client = backend.test_client()
|
||||
|
||||
create_secret = test_client.post('/',
|
||||
data={"Name": "test-secret",
|
||||
"SecretString": "foosecret"},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
rotation_lambda_arn = '85B7-446A-B7E4' * 147 # == 2058 characters
|
||||
rotate_secret = test_client.post('/',
|
||||
data={"SecretId": "test-secret",
|
||||
"RotationLambdaARN": rotation_lambda_arn},
|
||||
headers={
|
||||
"X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
},
|
||||
)
|
||||
|
||||
json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
assert json_data['message'] == "RotationLambdaARN must <= 2048 characters long."
|
||||
assert json_data['__type'] == 'InvalidParameterException'
|
||||
|
||||
|
||||
#
|
||||
# The following tests should work, but fail on the embedded dict in
|
||||
# RotationRules. The error message suggests a problem deeper in the code, which
|
||||
# needs further investigation.
|
||||
#
|
||||
|
||||
# @mock_secretsmanager
|
||||
# def test_rotate_secret_rotation_period_zero():
|
||||
# backend = server.create_backend_app('secretsmanager')
|
||||
# test_client = backend.test_client()
|
||||
|
||||
# create_secret = test_client.post('/',
|
||||
# data={"Name": "test-secret",
|
||||
# "SecretString": "foosecret"},
|
||||
# headers={
|
||||
# "X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
# },
|
||||
# )
|
||||
|
||||
# rotate_secret = test_client.post('/',
|
||||
# data={"SecretId": "test-secret",
|
||||
# "RotationRules": {"AutomaticallyAfterDays": 0}},
|
||||
# headers={
|
||||
# "X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
# },
|
||||
# )
|
||||
|
||||
# json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
# assert json_data['message'] == "RotationLambdaARN must <= 2048 characters long."
|
||||
# assert json_data['__type'] == 'InvalidParameterException'
|
||||
|
||||
# @mock_secretsmanager
|
||||
# def test_rotate_secret_rotation_period_too_long():
|
||||
# backend = server.create_backend_app('secretsmanager')
|
||||
# test_client = backend.test_client()
|
||||
|
||||
# create_secret = test_client.post('/',
|
||||
# data={"Name": "test-secret",
|
||||
# "SecretString": "foosecret"},
|
||||
# headers={
|
||||
# "X-Amz-Target": "secretsmanager.CreateSecret"
|
||||
# },
|
||||
# )
|
||||
|
||||
# rotate_secret = test_client.post('/',
|
||||
# data={"SecretId": "test-secret",
|
||||
# "RotationRules": {"AutomaticallyAfterDays": 1001}},
|
||||
# headers={
|
||||
# "X-Amz-Target": "secretsmanager.RotateSecret"
|
||||
# },
|
||||
# )
|
||||
|
||||
# json_data = json.loads(rotate_secret.data.decode("utf-8"))
|
||||
# assert json_data['message'] == "RotationLambdaARN must <= 2048 characters long."
|
||||
# assert json_data['__type'] == 'InvalidParameterException'
|
||||
|
Loading…
Reference in New Issue
Block a user