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
|
import sys
from hypothesis import given
from hypothesis import strategies as st
import atheris
import jsonschema
PRIM = st.one_of(
st.booleans(),
st.integers(),
st.floats(allow_nan=False, allow_infinity=False),
st.text(),
)
DICT = st.recursive(
base=st.booleans() | 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()
|