Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 535a1d1

Browse files
committed
work in review suggestions
1 parent 0cc8799 commit 535a1d1

6 files changed

Lines changed: 88 additions & 103 deletions

File tree

localstack-core/localstack/services/sns/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import re
22
from string import ascii_letters, digits
3+
from typing import get_args
4+
5+
from localstack.services.sns.v2.models import SnsApplicationPlatforms
36

47
SNS_PROTOCOLS = [
58
"http",
@@ -40,3 +43,5 @@
4043

4144
DUMMY_SUBSCRIPTION_PRINCIPAL = "arn:{partition}:iam::{account_id}:user/DummySNSPrincipal"
4245
E164_REGEX = re.compile(r"^\+?[1-9]\d{1,14}$")
46+
47+
VALID_APPLICATION_PLATFORMS = list(get_args(SnsApplicationPlatforms))

localstack-core/localstack/services/sns/v2/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33
from dataclasses import dataclass, field
44
from enum import StrEnum
5-
from typing import Literal, TypedDict, get_args
5+
from typing import Literal, TypedDict
66

77
from localstack.aws.api.sns import (
88
MessageAttributeMap,
@@ -39,10 +39,6 @@ class Topic(TypedDict, total=True):
3939
]
4040

4141

42-
def get_valid_platforms() -> list[str]:
43-
return list(get_args(SnsApplicationPlatforms))
44-
45-
4642
SMS_ATTRIBUTE_NAMES = [
4743
"DeliveryStatusIAMRole",
4844
"DeliveryStatusSuccessSamplingRate",

localstack-core/localstack/services/sns/v2/provider.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
)
5151
from localstack.services.sns import constants as sns_constants
5252
from localstack.services.sns.certificate import SNS_SERVER_CERT
53-
from localstack.services.sns.constants import DUMMY_SUBSCRIPTION_PRINCIPAL
53+
from localstack.services.sns.constants import (
54+
DUMMY_SUBSCRIPTION_PRINCIPAL,
55+
VALID_APPLICATION_PLATFORMS,
56+
)
5457
from localstack.services.sns.filter import FilterPolicyValidator
5558
from localstack.services.sns.publisher import PublishDispatcher, SnsPublishContext
5659
from localstack.services.sns.v2.models import (
@@ -62,7 +65,6 @@
6265
SnsStore,
6366
SnsSubscription,
6467
Topic,
65-
get_valid_platforms,
6668
sns_stores,
6769
)
6870
from localstack.services.sns.v2.utils import (
@@ -559,26 +561,20 @@ def create_platform_application(
559561
**kwargs,
560562
) -> CreatePlatformApplicationResponse:
561563
_validate_platform_application_name(name)
562-
if platform not in get_valid_platforms():
564+
if platform not in VALID_APPLICATION_PLATFORMS:
563565
raise InvalidParameterException(
564566
f"Invalid parameter: Platform Reason: {platform} is not supported"
565567
)
566568

567569
_validate_platform_application_attributes(attributes)
568570

569571
# attribute validation specific to create_platform_application
570-
if (
571-
"PlatformCredential" in attributes.keys()
572-
and "PlatformPrincipal" not in attributes.keys()
573-
):
572+
if "PlatformCredential" in attributes and "PlatformPrincipal" not in attributes:
574573
raise InvalidParameterException(
575574
"Invalid parameter: Attributes Reason: PlatformCredential attribute provided without PlatformPrincipal"
576575
)
577576

578-
elif (
579-
"PlatformPrincipal" in attributes.keys()
580-
and "PlatformCredential" not in attributes.keys()
581-
):
577+
elif "PlatformPrincipal" in attributes and "PlatformCredential" not in attributes:
582578
raise InvalidParameterException(
583579
"Invalid parameter: Attributes Reason: PlatformPrincipal attribute provided without PlatformCredential"
584580
)
@@ -613,15 +609,15 @@ def list_platform_applications(
613609
store = self.get_store(context.account_id, context.region)
614610
platform_applications = store.platform_applications.values()
615611
paginated_applications = PaginatedList(platform_applications)
616-
page, next_token = paginated_applications.get_page(
612+
page, token = paginated_applications.get_page(
617613
token_generator=lambda x: get_next_page_token_from_arn(x["PlatformApplicationArn"]),
618614
page_size=100,
619615
next_token=next_token,
620616
)
621617

622618
response = ListPlatformApplicationsResponse(PlatformApplications=page)
623-
if next_token:
624-
response["NextToken"] = next_token
619+
if token:
620+
response["NextToken"] = token
625621
return response
626622

627623
def get_platform_application_attributes(

tests/aws/services/sns/test_sns.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,36 +3650,34 @@ def _get_messages(amount: int) -> list[dict]:
36503650

36513651

36523652
class TestSNSPlatformApplicationCrud:
3653-
@markers.aws.manual_setup_required
3654-
def test_create_platform_application(self, aws_client, snapshot, cleanups):
3655-
name = f"platform-application-{short_uid()}"
3656-
platform = "ADM"
3653+
@pytest.fixture(scope="class")
3654+
def platform_credentials(self) -> tuple[str, str]:
36573655
# these values need to be extracted from a real amazon developer account if tested against AWS
36583656
# https://developer.amazon.com/settings/console/securityprofile/overview.html
36593657
client_id = "dummy"
36603658
client_secret = "dummy"
3659+
return client_id, client_secret
3660+
3661+
@markers.aws.manual_setup_required
3662+
def test_create_platform_application(
3663+
self, aws_client, snapshot, sns_create_platform_application, platform_credentials
3664+
):
3665+
platform = "ADM"
3666+
# if tested against AWS, the fixture needs to contain real credentials
3667+
client_id, client_secret = platform_credentials
36613668
attributes = {"PlatformPrincipal": client_id, "PlatformCredential": client_secret}
3662-
response = aws_client.sns.create_platform_application(
3663-
Name=name, Platform=platform, Attributes=attributes
3664-
)
3669+
response = sns_create_platform_application(Platform=platform, Attributes=attributes)
36653670
snapshot.match("create-platform-application", response)
3666-
cleanups.append(
3667-
lambda: aws_client.delete_platform_application(
3668-
PlatformApplicationArn=response["PlatformApplicationArn"]
3669-
)
3670-
)
36713671

36723672
@pytest.mark.skipif(condition=is_sns_v1_provider(), reason="Parity gap with old provider")
36733673
@markers.aws.manual_setup_required
36743674
def test_list_platform_applications(
3675-
self, aws_client, snapshot, sns_create_platform_application
3675+
self, aws_client, snapshot, sns_create_platform_application, platform_credentials
36763676
):
36773677
name = f"platform-application-{short_uid()}"
36783678
platform = "ADM"
3679-
# these values need to be extracted from a real amazon developer account if tested against AWS
3680-
# https://developer.amazon.com/settings/console/securityprofile/overview.html
3681-
client_id = "dummy"
3682-
client_secret = "dummy"
3679+
# if tested against AWS, the fixture needs to contain real credentials
3680+
client_id, client_secret = platform_credentials
36833681
attributes = {"PlatformPrincipal": client_id, "PlatformCredential": client_secret}
36843682
sns_create_platform_application(Name=name, Platform=platform, Attributes=attributes)
36853683

@@ -3737,14 +3735,12 @@ def test_create_platform_application_invalid_platform(self, aws_client, snapshot
37373735
@pytest.mark.skipif(condition=is_sns_v1_provider(), reason="Parity gap with old provider")
37383736
@markers.aws.manual_setup_required
37393737
def test_get_platform_application_attributes(
3740-
self, aws_client, snapshot, sns_create_platform_application
3738+
self, aws_client, snapshot, sns_create_platform_application, platform_credentials
37413739
):
37423740
name = f"platform-application-{short_uid()}"
37433741
platform = "ADM"
3744-
# these values need to be extracted from a real amazon developer account if tested against AWS
3745-
# https://developer.amazon.com/settings/console/securityprofile/overview.html
3746-
client_id = "dummy"
3747-
client_secret = "dummy"
3742+
# if tested against AWS, the fixture needs to contain real credentials
3743+
client_id, client_secret = platform_credentials
37483744
attributes = {"PlatformPrincipal": client_id, "PlatformCredential": client_secret}
37493745
platform_application_arn = sns_create_platform_application(
37503746
Name=name, Platform=platform, Attributes=attributes
@@ -3774,14 +3770,12 @@ def test_get_platform_application_attributes_non_existing_app(
37743770
@pytest.mark.skipif(condition=is_sns_v1_provider(), reason="Parity gap with old provider")
37753771
@markers.aws.manual_setup_required
37763772
def test_set_platform_application_attributes(
3777-
self, aws_client, snapshot, sns_create_platform_application
3773+
self, aws_client, snapshot, sns_create_platform_application, platform_credentials
37783774
):
37793775
name = f"platform-application-{short_uid()}"
37803776
platform = "ADM"
3781-
# these values need to be extracted from a real amazon developer account if tested against AWS
3782-
# https://developer.amazon.com/settings/console/securityprofile/overview.html
3783-
client_id = "dummy"
3784-
client_secret = "dummy"
3777+
# if tested against AWS, the fixture needs to contain real credentials
3778+
client_id, client_secret = platform_credentials
37853779
attributes = {"PlatformPrincipal": client_id, "PlatformCredential": client_secret}
37863780
platform_application_arn = sns_create_platform_application(
37873781
Name=name, Platform=platform, Attributes=attributes

tests/aws/services/sns/test_sns.snapshot.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6049,7 +6049,7 @@
60496049
}
60506050
},
60516051
"tests/aws/services/sns/test_sns.py::TestSNSPlatformApplicationCrud::test_create_platform_application": {
6052-
"recorded-date": "28-10-2025, 09:29:32",
6052+
"recorded-date": "29-10-2025, 09:14:55",
60536053
"recorded-content": {
60546054
"create-platform-application": {
60556055
"PlatformApplicationArn": "arn:<partition>:sns:<region>:111111111111:app/ADM/<resource:1>",
@@ -6061,7 +6061,7 @@
60616061
}
60626062
},
60636063
"tests/aws/services/sns/test_sns.py::TestSNSPlatformApplicationCrud::test_list_platform_applications": {
6064-
"recorded-date": "28-10-2025, 09:29:33",
6064+
"recorded-date": "29-10-2025, 09:20:15",
60656065
"recorded-content": {
60666066
"list-platform-applications": {
60676067
"PlatformApplications": [
@@ -6070,12 +6070,6 @@
60706070
"Enabled": "true"
60716071
},
60726072
"PlatformApplicationArn": "arn:<partition>:sns:<region>:111111111111:app/ADM/<resource:1>"
6073-
},
6074-
{
6075-
"Attributes": {
6076-
"Enabled": "true"
6077-
},
6078-
"PlatformApplicationArn": "arn:<partition>:sns:<region>:111111111111:app/ADM/<resource:2>"
60796073
}
60806074
],
60816075
"ResponseMetadata": {

0 commit comments

Comments
 (0)