-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNS: Improve PlatformApplication error handling (#6953)
- Loading branch information
Showing
5 changed files
with
237 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
# This file is intentionally left blank. | ||
import boto3 | ||
import botocore | ||
import os | ||
from functools import wraps | ||
from moto import mock_sns, mock_sts | ||
from unittest import SkipTest | ||
|
||
|
||
def sns_aws_verified(func): | ||
""" | ||
Function that is verified to work against AWS. | ||
Can be run against AWS at any time by setting: | ||
MOTO_TEST_ALLOW_AWS_REQUEST=true | ||
If this environment variable is not set, the function runs in a `mock_ses` context. | ||
""" | ||
|
||
@wraps(func) | ||
def pagination_wrapper(): | ||
allow_aws_request = ( | ||
os.environ.get("MOTO_TEST_ALLOW_AWS_REQUEST", "false").lower() == "true" | ||
) | ||
|
||
if allow_aws_request: | ||
ssm = boto3.client("ssm", "us-east-1") | ||
try: | ||
param = ssm.get_parameter( | ||
Name="/moto/tests/ses/firebase_api_key", WithDecryption=True | ||
) | ||
api_key = param["Parameter"]["Value"] | ||
resp = func(api_key) | ||
except botocore.exceptions.ClientError: | ||
# SNS tests try to create a PlatformApplication that connects to GCM | ||
# (Google Cloud Messaging, also known as Firebase Messaging) | ||
# That requires an account and an API key | ||
# If the API key has not been configured in SSM, we'll just skip the test | ||
# | ||
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns/client/create_platform_application.html | ||
# AWS calls it 'API key', but Firebase calls it Server Key | ||
# | ||
# https://stackoverflow.com/a/75896532/13245310 | ||
raise SkipTest("Can't execute SNS tests without Firebase API key") | ||
else: | ||
with mock_sns(), mock_sts(): | ||
resp = func("mock_api_key") | ||
return resp | ||
|
||
return pagination_wrapper |
Oops, something went wrong.