sns#create_platform_endpoint: If token and attributes are the same, return endpoint (#4055)

* If token and attributes are the same, return endpoint

* fix black

* moto sns platform_endpoint.attributes includes only token,enabled

* add tests when calling sns#create_platform_endpoint with same attrs for #4056
This commit is contained in:
kohbis 2021-07-04 15:43:22 +09:00 committed by GitHub
parent b44ab23c63
commit c20a36b8cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

@ -584,10 +584,13 @@ class SNSBackend(BaseBackend):
def create_platform_endpoint( def create_platform_endpoint(
self, region, application, custom_user_data, token, attributes self, region, application, custom_user_data, token, attributes
): ):
if any( for endpoint in self.platform_endpoints.values():
token == endpoint.token for endpoint in self.platform_endpoints.values() if token == endpoint.token:
): if attributes["Enabled"].lower() == endpoint.attributes["Enabled"]:
raise DuplicateSnsEndpointError("Duplicate endpoint token: %s" % token) return endpoint
raise DuplicateSnsEndpointError(
"Duplicate endpoint token with different attributes: %s" % token
)
platform_endpoint = PlatformEndpoint( platform_endpoint = PlatformEndpoint(
region, application, custom_user_data, token, attributes region, application, custom_user_data, token, attributes
) )

View File

@ -156,10 +156,37 @@ def test_create_duplicate_platform_endpoint():
PlatformApplicationArn=application_arn, PlatformApplicationArn=application_arn,
Token="some_unique_id", Token="some_unique_id",
CustomUserData="some user data", CustomUserData="some user data",
Attributes={"Enabled": "false"}, Attributes={"Enabled": "true"},
).should.throw(ClientError) ).should.throw(ClientError)
@mock_sns
def test_create_duplicate_platform_endpoint_with_same_attributes():
conn = boto3.client("sns", region_name="us-east-1")
platform_application = conn.create_platform_application(
Name="my-application", Platform="APNS", Attributes={}
)
application_arn = platform_application["PlatformApplicationArn"]
created_endpoint = conn.create_platform_endpoint(
PlatformApplicationArn=application_arn,
Token="some_unique_id",
CustomUserData="some user data",
Attributes={"Enabled": "false"},
)
created_endpoint_arn = created_endpoint["EndpointArn"]
endpoint = conn.create_platform_endpoint(
PlatformApplicationArn=application_arn,
Token="some_unique_id",
CustomUserData="some user data",
Attributes={"Enabled": "false"},
)
endpoint_arn = endpoint["EndpointArn"]
endpoint_arn.should.equal(created_endpoint_arn)
@mock_sns @mock_sns
def test_get_list_endpoints_by_platform_application(): def test_get_list_endpoints_by_platform_application():
conn = boto3.client("sns", region_name="us-east-1") conn = boto3.client("sns", region_name="us-east-1")