Skip to content

Commit

Permalink
#30 handle yaml input file
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Feb 11, 2020
1 parent b5aaf52 commit 1ff2420
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if you application can cope with the fuzzed parameters. Does not require coding.

## Pre-requirements
1. Python3
2. libcurl4-openssl-dev libssl-dev (for pycurl)
2. sudo apt install libcurl4-openssl-dev libssl-dev (on Ubuntu 18.04, required by pycurl)

## Installation

Expand Down
19 changes: 15 additions & 4 deletions apifuzzer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import pycurl
from bitstring import Bits
from ruamel.yaml import YAML
from ruamel.yaml.scanner import ScannerError

from apifuzzer.custom_fuzzers import RandomBitsField

Expand Down Expand Up @@ -142,8 +144,17 @@ def save_api_definition(url, temp_file):
def get_api_definition_from_file(src_file):
try:
with open(src_file, mode='rb') as f:
api_definition_json = json.loads(f.read())
except Exception as e:
print('Failed to parse input file: {}'.format(e))
api_definition = f.read()
try:
return json.loads(api_definition)
except ValueError as e:
print('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))
raise e
except Exception:
print('Failed to parse input file, exit')
exit()
return api_definition_json
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
kittyfuzzer==0.7.4
pycurl==7.43.0.1
pycurl==7.43.0.5
ruamel.yaml==0.16.7

0 comments on commit 1ff2420

Please sign in to comment.