Coverage for /pythoncovmergedfiles/medio/medio/src/python-multipart/fuzz/fuzz_form.py: 42%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12import io
13import sys
14from unittest.mock import Mock
16import atheris
17from helpers import EnhancedDataProvider
19with atheris.instrument_imports():
20 from multipart.exceptions import FormParserError
21 from multipart.multipart import parse_form
23on_field = Mock()
24on_file = Mock()
27def parse_octet_stream(fdp: EnhancedDataProvider) -> None:
28 header = {"Content-Type": "application/octet-stream"}
29 parse_form(header, io.BytesIO(fdp.ConsumeRandomBytes()), on_field, on_file)
32def parse_url_encoded(fdp: EnhancedDataProvider) -> None:
33 header = {"Content-Type": "application/x-url-encoded"}
34 parse_form(header, io.BytesIO(fdp.ConsumeRandomBytes()), on_field, on_file)
37def parse_form_urlencoded(fdp: EnhancedDataProvider) -> None:
38 header = {"Content-Type": "application/x-www-form-urlencoded"}
39 parse_form(header, io.BytesIO(fdp.ConsumeRandomBytes()), on_field, on_file)
42def parse_multipart_form_data(fdp: EnhancedDataProvider) -> None:
43 header = {"Content-Type": "multipart/form-data; boundary=--boundary"}
44 parse_form(header, io.BytesIO(fdp.ConsumeRandomBytes()), on_field, on_file)
47def TestOneInput(data: bytes) -> None:
48 fdp = EnhancedDataProvider(data)
49 targets = [parse_octet_stream, parse_url_encoded, parse_form_urlencoded, parse_multipart_form_data]
50 target = fdp.PickValueInList(targets)
52 try:
53 target(fdp)
54 except FormParserError:
55 return
58def main():
59 atheris.Setup(sys.argv, TestOneInput)
60 atheris.Fuzz()
63if __name__ == "__main__":
64 main()