Skip to content

Commit

Permalink
python-resource-manager: initial integration (google#8124)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKorczynski authored and MartinPetkov committed Aug 15, 2022
1 parent 0601706 commit 3882ee5
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
22 changes: 22 additions & 0 deletions projects/g-api-resource-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

FROM gcr.io/oss-fuzz-base/base-builder-python
RUN apt-get update && apt-get install -y make autoconf automake libtool
RUN pip3 install --upgrade pip && pip install google-api-core google-cloud-core mock
RUN git clone --depth 1 https://github.com/googleapis/python-resource-manager
WORKDIR python-resource-manager
COPY build.sh *.py $SRC/
22 changes: 22 additions & 0 deletions projects/g-api-resource-manager/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -eu
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

GRPC_PYTHON_CFLAGS="${CFLAGS}" GRPC_PYTHON_BUILD_SYSTEM_RE2=true GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip3 install -v .

for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
compile_python_fuzzer $fuzzer
done
141 changes: 141 additions & 0 deletions projects/g-api-resource-manager/fuzz_tag_values_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/python3
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Fuzzer for google/cloud/resourcemanager_v3/services/tag_values/client.py"""

import os
import sys
import atheris

import mock

from google.auth import credentials as ga_credentials
from google.longrunning import operations_pb2
from google.iam.v1 import iam_policy_pb2
from google.iam.v1 import policy_pb2
from google.cloud.resourcemanager_v3.services.tag_values import (
TagValuesAsyncClient,
TagValuesClient,
pagers,
transports,
)
from google.cloud.resourcemanager_v3.types import tag_values


def test_get_tag_value(fdp, client):
if fdp.ConsumeBool():
request = tag_values.GetTagValueRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.get_tag_value), "__call__") as call:
call.return_value = tag_values.TagValue(
name=fdp.ConsumeUnicodeNoSurrogates(10),
parent=fdp.ConsumeUnicodeNoSurrogates(10),
short_name=fdp.ConsumeUnicodeNoSurrogates(10),
namespaced_name=fdp.ConsumeUnicodeNoSurrogates(10),
description=fdp.ConsumeUnicodeNoSurrogates(10),
etag=fdp.ConsumeUnicodeNoSurrogates(10),
)

response = client.get_tag_value(request)


def test_create_tag_value(fdp, client):
if fdp.ConsumeBool():
request = tag_values.CreateTagValueRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.create_tag_value), "__call__") as call:
call.return_value = operations_pb2.Operation(name=fdp.ConsumeUnicodeNoSurrogates(20))
response = client.create_tag_value(request)

def test_update_tag_value(fdp, client):
if fdp.ConsumeBool():
request = tag_values.UpdateTagValueRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.update_tag_value), "__call__") as call:
call.return_value = operations_pb2.Operation(name=fdp.ConsumeUnicodeNoSurrogates(20))
response = client.update_tag_value(request)


def test_delete_tag_value(fdp, client):
if fdp.ConsumeBool():
request = tag_values.DeleteTagValueRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.delete_tag_value), "__call__") as call:
call.return_value = operations_pb2.Operation(name="operations/spam")
response = client.delete_tag_value(request)

def test_get_iam_policy(fdp, client):
if fdp.ConsumeBool():
request = iam_policy_pb2.GetIamPolicyRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call:
call.return_value = policy_pb2.Policy(
version=774,
etag=fdp.ConsumeBytes(20),
)
response = client.get_iam_policy(request)

def test_set_iam_policy(fdp, client):
if fdp.ConsumeBool():
request = iam_policy_pb2.SetIamPolicyRequest()
else:
request = dict()

with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call:
call.return_value = policy_pb2.Policy(
version=774,
etag=fdp.ConsumeBytes(20),
)
response = client.set_iam_policy(request)

def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)

# Create our client
client = TagValuesClient(
credentials=ga_credentials.AnonymousCredentials(),
transport="grpc",
)

# Call a set of operations on the client. Using mocked responses.
operations = [
test_get_tag_value,
test_create_tag_value,
test_update_tag_value,
test_delete_tag_value,
test_get_iam_policy,
test_set_iam_policy
]
number_of_calls = 20
for i in range(number_of_calls):
target = operations[fdp.ConsumeIntInRange(0, len(operations)-1)]
target(fdp, client)

def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Fuzz()

if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions projects/g-api-resource-manager/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
homepage: "https://github.com/googleapis/python-resource-manager"
language: python
main_repo: "https://github.com/googleapis/python-resource-manager"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefined
vendor_ccs:
- [email protected]
- [email protected]
- [email protected]

0 comments on commit 3882ee5

Please sign in to comment.