Skip to content

Commit

Permalink
fix(signature): avoid generating signatures
Browse files Browse the repository at this point in the history
Avoid generating signatures if no signatures are specified.
  • Loading branch information
dclayton-godaddy committed Apr 4, 2023
1 parent 5bee353 commit 63e5cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tartufo/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,13 @@ def signature_is_excluded(self, blob: str, file_path: str) -> bool:
:param blob: The piece of data which is being scanned
:param file_path: The path and file name for the data being scanned
"""
excluded_signatures = self.excluded_signatures
if len(excluded_signatures) == 0:
return False

return (
blob
in self.excluded_signatures # Signatures themselves pop up as entropy matches
in excluded_signatures # Signatures themselves pop up as entropy matches
or util.generate_signature(blob, file_path) in self.excluded_signatures
)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ def test_rule_patterns_with_rule_patterns_syntax_issue(self):


class SignatureTests(ScannerTestCase):
@mock.patch("tartufo.util.generate_signature")
def test_no_signatures_should_not_generate_signature(self, mock_signature: mock.MagicMock):
test_scanner = TestScanner(self.options)
self.options.exclude_signatures = ()
mock_signature.assert_not_called()
self.assertFalse(test_scanner.signature_is_excluded("bar", "blah"))

@mock.patch("tartufo.util.generate_signature")
def test_matched_signatures_are_excluded(self, mock_signature: mock.MagicMock):
mock_signature.return_value = "foo"
Expand Down

0 comments on commit 63e5cc5

Please sign in to comment.