Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(signature): avoid generating signatures #487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions tests/test_base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ 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