forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_event_sources.py
More file actions
77 lines (59 loc) · 1.89 KB
/
fuzz_event_sources.py
File metadata and controls
77 lines (59 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Fuzz target for Event Source Data Classes - SQS, SNS, API Gateway, Kinesis parsing."""
from __future__ import annotations
import json
import sys
import atheris
with atheris.instrument_imports():
from aws_lambda_powertools.utilities.data_classes import (
APIGatewayProxyEvent,
KinesisStreamEvent,
SNSEvent,
SQSEvent,
)
def fuzz_sqs_event(data: bytes) -> None:
"""Fuzz SQS event parsing."""
try:
event_dict = json.loads(data.decode("utf-8", errors="ignore"))
SQSEvent(event_dict)
except (json.JSONDecodeError, KeyError, TypeError, ValueError):
pass
except Exception:
pass
def fuzz_sns_event(data: bytes) -> None:
"""Fuzz SNS event parsing."""
try:
event_dict = json.loads(data.decode("utf-8", errors="ignore"))
SNSEvent(event_dict)
except (json.JSONDecodeError, KeyError, TypeError, ValueError):
pass
except Exception:
pass
def fuzz_api_gateway_event(data: bytes) -> None:
"""Fuzz API Gateway event parsing."""
try:
event_dict = json.loads(data.decode("utf-8", errors="ignore"))
APIGatewayProxyEvent(event_dict)
except (json.JSONDecodeError, KeyError, TypeError, ValueError):
pass
except Exception:
pass
def fuzz_kinesis_event(data: bytes) -> None:
"""Fuzz Kinesis event parsing."""
try:
event_dict = json.loads(data.decode("utf-8", errors="ignore"))
KinesisStreamEvent(event_dict)
except (json.JSONDecodeError, KeyError, TypeError, ValueError):
pass
except Exception:
pass
def fuzz_all_events(data: bytes) -> None:
"""Fuzz all event sources."""
fuzz_sqs_event(data)
fuzz_sns_event(data)
fuzz_api_gateway_event(data)
fuzz_kinesis_event(data)
def main() -> None:
atheris.Setup(sys.argv, fuzz_all_events)
atheris.Fuzz()
if __name__ == "__main__":
main()