Skip to content

Commit

Permalink
Add whitelist to Keyword plugin, fix the rest of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Sep 20, 2018
1 parent e4911bf commit d912ced
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion detect_secrets/core/potential_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
):
"""
:type typ: str
:param typ: human-readable secret types, defined by the plugins
:param typ: human-readable secret type, defined by the plugin
that generated this PotentialSecret.
e.g. "High Entropy String"
Expand Down
4 changes: 4 additions & 0 deletions detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from .base import BasePlugin
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.plugins.core.constants import WHITELIST_REGEX


BLACKLIST = (
Expand All @@ -51,6 +52,9 @@ class KeywordDetector(BasePlugin):
def analyze_string(self, string, line_num, filename):
output = {}

if WHITELIST_REGEX.search(string):
return output

for identifier in self.secret_generator(string.lower()):
secret = PotentialSecret(
self.secret_type,
Expand Down
2 changes: 1 addition & 1 deletion test_data/files/file_with_secrets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# Will change this later.
SUPER_SECRET_VALUE = 'c3VwZXIgbG9uZyBzdHJpbmcgc2hvdWxkIGNhdXNlIGVub3VnaCBlbnRyb3B5'
SUPER_SEECRET_VALUE = 'c3VwZXIgbG9uZyBzdHJpbmcgc2hvdWxkIGNhdXNlIGVub3VnaCBlbnRyb3B5'
VERY_SECRET_TOO = 'f6CGV4aMM9zedoh3OUNbSakBymo7yplB' # pragma: whitelist secret


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 @@
secret = 'BEEF0123456789a'
seecret = 'BEEF0123456789a'
skipped_sequential_false_positive = '0123456789a'
print('second line')
var = 'third line'
2 changes: 1 addition & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_old_baseline_ignored_with_update_flag(
(
'test_data/short_files/first_line.py',
textwrap.dedent("""
1:secret = 'BEEF0123456789a'
1:seecret = 'BEEF0123456789a'
2:skipped_sequential_false_positive = '0123456789a'
3:print('second line')
4:var = 'third line'
Expand Down

0 comments on commit d912ced

Please sign in to comment.