-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with signature matching (#33)
* Fix bug with signature matching * Fix indent * Add some tests, don't expone on non-existent config keys * Fix CI
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '2.1.0' | ||
__version__ = '2.1.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import unittest | ||
from typing import Optional | ||
|
||
from tell_me_your_secrets.__main__ import (MatchResult, Signature, | ||
SignatureRecognizer) | ||
|
||
|
||
class MockSignature(Signature): | ||
def match(self, file_path: str, file_content: str) -> MatchResult: | ||
return MatchResult(self.is_fail, self.matched_value or '') | ||
|
||
def __init__(self, is_fail: bool, matched_value: Optional[str] = None): | ||
super().__init__('file', 'Mock Signature', 'Mock Signature') | ||
self.is_fail = is_fail | ||
self.matched_value = matched_value | ||
|
||
|
||
class RunSignaturesTest(unittest.TestCase): | ||
|
||
def test_run_signatures_matched(self): | ||
signature_recognizer = SignatureRecognizer({}, '.', False) | ||
signature_recognizer.signatures.append(MockSignature(True, 'matched-yada')) | ||
|
||
result = signature_recognizer.run_signatures('file/with/issues', 'dodgy-content') | ||
self.assertEquals('Mock Signature', result[0]) | ||
self.assertEquals('file', result[1]) | ||
|
||
def test_run_signatures_whitelisted(self): | ||
signature_recognizer = SignatureRecognizer({}, '.', False) | ||
signature_recognizer.whitelisted_strings.append('matched-yada') | ||
signature_recognizer.signatures.append(MockSignature(True, 'matched-yada')) | ||
|
||
result = signature_recognizer.run_signatures('file/with/issues', 'dodgy-content') | ||
self.assertIsNone(result[0]) | ||
self.assertIsNone(result[1]) |