Coverage for /pythoncovmergedfiles/medio/medio/src/websockets/fuzzing/fuzz_http11_response_parser.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 sys
14import atheris
17with atheris.instrument_imports():
18 from websockets.exceptions import SecurityError
19 from websockets.http11 import Response
20 from websockets.streams import StreamReader
23def test_one_input(data):
24 reader = StreamReader()
25 reader.feed_data(data)
26 reader.feed_eof()
28 parser = Response.parse(
29 reader.read_line,
30 reader.read_exact,
31 reader.read_to_eof,
32 )
33 try:
34 next(parser)
35 except StopIteration as exc:
36 assert isinstance(exc.value, Response)
37 return # input accepted
38 except (
39 EOFError, # connection is closed without a full HTTP response
40 SecurityError, # response exceeds a security limit
41 LookupError, # response isn't well formatted
42 ValueError, # response isn't well formatted
43 ):
44 return # input rejected with a documented exception
46 raise RuntimeError("parsing didn't complete")
49def main():
50 atheris.Setup(sys.argv, test_one_input)
51 atheris.Fuzz()
54if __name__ == "__main__":
55 main()