Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/tests/fuzzed/__init__.py: 94%

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

16 statements  

1"""This is a collection of test files that are generated from the fuzzer. 

2 

3The fuzzer finds the cases in which the icalendar module breaks. 

4These test cases reproduce the failure. 

5Some more tests can be added to make sure that the behavior works properly. 

6""" 

7 

8_value_error_matches = [ 

9 "component", 

10 "parse", 

11 "Expected", 

12 "Wrong date format", 

13 "END encountered", 

14 "vDDD", 

15 "recurrence", 

16 "Offset must", 

17 "Invalid iCalendar", 

18 "alue MUST", 

19 "Key name", 

20 "Invalid content line", 

21 "does not exist", 

22 "base 64", 

23 "must use datetime", 

24 "Unknown date type", 

25 "Wrong", 

26 "Start time", 

27 "iCalendar", 

28 "recurrence", 

29 "float, float", 

30 "utc offset", 

31 "parent", 

32 "MUST be a datetime", 

33 "Invalid month:", 

34 "must have exactly", # vCard field count validation (ADR, N) 

35 "must have at least", # vCard ORG minimum field validation 

36] 

37 

38 

39def fuzz_v1_calendar( 

40 from_ical, calendar_string: str, multiple: bool, should_walk: bool 

41): 

42 """Take a from_ical function and reproduce the error. 

43 

44 The calendar_string is a fuzzed input. 

45 """ 

46 try: 

47 cal = from_ical(calendar_string, multiple=multiple) 

48 

49 if not multiple: 

50 cal = [cal] 

51 for c in cal: 

52 if should_walk: 

53 for event in c.walk("VEVENT"): 

54 event.to_ical() 

55 else: 

56 c.to_ical() 

57 except (ValueError, TypeError) as e: 

58 if any(m in str(e) for m in _value_error_matches): 

59 return -1 

60 raise