Skip to content

Commit a734ee8

Browse files
authored
Merge pull request #94 from Yelp/nicer-audit
Nicer audit display
2 parents 411a865 + 01cfaf1 commit a734ee8

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

detect_secrets/core/audit.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ def _print_context(filename, secret, count, total, plugin_settings): # pragma:
132132
133133
:raises: SecretNotFoundOnSpecifiedLineError
134134
"""
135-
print('{} {} {} {}\n{} {}'.format(
136-
BashColor.color('Secret', Color.BOLD),
135+
print('{} {} {} {}\n{} {}\n{} {}'.format(
136+
BashColor.color('Secret: ', Color.BOLD),
137137
BashColor.color(str(count), Color.PURPLE),
138138
BashColor.color('of', Color.BOLD),
139139
BashColor.color(str(total), Color.PURPLE),
140-
BashColor.color('Filename:', Color.BOLD),
140+
BashColor.color('Filename: ', Color.BOLD),
141141
BashColor.color(filename, Color.PURPLE),
142+
BashColor.color('Secret Type:', Color.BOLD),
143+
BashColor.color(secret['type'], Color.PURPLE),
142144
))
143145
print('-' * 10)
144146

test_data/short_files/first_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
seecret = 'BEEF0123456789a'
1+
secret = 'BEEF0123456789a'
22
skipped_sequential_false_positive = '0123456789a'
33
print('second line')
44
var = 'third line'

test_data/short_files/last_line.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[some section]
2-
secreets_for_no_one_to_find =
2+
secrets_for_no_one_to_find =
33
hunter2
4-
passsword123
4+
password123
55
BEEF0123456789a

test_data/short_files/middle_line.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
deploy:
22
user: aaronloo
3-
passhword:
3+
password:
44
secure: thequickbrownfoxjumpsoverthelazydog
55
on:
6-
repo: Yelp/detect-sechrets
6+
repo: Yelp/detect-secrets

tests/core/audit_test.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ def test_basic(self, mock_printer):
362362
assert sed_call.call_args[0][0] == 'sed -n 10,20p filenameA'.split()
363363

364364
assert mock_printer.message == textwrap.dedent("""
365-
Secret 1 of 2
366-
Filename: filenameA
365+
Secret: 1 of 2
366+
Filename: filenameA
367+
Secret Type: Private Key
367368
----------
368369
10:a
369370
11:b
@@ -394,8 +395,9 @@ def test_secret_at_top_of_file(self, mock_printer):
394395
assert sed_call.call_args[0][0] == 'sed -n 1,6p filenameA'.split()
395396

396397
assert mock_printer.message == textwrap.dedent("""
397-
Secret 1 of 2
398-
Filename: filenameA
398+
Secret: 1 of 2
399+
Filename: filenameA
400+
Secret Type: Private Key
399401
----------
400402
1:-----BEGIN PRIVATE KEY-----
401403
2:e
@@ -421,8 +423,9 @@ def test_secret_not_found(self, mock_printer):
421423
)
422424

423425
assert mock_printer.message == textwrap.dedent("""
424-
Secret 1 of 2
425-
Filename: filenameA
426+
Secret: 1 of 2
427+
Filename: filenameA
428+
Secret Type: Private Key
426429
----------
427430
ERROR: Secret not found on line 15!
428431
Try recreating your baseline to fix this issue.
@@ -450,8 +453,9 @@ def test_secret_in_yaml_file(self, mock_printer):
450453
)
451454

452455
assert mock_printer.message == textwrap.dedent("""
453-
Secret 1 of 2
454-
Filename: filenameB
456+
Secret: 1 of 2
457+
Filename: filenameB
458+
Secret Type: Hex High Entropy String
455459
----------
456460
10:a
457461
11:b

tests/main_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_old_baseline_ignored_with_update_flag(
192192
(
193193
'test_data/short_files/first_line.py',
194194
textwrap.dedent("""
195-
1:seecret = 'BEEF0123456789a'
195+
1:secret = 'BEEF0123456789a'
196196
2:skipped_sequential_false_positive = '0123456789a'
197197
3:print('second line')
198198
4:var = 'third line'
@@ -203,19 +203,19 @@ def test_old_baseline_ignored_with_update_flag(
203203
textwrap.dedent("""
204204
1:deploy:
205205
2: user: aaronloo
206-
3: passhword:
206+
3: password:
207207
4: secure: thequickbrownfoxjumpsoverthelazydog
208208
5: on:
209-
6: repo: Yelp/detect-sechrets
209+
6: repo: Yelp/detect-secrets
210210
""")[1:-1],
211211
),
212212
(
213213
'test_data/short_files/last_line.ini',
214214
textwrap.dedent("""
215215
1:[some section]
216-
2:secreets_for_no_one_to_find =
216+
2:secrets_for_no_one_to_find =
217217
3: hunter2
218-
4: passsword123
218+
4: password123
219219
5: BEEF0123456789a
220220
""")[1:-1],
221221
),
@@ -231,10 +231,11 @@ def test_audit_short_file(self, filename, expected_output):
231231
main(['scan', filename])
232232
baseline = printer_shim.message
233233

234+
baseline_dict = json.loads(baseline)
234235
with mock_stdin(), mock.patch(
235236
# To pipe in printer_shim
236237
'detect_secrets.core.audit._get_baseline_from_file',
237-
return_value=json.loads(baseline),
238+
return_value=baseline_dict,
238239
), mock.patch(
239240
# We don't want to clear the pytest testing screen
240241
'detect_secrets.core.audit._clear_screen',
@@ -251,14 +252,16 @@ def test_audit_short_file(self, filename, expected_output):
251252
main('audit will_be_mocked'.split())
252253

253254
assert printer_shim.message == textwrap.dedent("""
254-
Secret 1 of 1
255-
Filename: {}
255+
Secret: 1 of 1
256+
Filename: {}
257+
Secret Type: {}
256258
----------
257259
{}
258260
----------
259261
Saving progress...
260262
""")[1:].format(
261263
filename,
264+
baseline_dict['results'][filename][0]['type'],
262265
expected_output,
263266
)
264267

0 commit comments

Comments
 (0)