|
| 1 | +import json |
1 | 2 | from typing import Any, List
|
2 | 3 |
|
3 | 4 | import pytest
|
@@ -103,3 +104,29 @@ def handle_sns_sqs_json_body(event: List[MySnsBusiness], _: LambdaContext):
|
103 | 104 | def test_handle_sns_sqs_trigger_event_json_body(): # noqa: F811
|
104 | 105 | event_dict = load_event("snsSqsEvent.json")
|
105 | 106 | handle_sns_sqs_json_body(event_dict, LambdaContext())
|
| 107 | + |
| 108 | + |
| 109 | +def test_handle_sns_sqs_trigger_event_json_body_missing_signing_cert_url(): |
| 110 | + # GIVEN an event is tampered with a missing SigningCertURL |
| 111 | + event_dict = load_event("snsSqsEvent.json") |
| 112 | + payload = json.loads(event_dict["Records"][0]["body"]) |
| 113 | + payload.pop("SigningCertURL") |
| 114 | + event_dict["Records"][0]["body"] = json.dumps(payload) |
| 115 | + |
| 116 | + # WHEN parsing the payload |
| 117 | + # THEN raise a ValidationError error |
| 118 | + with pytest.raises(ValidationError): |
| 119 | + handle_sns_sqs_json_body(event_dict, LambdaContext()) |
| 120 | + |
| 121 | + |
| 122 | +def test_handle_sns_sqs_trigger_event_json_body_missing_unsubscribe_url(): |
| 123 | + # GIVEN an event is tampered with a missing UnsubscribeURL |
| 124 | + event_dict = load_event("snsSqsEvent.json") |
| 125 | + payload = json.loads(event_dict["Records"][0]["body"]) |
| 126 | + payload.pop("UnsubscribeURL") |
| 127 | + event_dict["Records"][0]["body"] = json.dumps(payload) |
| 128 | + |
| 129 | + # WHEN parsing the payload |
| 130 | + # THEN raise a ValidationError error |
| 131 | + with pytest.raises(ValidationError): |
| 132 | + handle_sns_sqs_json_body(event_dict, LambdaContext()) |
0 commit comments