From c2698395bf4ead37a6ffd16a2478434a0f138768 Mon Sep 17 00:00:00 2001 From: davkor Date: Thu, 21 Jan 2021 14:15:59 +0000 Subject: Added fuzzer to be run with OSS-Fuzz --- jsonschema/tests/fuzz_validate.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 jsonschema/tests/fuzz_validate.py diff --git a/jsonschema/tests/fuzz_validate.py b/jsonschema/tests/fuzz_validate.py new file mode 100644 index 0000000..eb1a3d3 --- /dev/null +++ b/jsonschema/tests/fuzz_validate.py @@ -0,0 +1,35 @@ +import os +import sys +import atheris + +import jsonschema +from hypothesis import given, strategies as st + +PRIM = st.one_of( + st.booleans(), + st.integers(min_value=-(2 ** 63), max_value=2 ** 63 - 1), + st.floats(allow_nan=False, allow_infinity=False), + st.text(), +) +DICT = st.recursive( + base=st.dictionaries(st.text(), PRIM), + extend=lambda inner: st.dictionaries(st.text(), inner), +) + +@given(obj1=DICT, obj2=DICT) +def test_schemas(obj1, obj2): + try: + jsonschema.validate(instance=obj1, schema=obj2) + except jsonschema.exceptions.ValidationError: + None + except jsonschema.exceptions.SchemaError: + None + +def main(): + atheris.Setup(sys.argv, + test_schemas.hypothesis.fuzz_one_input, + enable_python_coverage=True) + atheris.Fuzz() + +if __name__ == "__main__": + main() -- cgit v1.2.1