8000 regenerate snapshots with ordering · localstack/localstack@25913f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25913f1

Browse files
committed
regenerate snapshots with ordering
1 parent 8cd75d0 commit 25913f1

File tree

6 files changed

+1469
-535
lines changed

6 files changed

+1469
-535
lines changed

localstack/services/sns/provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ def create_sns_message_body(
11741174
"Timestamp": timestamp_millis(),
11751175
"SignatureVersion": "1",
11761176
# TODO Add a more sophisticated solution with an actual signature
1177+
# check KMS for providing real cert and how to serve them
11771178
# Hardcoded
11781179
"Signature": "EXAMPLEpH+..",
11791180
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem",

localstack/testing/snapshots/transformer_utility.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ def sqs_api():
173173
"""
174174
return [
175175
TransformerUtility.key_value("ReceiptHandle"),
176-
# account ID
177-
TransformerUtility.key_value(
178-
"SenderId", value_replacement="111111111111", reference_replacement=False
179-
),
176+
TransformerUtility.key_value("SenderId"),
180177
TransformerUtility.jsonpath("$..MessageAttributes.RequestID.StringValue", "request-id"),
181178
KeyValueBasedTransformer(_resource_name_transformer, "resource"),
182179
]
@@ -187,12 +184,17 @@ def sns_api():
187184
:return: array with Transformers, for sns api.
188185
"""
189186
return [
187+
TransformerUtility.key_value("ReceiptHandle"),
190188
TransformerUtility.key_value("SequenceNumber"), # this might need to be in SQS
191189
TransformerUtility.key_value(
192190
"Signature", value_replacement="<signature>", reference_replacement=False
193191
),
192+
# the body of SNS messages contains a timestamp, need to ignore the hash
194193
TransformerUtility.key_value("MD5OfBody", "<md5-hash>", reference_replacement=False),
195-
KeyValueBasedTransformer(_sns_unsubscribe_url_token_transformer, replacement="token"),
194+
# this can interfere in ARN with the accountID
195+
TransformerUtility.key_value(
196+
"SenderId", value_replacement="<sender-id>", reference_replacement=False
197+
),
196198
KeyValueBasedTransformer(
197199
_sns_pem_file_token_transformer,
198200
replacement="signing-cert-file",
@@ -205,6 +207,11 @@ def sns_api():
205207
r"(?<=(?i)UnsubscribeURL[\"|']:\s[\"|'])(https?.*?)(?=/\?Action=Unsubscribe)",
206208
replacement="<unsubscribe-domain>",
207209
),
210+
KeyValueBasedTransformer(_resource_name_transformer, "resource"),
211+
# add a special transformer with 'resource' replacement for SubscriptionARN in UnsubscribeURL
212+
KeyValueBasedTransformer(
213+
_sns_unsubscribe_url_subscription_arn_transformer, replacement="resource"
214+
),
208215
]
209216

210217
@staticmethod
@@ -245,7 +252,7 @@ def _sns_pem_file_token_transformer(key: str, val: str) -> str:
245252
return match.groups()[0]
246253

247254

248-
def _sns_unsubscribe_url_token_transformer(key: str, val: str) -> str:
255+
def _sns_unsubscribe_url_subscription_arn_transformer(key: str, val: str) -> str:
249256
if isinstance(val, str) and key.lower() == "UnsubscribeURL".lower():
250257
pattern = re.compile(r".*(?<=\?Action=Unsubscribe&SubscriptionArn=).*:(.*)")
251258
match = re.match(pattern, val)

tests/integration/s3/test_s3_notifications_sns.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,9 @@ def test_object_created_put(
110110
snapshot,
111111
):
112112
snapshot.add_transformer(snapshot.transform.sqs_api())
113+
snapshot.add_transformer(snapshot.transform.sns_api())
113114
snapshot.add_transformer(snapshot.transform.s3_api())
114-
snapshot.add_transformer(
115-
snapshot.transform.jsonpath(
116-
"$..Signature",
117-
"signature",
118-
reference_replacement=False,
119-
),
120-
)
115+
121116
bucket_name = s3_create_bucket()
122117
topic_arn = sns_create_topic()["TopicArn"]
123118
queue_url = sqs_create_queue()

tests/integration/s3/test_s3_notifications_sns.snapshot.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tests/integration/s3/test_s3_notifications_sns.py::TestS3NotificationsToSns::test_object_created_put": {
3-
"recorded-date": "08-08-2022, 17:51:20",
3+
"recorded-date": "09-08-2022, 11:38:05",
44
"recorded-content": {
55
"receive_messages": {
66
"messages": [
@@ -44,14 +44,14 @@
4444
]
4545
},
4646
"MessageId": "<uuid:1>",
47-
"Signature": "signature",
47+
"Signature": "<signature>",
4848
"SignatureVersion": "1",
49-
"SigningCertURL": "https://sns.<region>.amazonaws.com/SimpleNotificationService-<signing-cert-file:1>.pem",
49+
"SigningCertURL": "https://sns.<region>.amazonaws.com/SimpleNotificationService-<signing-cert-file:1>",
5050
"Subject": "Amazon S3 Notification",
5151
"Timestamp": "date",
5252
"TopicArn": "arn:aws:sns:<region>:111111111111:<resource:2>",
5353
"Type": "Notification",
54-
"UnsubscribeURL": "<unsubscribe-domain>/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:<region>:111111111111:<resource:2>:<token:1>"
54+
"UnsubscribeURL": "<unsubscribe-domain>/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:<region>:111111111111:<resource:2>:<resource:3>"
5555
},
5656
{
5757
"Message": {
@@ -93,14 +93,14 @@
9393
]
9494
},
9595
"MessageId": "<uuid:2>",
96-
"Signature": "signature",
96+
"Signature": "<signature>",
9797
"SignatureVersion": "1",
98-
"SigningCertURL": "https://sns.<region>.amazonaws.com/SimpleNotificationService-<signing-cert-file:1>.pem",
98+
"SigningCertURL": "https://sns.<region>.amazonaws.com/SimpleNotificationService-<signing-cert-file:1>",
9999
"Subject": "Amazon S3 Notification",
100100
"Timestamp": "date",
101101
"TopicArn": "arn:aws:sns:<region>:111111111111:<resource:2>",
102102
"Type": "Notification",
103-
"UnsubscribeURL": "<unsubscribe-domain>/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:<region>:111111111111:<resource:2>:<token:1>"
103+
"UnsubscribeURL": "<unsubscribe-domain>/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:<region>:111111111111:<resource:2>:<resource:3>"
104104
}
105105
]
106106
}

0 commit comments

Comments
 (0)
0