Skip to content

Commit

Permalink
SNS: create_platform_endpoint() is idempotent, if without attributes …
Browse files Browse the repository at this point in the history
…supplied (#7635)
  • Loading branch information
bblommers committed Apr 27, 2024
1 parent e51192b commit e72c9a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion moto/sns/models.py
Expand Up @@ -679,7 +679,7 @@ def create_platform_endpoint(
if token == endpoint.token:
same_user_data = custom_user_data == endpoint.custom_user_data
same_attrs = (
attributes.get("Enabled", "").lower()
attributes.get("Enabled", "true").lower()
== endpoint.attributes["Enabled"]
)

Expand Down
38 changes: 37 additions & 1 deletion tests/test_sns/test_application_boto3.py
Expand Up @@ -139,7 +139,43 @@ def test_create_platform_endpoint():

@pytest.mark.aws_verified
@sns_aws_verified
def test_create_duplicate_platform_endpoint(api_key=None):
def test_create_duplicate_default_platform_endpoint(api_key=None):
conn = boto3.client("sns", region_name="us-east-1")
platform_name = str(uuid4())[0:6]
app_arn = None
try:
platform_application = conn.create_platform_application(
Name=platform_name,
Platform="GCM",
Attributes={"PlatformCredential": api_key},
)
app_arn = platform_application["PlatformApplicationArn"]

# Create duplicate endpoints
arn1 = conn.create_platform_endpoint(
PlatformApplicationArn=app_arn, Token="token"
)["EndpointArn"]
arn2 = conn.create_platform_endpoint(
PlatformApplicationArn=app_arn, Token="token"
)["EndpointArn"]

# Create another duplicate endpoint, just specify the default value
arn3 = conn.create_platform_endpoint(
PlatformApplicationArn=app_arn,
Token="token",
Attributes={"Enabled": "true"},
)["EndpointArn"]

assert arn1 == arn2
assert arn2 == arn3
finally:
if app_arn is not None:
conn.delete_platform_application(PlatformApplicationArn=app_arn)


@pytest.mark.aws_verified
@sns_aws_verified
def test_create_duplicate_platform_endpoint_with_attrs(api_key=None):
identity = boto3.client("sts", region_name="us-east-1").get_caller_identity()
account_id = identity["Account"]

Expand Down

0 comments on commit e72c9a5

Please sign in to comment.