diff options
author | davkor <david@adalogics.com> | 2021-01-21 14:15:59 +0000 |
---|---|---|
committer | davkor <david@adalogics.com> | 2021-01-21 14:15:59 +0000 |
commit | c2698395bf4ead37a6ffd16a2478434a0f138768 (patch) | |
tree | 54ec6d262fe8c7a8dd81482e7131d7279609f78d | |
parent | 9814afc7659d68150f889a4820991210ba26555f (diff) | |
download | jsonschema-c2698395bf4ead37a6ffd16a2478434a0f138768.tar.gz |
Added fuzzer to be run with OSS-Fuzz
-rw-r--r-- | jsonschema/tests/fuzz_validate.py | 35 |
1 files changed, 35 insertions, 0 deletions
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() |