Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNS: create_platform_endpoint() is idempotent, if without attributes … #7635

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion moto/sns/models.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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