-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
use snapshots for SNS tests #6601
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
Changes from all commits
3318c00
41d4935
9fe2785
5f6f684
0883522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,17 +176,42 @@ def sqs_api(): | |
TransformerUtility.key_value("SenderId"), | ||
TransformerUtility.jsonpath("$..MessageAttributes.RequestID.StringValue", "request-id"), | ||
KeyValueBasedTransformer(_resource_name_transformer, "resource"), | ||
KeyValueBasedTransformer(_signing_cert_url_token_transformer, replacement="token"), | ||
] | ||
|
||
@staticmethod | ||
def sns_api(): | ||
""" | ||
:return: array with Transformers, for sns api. | ||
""" | ||
return [ | ||
TransformerUtility.key_value("ReceiptHandle"), | ||
TransformerUtility.key_value("SequenceNumber"), # this might need to be in SQS | ||
TransformerUtility.key_value( | ||
"Signature", value_replacement="<signature>", reference_replacement=False | ||
), | ||
# the body of SNS messages contains a timestamp, need to ignore the hash | ||
TransformerUtility.key_value("MD5OfBody", "<md5-hash>", reference_replacement=False), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we not maybe leave this in per default? or are you having issues with bodies containing data that is dynamically generated by the tests? (like passing ARNs through a message body). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The MD5 hash almost never matches: the body of the SNS message always contains a timestamp, and a signature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright :) i think in that case, having unittests should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it could work as well. The issue also that I didn't think about is that in some tests, we have both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see :) yes, sounds good. but I think it would also be fine to cover the md5-checksum in unittests as you suggested before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The md5 is part of SQS, and is covered inside the integration tests there, there shouldn't be any regression on that side. |
||
# this can interfere in ARN with the accountID | ||
TransformerUtility.key_value( | ||
"SenderId", value_replacement="<sender-id>", reference_replacement=False | ||
), | ||
KeyValueBasedTransformer( | ||
_sns_pem_file_token_transformer, replacement="signing-cert-file" | ||
_sns_pem_file_token_transformer, | ||
replacement="signing-cert-file", | ||
), | ||
# replaces the domain in "UnsubscribeURL" | ||
TransformerUtility.regex( | ||
re.compile( | ||
r"(?<=UnsubscribeURL[\"|']:\s[\"|'])(https?.*?)(?=/\?Action=Unsubscribe)" | ||
), | ||
# replaces the domain in "UnsubscribeURL" URL (KeyValue won't work as it replaces reference, and if | ||
# replace_reference is False, then it replaces the whole key | ||
# this will be able to use a KeyValue based once we provide a certificate for message signing in SNS | ||
# a match must be made case-insensitive because the key casing is different from lambda notifications | ||
RegexTransformer( | ||
r"(?<=(?i)UnsubscribeURL[\"|']:\s[\"|'])(https?.*?)(?=/\?Action=Unsubscribe)", | ||
replacement="<unsubscribe-domain>", | ||
), | ||
KeyValueBasedTransformer(_resource_name_transformer, "resource"), | ||
# add a special transformer with 'resource' replacement for SubscriptionARN in UnsubscribeURL | ||
KeyValueBasedTransformer( | ||
_sns_unsubscribe_url_subscription_arn_transformer, replacement="resource" | ||
), | ||
] | ||
|
||
@staticmethod | ||
|
@@ -220,15 +245,15 @@ def secretsmanager_secret_id_arn(create_secret_res: CreateSecretResponse, index: | |
|
||
|
||
def _sns_pem_file_token_transformer(key: str, val: str) -> str: | ||
if isinstance(val, str) and key == "SigningCertURL": | ||
pattern = re.compile(r".*SimpleNotificationService-(.*)?\.pem") | ||
if isinstance(val, str) and key.lower() == "SigningCertURL".lower(): | ||
pattern = re.compile(r".*SimpleNotificationService-(.*\.pem)") | ||
match = re.match(pattern, val) | ||
if match: | ||
return match.groups()[0] | ||
|
||
|
||
def _signing_cert_url_token_transformer(key: str, val: str) -> str: | ||
if isinstance(val, str) and key == "UnsubscribeURL": | ||
def _sns_unsubscribe_url_subscription_arn_transformer(key: str, val: str) -> str: | ||
if isinstance(val, str) and key.lower() == "UnsubscribeURL".lower(): | ||
pattern = re.compile(r".*(?<=\?Action=Unsubscribe&SubscriptionArn=).*:(.*)") | ||
match = re.match(pattern, val) | ||
if match: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we maybe just use the default
value_replacement
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the reference_replacement set to false, the default value would be
signature
. I think it's fine to use<signature>
here as it indicates at the first sight that the value was replaced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that was my issue, the fact that the
<[...]>
were missing was troubling me, so I added it manually!