Skip to content

Commit 2dd83ad

Browse files
XIANJUN ZHUjustineyster
XIANJUN ZHU
authored andcommitted
Verify by default for baseline (Yelp#313)
Add back missing param (Yelp#314)
1 parent 01ca438 commit 2dd83ad

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

detect_secrets/core/secrets_collection.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ def load_baseline_from_dict(cls, data):
122122
# The difference will show whenever the word list changes
123123
automaton, result.word_list_hash = build_automaton(result.word_list_file)
124124

125-
# In v0.14.0 the `--custom-plugins` option got added
126-
result.custom_plugin_paths = tuple(data.get('custom_plugin_paths', ()))
127-
128-
result.plugins = tuple(
129-
initialize.from_plugin_classname(
130-
plugin_classname=plugin.pop('name'),
131-
custom_plugin_paths=result.custom_plugin_paths,
132-
exclude_lines_regex=result.exclude_lines,
133-
automaton=automaton,
134-
should_verify_secrets=False,
135-
**plugin
136-
) for plugin in data['plugins_used']
137-
)
125+
plugins = []
126+
for plugin in data['plugins_used']:
127+
plugin_classname = plugin.pop('name')
128+
plugins.append(
129+
initialize.from_plugin_classname(
130+
plugin_classname,
131+
exclude_lines_regex=result.exclude_lines,
132+
automaton=automaton,
133+
should_verify_secrets=True,
134+
**plugin
135+
),
136+
)
137+
result.plugins = tuple(plugins)
138138

139139
for filename in data['results']:
140140
result.data[filename] = {}

detect_secrets/plugins/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def adhoc_scan(self, string):
224224

225225
verified_result = VerifiedResult.UNVERIFIED
226226
for result in results:
227-
is_verified = self.verify(result.secret_value)
227+
is_verified = self.verify(result.secret_value, string, result)
228228
if is_verified != VerifiedResult.UNVERIFIED:
229229
verified_result = is_verified
230230
break

detect_secrets/plugins/high_entropy_strings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class HighEntropyStringsPlugin(BasePlugin):
2727

2828
__metaclass__ = ABCMeta
2929

30-
def __init__(self, charset, limit, exclude_lines_regex, automaton, *args):
30+
def __init__(self, charset, limit, exclude_lines_regex, automaton, *args, **kwargs):
3131
if limit < 0 or limit > 8:
3232
raise ValueError(
3333
'The limit set for HighEntropyStrings must be between 0.0 and 8.0',
@@ -46,6 +46,8 @@ def __init__(self, charset, limit, exclude_lines_regex, automaton, *args):
4646
super(HighEntropyStringsPlugin, self).__init__(
4747
exclude_lines_regex=exclude_lines_regex,
4848
false_positive_heuristics=false_positive_heuristics,
49+
*args,
50+
**kwargs
4951
)
5052

5153
def analyze(self, file, filename, output_raw=False, output_verified_false=False):
@@ -335,6 +337,7 @@ def __init__(self, hex_limit, exclude_lines_regex=None, automaton=None, **kwargs
335337
limit=hex_limit,
336338
exclude_lines_regex=exclude_lines_regex,
337339
automaton=automaton,
340+
**kwargs
338341
)
339342

340343
@classproperty

tests/core/baseline_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ def test_copies_is_secret_label_accurately(self):
491491
},
492492

493493
}
494-
pass
495494

496495

497496
class TestMergeResults:

tests/core/secrets_collection_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,13 @@ def test_load_baseline_from_string_with_point_twelve_point_seven_and_later_strin
344344
data=word_list,
345345
namespace='detect_secrets.util.open',
346346
):
347-
secrets = SecretsCollection.load_baseline_from_string(
347+
baseline = SecretsCollection.load_baseline_from_string(
348348
json.dumps(original),
349-
).format_for_baseline_output()
349+
)
350+
for plugin in baseline.plugins:
351+
assert plugin.should_verify is True
352+
353+
secrets = baseline.format_for_baseline_output()
350354

351355
# v0.14.0+ assertions
352356
assert 'custom_plugin_paths' not in original

0 commit comments

Comments
 (0)