codekingpro/portable-devtools
114k
1"""2Fuzzing setup for OSS-Fuzz.3 4See https://github.com/google/oss-fuzz/tree/master/projects/jsonschema for the5other half of the setup here.6"""7import sys8 9from hypothesis import given, strategies10 11import jsonschema12 13PRIM = strategies.one_of(14 strategies.booleans(),15 strategies.integers(),16 strategies.floats(allow_nan=False, allow_infinity=False),17 strategies.text(),18)19DICT = strategies.recursive(20 base=strategies.one_of(21 strategies.booleans(),22 strategies.dictionaries(strategies.text(), PRIM),23 ),24 extend=lambda inner: strategies.dictionaries(strategies.text(), inner),25)26 27 28@given(obj1=DICT, obj2=DICT)29def test_schemas(obj1, obj2):30 try:31 jsonschema.validate(instance=obj1, schema=obj2)32 except jsonschema.exceptions.ValidationError:33 pass34 except jsonschema.exceptions.SchemaError:35 pass36 37 38def main():39 atheris.instrument_all()40 atheris.Setup(41 sys.argv,42 test_schemas.hypothesis.fuzz_one_input,43 enable_python_coverage=True,44 )45 atheris.Fuzz()46 47 48if __name__ == "__main__":49 import atheris50 main()51 