Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_util.py: 58%

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

52 statements  

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 

12#!/usr/bin/python3 

13# Copyright 2022 Google LLC 

14# 

15# Licensed under the Apache License, Version 2.0 (the "License"); 

16# you may not use this file except in compliance with the License. 

17# You may obtain a copy of the License at 

18# 

19# http://www.apache.org/licenses/LICENSE-2.0 

20# 

21# Unless required by applicable law or agreed to in writing, software 

22# distributed under the License is distributed on an "AS IS" BASIS, 

23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

24# See the License for the specific language governing permissions and 

25# limitations under the License. 

26 

27import atheris 

28import sys 

29with atheris.instrument_imports(): 

30 from gunicorn import util 

31 from gunicorn.errors import AppImportError 

32 

33def TestInput(data): 

34 

35 fdp = atheris.FuzzedDataProvider(data) 

36 

37 util.is_ipv6(fdp.ConsumeString(100)) 

38 util.warn(fdp.ConsumeString(100)) 

39 util.split_request_uri(fdp.ConsumeString(100)) 

40 

41 try: 

42 util.parse_address(fdp.ConsumeString(100)) 

43 except RuntimeError as e: 

44 if "is not a valid port number." not in str(e): 

45 raise e 

46 

47 try: 

48 util.http_date(fdp.ConsumeInt(50)) 

49 except OSError as e: 

50 if "Value too large for defined data type" not in str(e): 

51 raise e 

52 except (OverflowError,ValueError) as e: 

53 if "out of range" not in str(e): 

54 raise e 

55 

56 try: 

57 util.to_bytestring(fdp.ConsumeString(100)) 

58 util.to_bytestring(fdp.ConsumeString(100),'ascii') 

59 except UnicodeEncodeError as e: 

60 if "codec can't encode character" not in str(e): 

61 raise e 

62 

63 try: 

64 util.import_app(fdp.ConsumeString(100)) 

65 except (ValueError,ImportError,AppImportError) as e: 

66 error_list = [ 

67 "Empty module name", 

68 "No module", 

69 "Failed to parse", 

70 "Function reference", 

71 "literal values", 

72 "attribute name", 

73 "find attribute", 

74 "takes", 

75 "inner", 

76 "find application object", 

77 "callable" 

78 ] 

79 expected_error = False 

80 for error in error_list: 

81 if error in str(e): 

82 expected_error = True 

83 if not expected_error: 

84 raise e 

85 

86def main(): 

87 atheris.Setup(sys.argv, TestInput, enable_python_coverage=True) 

88 atheris.Fuzz() 

89 

90if __name__ == "__main__": 

91 main()