Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_helpers.py: 60%
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
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.
27import atheris
28import sys
29import binascii
30with atheris.instrument_imports():
31 import oauth2client._helpers as helpers
33def TestInput(data):
34 fdp = atheris.FuzzedDataProvider(data)
36 expected_error_list = [
37 'URL-encoded content contains a repeated value:',
38 'Invalid IPv6 URL',
39 'Is a symbolic link.',
40 'Is a directory',
41 'Incorrect padding',
42 'Invalid base64-encoded string',
43 'could not be converted to',
44 'contains invalid characters under NFKC normalization'
45 ]
47 try:
48 helpers.scopes_to_string([
49 fdp.ConsumeUnicodeNoSurrogates(20),
50 fdp.ConsumeUnicodeNoSurrogates(20)
51 ])
52 helpers.scopes_to_string(fdp.ConsumeUnicodeNoSurrogates(20))
54 helpers.string_to_scopes(fdp.ConsumeUnicodeNoSurrogates(100))
56 helpers.parse_unique_urlencoded(fdp.ConsumeUnicodeNoSurrogates(100))
58 helpers.update_query_params(
59 fdp.ConsumeUnicodeNoSurrogates(100),{
60 fdp.ConsumeUnicodeNoSurrogates(10):fdp.ConsumeUnicodeNoSurrogates(20),
61 fdp.ConsumeUnicodeNoSurrogates(10):fdp.ConsumeUnicodeNoSurrogates(20),
62 fdp.ConsumeUnicodeNoSurrogates(10):fdp.ConsumeUnicodeNoSurrogates(20)
63 })
65 helpers._add_query_parameter(
66 fdp.ConsumeUnicodeNoSurrogates(100),
67 fdp.ConsumeUnicodeNoSurrogates(10),
68 fdp.ConsumeUnicodeNoSurrogates(20)
69 )
71 helpers.validate_file(fdp.ConsumeUnicodeNoSurrogates(100))
73 helpers._json_encode(fdp.ConsumeUnicodeNoSurrogates(100))
75 input = fdp.ConsumeUnicodeNoSurrogates(100).encode('ascii', errors='ignore').decode()
76 helpers._to_bytes(input)
77 helpers._from_bytes(fdp.ConsumeUnicodeNoSurrogates(100))
79 helpers._urlsafe_b64encode(fdp.ConsumeUnicodeNoSurrogates(100))
80 input = fdp.ConsumeUnicodeNoSurrogates(100).encode('ascii', errors='ignore').decode()
81 helpers._urlsafe_b64decode(input)
82 except (ValueError, IOError, binascii.Error) as e:
83 expected = False
84 for expected_error in expected_error_list:
85 if expected_error in str(e):
86 expected = True
87 break
88 if not expected:
89 raise e
91def main():
92 atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
93 atheris.Fuzz()
95if __name__ == "__main__":
96 main()