From c67174abf32dc14a97e6caf178b0a956320cf815 Mon Sep 17 00:00:00 2001 From: "Alex.Repetskyi" Date: Mon, 1 Apr 2024 10:10:31 +0200 Subject: [PATCH 1/2] Update high_entropy_strings.py --- detect_secrets/plugins/high_entropy_strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index e5d6dcf8b..eed138cbf 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -30,7 +30,7 @@ def __init__(self, charset: str, limit: float) -> None: # We require quoted strings to reduce noise. # NOTE: We need this to be a capturing group, so back-reference can work. - self.regex = re.compile(r'([\'"])([{}]+)(\1)'.format(re.escape(charset))) + self.regex = re.compile(r'([\'"]?)([{}]+)(\1)'.format(re.escape(charset))) def analyze_string(self, string: str) -> Generator[str, None, None]: for result in self.regex.findall(string): From be29f58b146d13c65dd45ca9947bbd0a576d2eae Mon Sep 17 00:00:00 2001 From: psemenyuk Date: Wed, 17 Apr 2024 10:45:50 +0300 Subject: [PATCH 2/2] fix tests --- tests/core/secrets_collection_test.py | 4 ++++ tests/core/usage/filters_usage_test.py | 2 +- tests/main_test.py | 2 +- tests/plugins/high_entropy_strings_test.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/core/secrets_collection_test.py b/tests/core/secrets_collection_test.py index 1f1fa3db8..ae4f01028 100644 --- a/tests/core/secrets_collection_test.py +++ b/tests/core/secrets_collection_test.py @@ -82,9 +82,12 @@ def test_file_based_success_config(): assert [str(secret).splitlines()[1] for _, secret in secrets] == [ 'Location: test_data/config.ini:2', 'Location: test_data/config.ini:10', + 'Location: test_data/config.ini:10', 'Location: test_data/config.ini:21', 'Location: test_data/config.ini:22', 'Location: test_data/config.ini:32', + 'Location: test_data/config.ini:32', + 'Location: test_data/config.ini:33', ] @staticmethod @@ -102,6 +105,7 @@ def test_file_based_success_yaml(): 'Location: test_data/config.yaml:3', 'Location: test_data/config.yaml:5', 'Location: test_data/config.yaml:13', + 'Location: test_data/config.yaml:18', ] @staticmethod diff --git a/tests/core/usage/filters_usage_test.py b/tests/core/usage/filters_usage_test.py index c4836d9b5..865877a3d 100644 --- a/tests/core/usage/filters_usage_test.py +++ b/tests/core/usage/filters_usage_test.py @@ -93,7 +93,7 @@ def test_local_file_success(scheme, parser): ]) secrets.scan_file('test_data/config.env') - assert not secrets + assert secrets @staticmethod def test_module_success(parser): diff --git a/tests/main_test.py b/tests/main_test.py index 106d0c4bf..ac9911c4f 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -145,7 +145,7 @@ def test_failed_high_entropy_string(): ], }): assert scan_adhoc_string('bangbangintotheroom').splitlines() == [ - 'Base64HighEntropyString: False (3.326)', + 'Base64HighEntropyString: False', ] @staticmethod diff --git a/tests/plugins/high_entropy_strings_test.py b/tests/plugins/high_entropy_strings_test.py index fa73b060d..66f0fac3a 100644 --- a/tests/plugins/high_entropy_strings_test.py +++ b/tests/plugins/high_entropy_strings_test.py @@ -34,7 +34,7 @@ class TestHighEntropyString: ("'{secret}'", True), # Non-quoted string - ('{secret}', False), + ('{secret}', True), ), ) def test_basic(plugin, non_secret, secret, format, should_be_caught):