From e72c9a507c3770c0896240d59e5785b41ab0fa0f Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sat, 27 Apr 2024 21:12:33 +0000 Subject: [PATCH] SNS: create_platform_endpoint() is idempotent, if without attributes supplied (#7635) --- moto/sns/models.py | 2 +- tests/test_sns/test_application_boto3.py | 38 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/moto/sns/models.py b/moto/sns/models.py index 98c380fb66b..a3459de589b 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -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"] ) diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index d13872d2724..8411e4dec0b 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -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"]