Skip to content

Commit 6945f4c

Browse files
oauth2client: initial integration (#8083)
* oauth2client: initial integration Create fuzzers * Update fuzz_basic.py Co-authored-by: jonathanmetzman <[email protected]>
1 parent f23485d commit 6945f4c

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

projects/oauth2/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
17+
FROM gcr.io/oss-fuzz-base/base-builder-python
18+
19+
RUN git clone --depth=1 https://github.com/googleapis/oauth2client oauth2
20+
WORKDIR oauth2
21+
22+
COPY build.sh fuzz_*.py $SRC/

projects/oauth2/build.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash -eu
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
18+
# Build and install project (using current CFLAGS, CXXFLAGS).
19+
pip3 install --upgrade pip
20+
pip3 install .
21+
22+
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
23+
compile_python_fuzzer $fuzzer
24+
done

projects/oauth2/fuzz_basic.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/python3
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import atheris
17+
import sys
18+
19+
with atheris.instrument_imports():
20+
from oauth2client.client import OAuth2WebServerFlow
21+
from oauth2client.client import OAuth2DeviceCodeError
22+
23+
def TestInput(data):
24+
fdp = atheris.FuzzedDataProvider(data)
25+
26+
CLIENT_ID = fdp.ConsumeString(100)
27+
CLIENT_SECRET = fdp.ConsumeString(100)
28+
SCOPES = ("https://localhost:%d/%s"%(
29+
fdp.ConsumeIntInRange(1000,65535),
30+
fdp.ConsumeString(50)
31+
))
32+
33+
try:
34+
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, " ".join(SCOPES))
35+
flow_info = flow.step1_get_device_and_user_codes()
36+
credentials = flow.step2_exchange(device_flow_info=flow_info)
37+
except OAuth2DeviceCodeError as e:
38+
pass
39+
40+
def main():
41+
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
42+
atheris.Fuzz()
43+
44+
if __name__ == "__main__":
45+
main()

projects/oauth2/fuzz_helpers.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/python3
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import atheris
17+
import sys
18+
with atheris.instrument_imports():
19+
import oauth2client._helpers as helpers
20+
21+
def TestInput(data):
22+
fdp = atheris.FuzzedDataProvider(data)
23+
24+
helpers.scopes_to_string([
25+
fdp.ConsumeString(20),
26+
fdp.ConsumeString(20)
27+
])
28+
helpers.scopes_to_string(fdp.ConsumeString(20))
29+
30+
helpers.string_to_scopes(fdp.ConsumeString(100))
31+
32+
helpers.parse_unique_urlencoded(fdp.ConsumeString(100))
33+
34+
helpers.update_query_params(
35+
fdp.ConsumeString(100),{
36+
fdp.ConsumeString(10):fdp.ConsumeString(20),
37+
fdp.ConsumeString(10):fdp.ConsumeString(20),
38+
fdp.ConsumeString(10):fdp.ConsumeString(20)
39+
})
40+
41+
helpers._add_query_parameter(
42+
fdp.ConsumeString(100),
43+
fdp.ConsumeString(10),
44+
fdp.ConsumeString(20)
45+
)
46+
47+
helpers.validate_file(fdp.ConsumeString(100))
48+
49+
helpers._json_encode(fdp.ConsumeString(100))
50+
51+
helpers._to_bytes(fdp.ConsumeString(100))
52+
helpers._from_bytes(fdp.ConsumeBytes(100))
53+
54+
helpers._urlsafe_b64encode(fdp.ConsumeString(100))
55+
helpers._urlsafe_b64decode(fdp.ConsumeString(100))
56+
57+
def main():
58+
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
59+
atheris.Fuzz()
60+
61+
if __name__ == "__main__":
62+
main()

projects/oauth2/project.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fuzzing_engines:
2+
- libfuzzer
3+
homepage: https://github.com/googleapis/oauth2client
4+
language: python
5+
main_repo: https://github.com/googleapis/oauth2client
6+
sanitizers:
7+
- address
8+
- undefined
9+
vendor_ccs:
10+
11+
12+

0 commit comments

Comments
 (0)