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

Nicer audit display #94

Merged
merged 2 commits into from
Nov 6, 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
8 changes: 5 additions & 3 deletions detect_secrets/core/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ def _print_context(filename, secret, count, total, plugin_settings): # pragma:

:raises: SecretNotFoundOnSpecifiedLineError
"""
print('{} {} {} {}\n{} {}'.format(
BashColor.color('Secret', Color.BOLD),
print('{} {} {} {}\n{} {}\n{} {}'.format(
BashColor.color('Secret: ', Color.BOLD),
BashColor.color(str(count), Color.PURPLE),
BashColor.color('of', Color.BOLD),
BashColor.color(str(total), Color.PURPLE),
BashColor.color('Filename:', Color.BOLD),
BashColor.color('Filename: ', Color.BOLD),
BashColor.color(filename, Color.PURPLE),
BashColor.color('Secret Type:', Color.BOLD),
BashColor.color(secret['type'], Color.PURPLE),
))
print('-' * 10)

Expand Down
2 changes: 1 addition & 1 deletion test_data/short_files/first_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
seecret = 'BEEF0123456789a'
secret = 'BEEF0123456789a'
skipped_sequential_false_positive = '0123456789a'
print('second line')
var = 'third line'
4 changes: 2 additions & 2 deletions test_data/short_files/last_line.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[some section]
secreets_for_no_one_to_find =
secrets_for_no_one_to_find =
hunter2
passsword123
password123
BEEF0123456789a
4 changes: 2 additions & 2 deletions test_data/short_files/middle_line.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
deploy:
user: aaronloo
passhword:
password:
secure: thequickbrownfoxjumpsoverthelazydog
on:
repo: Yelp/detect-sechrets
repo: Yelp/detect-secrets
20 changes: 12 additions & 8 deletions tests/core/audit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ def test_basic(self, mock_printer):
assert sed_call.call_args[0][0] == 'sed -n 10,20p filenameA'.split()

assert mock_printer.message == textwrap.dedent("""
Secret 1 of 2
Filename: filenameA
Secret: 1 of 2
Filename: filenameA
Secret Type: Private Key
----------
10:a
11:b
Expand Down Expand Up @@ -394,8 +395,9 @@ def test_secret_at_top_of_file(self, mock_printer):
assert sed_call.call_args[0][0] == 'sed -n 1,6p filenameA'.split()

assert mock_printer.message == textwrap.dedent("""
Secret 1 of 2
Filename: filenameA
Secret: 1 of 2
Filename: filenameA
Secret Type: Private Key
----------
1:-----BEGIN PRIVATE KEY-----
2:e
Expand All @@ -421,8 +423,9 @@ def test_secret_not_found(self, mock_printer):
)

assert mock_printer.message == textwrap.dedent("""
Secret 1 of 2
Filename: filenameA
Secret: 1 of 2
Filename: filenameA
Secret Type: Private Key
----------
ERROR: Secret not found on line 15!
Try recreating your baseline to fix this issue.
Expand Down Expand Up @@ -450,8 +453,9 @@ def test_secret_in_yaml_file(self, mock_printer):
)

assert mock_printer.message == textwrap.dedent("""
Secret 1 of 2
Filename: filenameB
Secret: 1 of 2
Filename: filenameB
Secret Type: Hex High Entropy String
----------
10:a
11:b
Expand Down
19 changes: 11 additions & 8 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_old_baseline_ignored_with_update_flag(
(
'test_data/short_files/first_line.py',
textwrap.dedent("""
1:seecret = 'BEEF0123456789a'
1:secret = 'BEEF0123456789a'
2:skipped_sequential_false_positive = '0123456789a'
3:print('second line')
4:var = 'third line'
Expand All @@ -203,19 +203,19 @@ def test_old_baseline_ignored_with_update_flag(
textwrap.dedent("""
1:deploy:
2: user: aaronloo
3: passhword:
3: password:
4: secure: thequickbrownfoxjumpsoverthelazydog
5: on:
6: repo: Yelp/detect-sechrets
6: repo: Yelp/detect-secrets
""")[1:-1],
),
(
'test_data/short_files/last_line.ini',
textwrap.dedent("""
1:[some section]
2:secreets_for_no_one_to_find =
2:secrets_for_no_one_to_find =
3: hunter2
4: passsword123
4: password123
5: BEEF0123456789a
""")[1:-1],
),
Expand All @@ -231,10 +231,11 @@ def test_audit_short_file(self, filename, expected_output):
main(['scan', filename])
baseline = printer_shim.message

baseline_dict = json.loads(baseline)
with mock_stdin(), mock.patch(
# To pipe in printer_shim
'detect_secrets.core.audit._get_baseline_from_file',
return_value=json.loads(baseline),
return_value=baseline_dict,
), mock.patch(
# We don't want to clear the pytest testing screen
'detect_secrets.core.audit._clear_screen',
Expand All @@ -251,14 +252,16 @@ def test_audit_short_file(self, filename, expected_output):
main('audit will_be_mocked'.split())

assert printer_shim.message == textwrap.dedent("""
Secret 1 of 1
Filename: {}
Secret: 1 of 1
Filename: {}
Secret Type: {}
----------
{}
----------
Saving progress...
""")[1:].format(
filename,
baseline_dict['results'][filename][0]['type'],
expected_output,
)

Expand Down