Skip to content

Commit

Permalink
updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Dec 30, 2020
1 parent d34eecd commit 66f44b1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- '3.6'
- '3.7'
- '3.8'
- '3.9'
before_script:
- export PYTHONPATH=$PYTHONPATH:$(pwd)
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
Expand Down
16 changes: 10 additions & 6 deletions apifuzzer/fuzz_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,34 @@ def container_name_to_param(container_name):
return container_name.split('|')[-1]


def get_api_definition_from_file(src_file):
def get_api_definition_from_file(src_file, logger=None):
if logger:
print_func = logger
else:
print_func = print
try:
with open(src_file, mode='rb') as f:
api_definition = f.read()
try:
return json.loads(api_definition.decode('utf-8'))
except ValueError as e:
print('Failed to load input as JSON, maybe YAML?')
print_func('Failed to load input as JSON, maybe YAML?')
try:
yaml = YAML(typ='safe')
return yaml.load(api_definition)
except (TypeError, ScannerError) as e:
print('Failed to load input as YAML:{}'.format(e))
print_func('Failed to load input as YAML:{}'.format(e))
raise e
except (Exception, FileNotFoundError):
print('Failed to parse input file, exit')
print_func('Failed to parse input file, exit')
raise FailedToParseFileException


def get_api_definition_from_url(url, temp_file=None):
def get_api_definition_from_url(url, temp_file=None, logger=None):
if temp_file is None:
temp_file = tempfile.NamedTemporaryFile().name
download_file(url, temp_file)
return get_api_definition_from_file(temp_file)
return get_api_definition_from_file(temp_file, logger=logger)


def get_base_url_form_api_src(url):
Expand Down
9 changes: 4 additions & 5 deletions apifuzzer/openapi_template_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def resolve_json_reference(self, param):
self.logger.debug('Looking for remote reference: {}'.format(schema_ref))
resource_reference, item_location = schema_ref.split('#', 1)
self.logger.info('Downloading resource from: {} and using {}'.format(resource_reference, item_location))
schema_definition = get_api_definition_from_url(resource_reference)
schema_definition = get_api_definition_from_url(resource_reference, logger=self.logger.debug)
schema_properties = self.get_properties_from_schema_definition(schema_definition, item_location)
elif schema_ref.startswith('//'):
self.logger.warning('Not implemented import: {}'.format(schema_ref))
Expand All @@ -148,7 +148,7 @@ def resolve_json_reference(self, param):
self.logger.debug('It seems the schema is stored in local file {}, schema location: {}'
.format(file_reference, item_location))
try:
schema_definition = get_api_definition_from_file(file_reference)
schema_definition = get_api_definition_from_file(file_reference, logger=self.logger.debug)
except FailedToParseFileException:
# This part is necessary only because some of the API definitions doesn't follow the standard
if len(self.api_definition_url):
Expand All @@ -157,7 +157,7 @@ def resolve_json_reference(self, param):
.format(self.api_definition_url, file_reference))
api_definition_url = "/".join([get_base_url_form_api_src(self.api_definition_url), file_reference])
self.logger.debug('Trying to fetch api definition from: {}'.format(api_definition_url))
schema_definition = get_api_definition_from_url(api_definition_url)
schema_definition = get_api_definition_from_url(api_definition_url, logger=self.logger.debug)
else:
self.logger.warning('Local file reference was found in API definition, but file is not available')
schema_definition = dict()
Expand Down Expand Up @@ -273,7 +273,6 @@ def _save_template(self, template):
def pre_process_api_resources(self):
iteration = 0
while True:
self.logger.debug(f'{iteration}')
tmp_api_resource = dict()
paths = self.api_resources['paths']
for resource in paths.keys():
Expand Down Expand Up @@ -307,7 +306,7 @@ def process_api_resources(self, paths=None):
template.url = normalized_url
template.method = method.upper()
params_to_process = list(paths[resource][method].get('parameters', {}))
params_to_process.append(paths[resource][method].get('requestBody', {}))
params_to_process.append(paths[resource][method].get('requestBody', {}).get('content', {}))
for param in params_to_process:

if not isinstance(param, dict):
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kittyfuzzer==0.7.4
pycurl==7.43.0.5
ruamel.yaml==0.16.7
junit-xml==1.8
pycurl==7.43.0.6
ruamel.yaml==0.16.12
junit-xml==1.9
14 changes: 7 additions & 7 deletions test/requirements_for_test.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Flask==1.1.1
pytest==5.3.5
pytest-cov==2.8.1
sphinx==2.4.1
Flask==1.1.2
pytest==6.2.1
pytest-cov==2.10.1
sphinx==3.4.1
sphinx_rtd_theme
pytest-html==2.0.1
coverage==5.0.3
hypothesis==5.10.4
pytest-html==3.1.1
coverage==5.3.1
hypothesis==5.43.4
attrs>=19.2.0

0 comments on commit 66f44b1

Please sign in to comment.