Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline support #106

Merged
merged 12 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pyt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
UImode
)
from .ast_helper import generate_ast
from .baseline import get_vulnerabilities_not_in_baseline
from .constraint_table import (
initialize_constraint_table,
print_table
Expand Down Expand Up @@ -136,6 +137,11 @@ def parse_args(args):

parser.add_argument('-ppm', '--print-project-modules',
help='Print project modules.', action='store_true')
parser.add_argument('-b', '--baseline',
help='path of a baseline report to compare against '
'(only JSON-formatted files are accepted)',
type=str,
default=False)

save_parser = subparsers.add_parser('save', help='Save menu.')
save_parser.set_defaults(which='save')
Expand Down Expand Up @@ -167,6 +173,7 @@ def parse_args(args):
help='Output everything to file.',
action='store_true')


search_parser = subparsers.add_parser(
'github_search',
help='Searches through github and runs PyT'
Expand Down Expand Up @@ -242,6 +249,7 @@ def main(command_line_args=sys.argv[1:]):
repo.clean_up()
exit()


if args.which == 'search':
set_github_api_token()
scan_github(
Expand Down Expand Up @@ -299,6 +307,9 @@ def main(command_line_args=sys.argv[1:]):
args.trigger_word_file
)
)
if args.baseline:
vulnerabilities = get_vulnerabilities_not_in_baseline(vulnerabilities, args.baseline)

if args.json:
json.report(vulnerabilities, sys.stdout)
else:
Expand Down
11 changes: 11 additions & 0 deletions pyt/baseline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this before but from looking at the Code Climate issues at the bottom of the PR, there are a couple of pep8 ones. Normally people have 2 lines between imports and the next class or function call like in expr_visitor.py for example.


def get_vulnerabilities_not_in_baseline(vulnerabilities, baseline):
baseline = json.load(open(baseline))
output = list()
vulnerabilities =[vuln for vuln in vulnerabilities]
for vuln in vulnerabilities:
if vuln.as_dict() not in baseline['vulnerabilities']:
output.append(vuln)
return(output)
1 change: 0 additions & 1 deletion pyt/formatters/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def report(
):
"""
Prints issues in JSON format.

Args:
vulnerabilities: list of vulnerabilities to report
fileobj: The output file object, which may be sys.stdout
Expand Down
2 changes: 1 addition & 1 deletion tests/command_line_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_no_args(self):
[-p | -vp | -trim | -i] [-t TRIGGER_WORD_FILE]
[-m BLACKBOX_MAPPING_FILE] [-py2] [-l LOG_LEVEL]
[-a ADAPTOR] [-db] [-dl DRAW_LATTICE [DRAW_LATTICE ...]]
[-j] [-li | -re | -rt] [-ppm]
[-j] [-li | -re | -rt] [-ppm] [-b BASELINE]
{save,github_search} ...\n""" + \
"python -m pyt: error: one of the arguments " + \
"-f/--filepath -gr/--git-repos is required\n"
Expand Down