Skip to content

Commit 29b3b78

Browse files
committed
Default lineno to be 0 in PotentialSecret, Change typ to be list
1 parent 60267d9 commit 29b3b78

9 files changed

+23
-24
lines changed

detect_secrets/core/audit.py

-4
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ def _highlight_secret(secret_line, secret, filename, plugin_settings):
321321
plugin.secret_type,
322322
filename,
323323
secret=raw_secret,
324-
325-
# This doesn't matter, because PotentialSecret only uses
326-
# line numbers for logging, and we're not logging it.
327-
lineno=0,
328324
)
329325

330326
# There could be more than two secrets on the same line.

detect_secrets/core/potential_secret.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ def __init__(
1818
self,
1919
typ,
2020
filename,
21-
lineno,
2221
secret,
22+
lineno=0,
2323
is_secret=None,
2424
):
2525
"""
26-
:type typ: str
27-
:param typ: human-readable secret type, defined by the plugin
26+
:type typ: list(str)
27+
:param typ: human-readable secret types, defined by the plugins
2828
that generated this PotentialSecret.
29-
e.g. "High Entropy String"
29+
e.g. ["High Entropy String"]
3030
3131
:type filename: str
3232
:param filename: name of file that this secret was found
3333
34+
:type secret: str
35+
:param secret: the actual secret identified
36+
3437
:type lineno: int
3538
:param lineno: location of secret, within filename.
3639
Merely used as a reference for easy triage.
3740
38-
:type secret: str
39-
:param secret: the actual secret identified
40-
4141
:type is_secret: bool|None
4242
:param is_secret: whether or not the secret is a true- or false- positive
4343
"""
44-
self.type = typ
44+
self.type = [typ]
4545
self.filename = filename
4646
self.lineno = lineno
4747
self.secret_hash = self.hash_secret(secret)
@@ -87,7 +87,10 @@ def __ne__(self, other):
8787

8888
def __hash__(self):
8989
return hash(
90-
tuple([getattr(self, x) for x in self.fields_to_compare]),
90+
tuple(
91+
getattr(self, x)
92+
for x in self.fields_to_compare
93+
),
9194
)
9295

9396
def __str__(self): # pragma: no cover

detect_secrets/core/secrets_collection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def _load_baseline_from_dict(cls, data):
8888
secret = PotentialSecret(
8989
item['type'],
9090
filename,
91-
item['line_number'],
9291
secret='will be replaced',
92+
lineno=item['line_number'],
9393
is_secret=item.get('is_secret'),
9494
)
9595
secret.secret_hash = item['hashed_secret']
@@ -204,7 +204,7 @@ def get_secret(self, filename, secret, type_=None):
204204
if type_:
205205
# Optimized lookup, because we know the type of secret
206206
# (and therefore, its hash)
207-
tmp_secret = PotentialSecret(type_, filename, 0, 'will be overriden')
207+
tmp_secret = PotentialSecret(type_, filename, secret='will be overriden')
208208
tmp_secret.secret_hash = secret
209209

210210
if tmp_secret in self.data[filename]:

detect_secrets/plugins/basic_auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def analyze_string(self, string, line_num, filename):
2222
secret = PotentialSecret(
2323
self.secret_type,
2424
filename,
25-
line_num,
2625
result,
26+
line_num,
2727
)
2828
output[secret] = secret
2929

detect_secrets/plugins/high_entropy_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def analyze_string(self, string, line_num, filename):
102102
for result in self.secret_generator(string):
103103
if self.is_sequential_string(result):
104104
continue
105-
secret = PotentialSecret(self.secret_type, filename, line_num, result)
105+
secret = PotentialSecret(self.secret_type, filename, result, line_num)
106106
output[secret] = secret
107107

108108
return output

detect_secrets/plugins/keyword.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def analyze_string(self, string, line_num, filename):
5555
secret = PotentialSecret(
5656
self.secret_type,
5757
filename,
58-
line_num,
5958
identifier,
59+
line_num,
6060
)
6161
output[secret] = secret
6262

detect_secrets/plugins/private_key.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def analyze_string(self, string, line_num, filename):
5555
secret = PotentialSecret(
5656
self.secret_type,
5757
filename,
58-
line_num,
5958
identifier,
59+
line_num,
6060
)
6161
output[secret] = secret
6262

tests/core/baseline_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_new_secret_line_old_file(self):
178178
results = get_secrets_not_in_baseline(new_findings, baseline)
179179

180180
assert len(results.data['filename']) == 1
181-
secretA = PotentialSecret('type', 'filename', 1, 'secret1')
181+
secretA = PotentialSecret('type', 'filename', 'secret1', 1)
182182
assert results.data['filename'][secretA].secret_hash == \
183183
PotentialSecret.hash_secret('secret1')
184184
assert baseline.data == backup_baseline
@@ -201,7 +201,7 @@ def test_rolled_creds(self):
201201

202202
assert len(results.data['filename']) == 1
203203

204-
secretA = PotentialSecret('type', 'filename', 1, 'secret_new')
204+
secretA = PotentialSecret('type', 'filename', 'secret_new', 1)
205205
assert results.data['filename'][secretA].secret_hash == \
206206
PotentialSecret.hash_secret('secret_new')
207207
assert baseline.data == backup_baseline

tests/core/secrets_collection_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class MockPluginFixedValue(MockBasePlugin):
369369
def analyze(self, f, filename):
370370
# We're not testing the plugin's ability to analyze secrets, so
371371
# it doesn't matter what we return
372-
secret = PotentialSecret('mock fixed value type', filename, 1, 'asdf')
372+
secret = PotentialSecret('mock fixed value type', filename, 'asdf', 1)
373373
return {secret: secret}
374374

375375

@@ -380,7 +380,7 @@ class MockPluginFileValue(MockBasePlugin):
380380
def analyze(self, f, filename):
381381
# We're not testing the plugin's ability to analyze secrets, so
382382
# it doesn't matter what we return
383-
secret = PotentialSecret('mock file value type', filename, 2, f.read().strip())
383+
secret = PotentialSecret('mock file value type', filename, f.read().strip(), 2)
384384
return {secret: secret}
385385

386386

@@ -389,7 +389,7 @@ class MockPasswordPluginValue(MockBasePlugin):
389389
secret_type = 'mock_plugin_file_value'
390390

391391
def analyze(self, f, filename):
392-
password_secret = PotentialSecret('Password', filename, 2, f.read().strip())
392+
password_secret = PotentialSecret('Password', filename, f.read().strip(), 2)
393393
return {
394394
password_secret: password_secret,
395395
}

0 commit comments

Comments
 (0)