forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_validation.py
More file actions
42 lines (31 loc) · 1022 Bytes
/
fuzz_validation.py
File metadata and controls
42 lines (31 loc) · 1022 Bytes
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
"""Fuzz target for Validation - JSON Schema validation."""
from __future__ import annotations
import json
import sys
import atheris
with atheris.instrument_imports():
from aws_lambda_powertools.utilities.validation import validate
from aws_lambda_powertools.utilities.validation.exceptions import SchemaValidationError
SIMPLE_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
},
"required": ["name"],
}
def fuzz_validation(data: bytes) -> None:
"""Fuzz JSON Schema validation."""
try:
event = json.loads(data.decode("utf-8", errors="ignore"))
validate(event=event, schema=SIMPLE_SCHEMA)
except (json.JSONDecodeError, SchemaValidationError, TypeError, ValueError):
pass
except Exception:
pass
def main() -> None:
atheris.Setup(sys.argv, fuzz_validation)
atheris.Fuzz()
if __name__ == "__main__":
main()