Skip to content

Commit 63e5cc5

Browse files
fix(signature): avoid generating signatures
Avoid generating signatures if no signatures are specified.
1 parent 5bee353 commit 63e5cc5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tartufo/scanner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,13 @@ def signature_is_excluded(self, blob: str, file_path: str) -> bool:
425425
:param blob: The piece of data which is being scanned
426426
:param file_path: The path and file name for the data being scanned
427427
"""
428+
excluded_signatures = self.excluded_signatures
429+
if len(excluded_signatures) == 0:
430+
return False
431+
428432
return (
429433
blob
430-
in self.excluded_signatures # Signatures themselves pop up as entropy matches
434+
in excluded_signatures # Signatures themselves pop up as entropy matches
431435
or util.generate_signature(blob, file_path) in self.excluded_signatures
432436
)
433437

tests/test_base_scanner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ def test_rule_patterns_with_rule_patterns_syntax_issue(self):
322322

323323

324324
class SignatureTests(ScannerTestCase):
325+
@mock.patch("tartufo.util.generate_signature")
326+
def test_no_signatures_should_not_generate_signature(self, mock_signature: mock.MagicMock):
327+
test_scanner = TestScanner(self.options)
328+
self.options.exclude_signatures = ()
329+
mock_signature.assert_not_called()
330+
self.assertFalse(test_scanner.signature_is_excluded("bar", "blah"))
331+
325332
@mock.patch("tartufo.util.generate_signature")
326333
def test_matched_signatures_are_excluded(self, mock_signature: mock.MagicMock):
327334
mock_signature.return_value = "foo"

0 commit comments

Comments
 (0)