Skip to content

Commit

Permalink
add test for secrets manager and apigateway
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutierMat committed Oct 15, 2024
1 parent 0d9939a commit 95e7611
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
44 changes: 33 additions & 11 deletions tests/test_apigateway/test_apigateway_custom_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
ApigwRestApiIdentifier,
ApigwUsagePlanIdentifier,
)
from moto.utilities.id_generator import TAG_KEY_CUSTOM_ID
from tests import DEFAULT_ACCOUNT_ID

API_ID = "ApiId"
API_KEY_ID = "ApiKeyId"
Expand All @@ -27,7 +29,7 @@
@pytest.mark.skipif(
not settings.TEST_DECORATOR_MODE, reason="Can't access the id manager in proxy mode"
)
def test_custom_id_rest_api(set_custom_id, account_id):
def test_custom_id_rest_api(set_custom_id):
region_name = "us-west-2"
rest_api_name = "my-api"
model_name = "modelName"
Expand All @@ -37,33 +39,40 @@ def test_custom_id_rest_api(set_custom_id, account_id):
client = boto3.client("apigateway", region_name=region_name)

set_custom_id(
ApigwRestApiIdentifier(account_id, region_name, rest_api_name), API_ID
ApigwRestApiIdentifier(DEFAULT_ACCOUNT_ID, region_name, rest_api_name), API_ID
)
set_custom_id(
ApigwResourceIdentifier(account_id, region_name, path_name="/"),
ApigwResourceIdentifier(DEFAULT_ACCOUNT_ID, region_name, path_name="/"),
ROOT_RESOURCE_ID,
)
set_custom_id(
ApigwResourceIdentifier(
account_id, region_name, parent_id=ROOT_RESOURCE_ID, path_name="pet"
DEFAULT_ACCOUNT_ID, region_name, parent_id=ROOT_RESOURCE_ID, path_name="pet"
),
PET_1_RESOURCE_ID,
)
set_custom_id(
ApigwResourceIdentifier(
account_id, region_name, parent_id=PET_1_RESOURCE_ID, path_name="pet"
DEFAULT_ACCOUNT_ID,
region_name,
parent_id=PET_1_RESOURCE_ID,
path_name="pet",
),
PET_2_RESOURCE_ID,
)
set_custom_id(ApigwModelIdentifier(account_id, region_name, model_name), MODEL_ID)
set_custom_id(
ApigwModelIdentifier(DEFAULT_ACCOUNT_ID, region_name, model_name), MODEL_ID
)
set_custom_id(
ApigwRequestValidatorIdentifier(
account_id, region_name, request_validator_name
DEFAULT_ACCOUNT_ID, region_name, request_validator_name
),
REQUEST_VALIDATOR_ID,
)
set_custom_id(
ApigwDeploymentIdentifier(account_id, region_name, stage_name=stage_name),
ApigwDeploymentIdentifier(
DEFAULT_ACCOUNT_ID, region_name, stage_name=stage_name
),
DEPLOYMENT_ID,
)

Expand Down Expand Up @@ -113,18 +122,19 @@ def test_custom_id_rest_api(set_custom_id, account_id):
@pytest.mark.skipif(
not settings.TEST_DECORATOR_MODE, reason="Can't access the id manager in proxy mode"
)
def test_custom_id_api_key(account_id, set_custom_id):
def test_custom_id_api_key(set_custom_id):
region_name = "us-west-2"
api_key_value = "01234567890123456789"
usage_plan_name = "usage-plan"

client = boto3.client("apigateway", region_name=region_name)

set_custom_id(
ApigwApiKeyIdentifier(account_id, region_name, value=api_key_value), API_KEY_ID
ApigwApiKeyIdentifier(DEFAULT_ACCOUNT_ID, region_name, value=api_key_value),
API_KEY_ID,
)
set_custom_id(
ApigwUsagePlanIdentifier(account_id, region_name, usage_plan_name),
ApigwUsagePlanIdentifier(DEFAULT_ACCOUNT_ID, region_name, usage_plan_name),
USAGE_PLAN_ID,
)

Expand All @@ -138,3 +148,15 @@ def test_custom_id_api_key(account_id, set_custom_id):

assert api_key["id"] == API_KEY_ID
assert usage_plan["id"] == USAGE_PLAN_ID


@mock_aws
def test_create_rest_api_with_custom_id_tag():
rest_api_name = "rest_api"
api_id = "testTagId"
client = boto3.client("apigateway")
rest_api = client.create_rest_api(
name=rest_api_name, tags={TAG_KEY_CUSTOM_ID: api_id}
)

assert rest_api["id"] == api_id
22 changes: 20 additions & 2 deletions tests/test_secretsmanager/test_secretsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from moto import mock_aws, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from moto.secretsmanager.utils import SecretsManagerSecretIdentifier
from moto.utilities.id_generator import TAG_KEY_CUSTOM_ID

from .. import DEFAULT_ACCOUNT_ID
from . import secretsmanager_aws_verified

DEFAULT_SECRET_NAME = "test-secret7"
Expand Down Expand Up @@ -1968,17 +1970,33 @@ def test_update_secret_version_stage_dont_specify_current_stage(secret_arn=None)
@pytest.mark.skipif(
not settings.TEST_DECORATOR_MODE, reason="Can't access the id manager in proxy mode"
)
def test_create_secret_custom_id(account_id, set_custom_id):
def test_create_secret_custom_id(set_custom_id):
secret_suffix = "randomSuffix"
secret_name = "secret-name"
region_name = "us-east-1"

client = boto3.client("secretsmanager", region_name=region_name)

set_custom_id(
SecretsManagerSecretIdentifier(account_id, region_name, secret_name),
SecretsManagerSecretIdentifier(DEFAULT_ACCOUNT_ID, region_name, secret_name),
secret_suffix,
)
secret = client.create_secret(Name=secret_name, SecretString="my secret")

assert secret["ARN"].split(":")[-1] == f"{secret_name}-{secret_suffix}"


@mock_aws
def test_create_secret_with_tag_custom_id(set_custom_id):
secret_suffix = "randomSuffix"
secret_name = "secret-name"

client = boto3.client("secretsmanager")

secret = client.create_secret(
Name=secret_name,
SecretString="my secret",
Tags=[{"Key": TAG_KEY_CUSTOM_ID, "Value": secret_suffix}],
)

assert secret["ARN"].split(":")[-1] == f"{secret_name}-{secret_suffix}"

0 comments on commit 95e7611

Please sign in to comment.