From 4f76df466d66edea4519c91f17a25f2063d40d84 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 6 Apr 2018 14:39:54 -0700 Subject: [PATCH 1/2] [private key plugin] Change analyze_string output dict to have PotentialSecret as the key, not filename --- detect_secrets/plugins/private_key.py | 3 ++- tests/plugins/private_key_test.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/detect_secrets/plugins/private_key.py b/detect_secrets/plugins/private_key.py index 8498907f4..64a500e99 100644 --- a/detect_secrets/plugins/private_key.py +++ b/detect_secrets/plugins/private_key.py @@ -40,11 +40,12 @@ def analyze_string(self, string, line_num, filename): output = {} if any(line in string for line in BLACKLIST): - output[filename] = PotentialSecret( + secret = PotentialSecret( self.secret_type, filename, line_num, string, ) + output[secret] = secret return output diff --git a/tests/plugins/private_key_test.py b/tests/plugins/private_key_test.py index 64a81d6be..f8c4b3bd4 100644 --- a/tests/plugins/private_key_test.py +++ b/tests/plugins/private_key_test.py @@ -16,4 +16,7 @@ def test_analyze(self): ) f = create_file_object_from_string(file_content) - assert 'mock_filename' in logic.analyze(f, 'mock_filename') + output = logic.analyze(f, 'mock_filename') + assert len(output) == 1 + for potential_secret in output: + assert 'mock_filename' == potential_secret.filename From 1925cdb5b31bfd38b7037353f904698ff0193cd5 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 6 Apr 2018 14:49:15 -0700 Subject: [PATCH 2/2] [private key plugin] Update docstring of analyze --- detect_secrets/plugins/private_key.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/detect_secrets/plugins/private_key.py b/detect_secrets/plugins/private_key.py index 64a500e99..c79f3383d 100644 --- a/detect_secrets/plugins/private_key.py +++ b/detect_secrets/plugins/private_key.py @@ -25,11 +25,14 @@ class PrivateKeyDetector(BasePlugin): def analyze(self, file, filename): """We override this, because we're only looking at the first line. - Though this doesn't strictly follow the schema of the parent function, - all that really matters is that each secret within this file scanned - has a unique key. Since we're only expecting at most one secret from - this file, by definition any key is a unique key, so we good. + :param file: The File object itself. + :param filename: string; filename of File object, used for creating + PotentialSecret objects + :returns dictionary representation of set (for random access by hash) + { detect_secrets.core.potential_secret.__hash__: + detect_secrets.core.potential_secret } """ + return self.analyze_string( file.readline(), 1,