From d8503549f7f542d74da591f1c9129553a63ce213 Mon Sep 17 00:00:00 2001 From: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com> Date: Wed, 11 Nov 2020 15:55:39 +0100 Subject: [PATCH 1/4] Azure Storage Key Detector pligin Co-authored-by: Dariusz Porowski --- detect_secrets/plugins/azure_storage_key.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 detect_secrets/plugins/azure_storage_key.py diff --git a/detect_secrets/plugins/azure_storage_key.py b/detect_secrets/plugins/azure_storage_key.py new file mode 100644 index 000000000..505bf9e4a --- /dev/null +++ b/detect_secrets/plugins/azure_storage_key.py @@ -0,0 +1,16 @@ +""" +This plugin searches for Azure Storage Account access keys. +""" +import re + +from detect_secrets.plugins.base import RegexBasedDetector + + +class AzureStorageKeyDetector(RegexBasedDetector): + """Scans for Azure Storage Account access keys.""" + secret_type = 'Azure Storage Account access key' + + denylist = [ + # Account Key (AccountKey=xxxxxxxxx) + re.compile(r'AccountKey=[a-zA-Z0-9+\/=]{88}') + ] From 4d7821b4042f0ed92cde3a89da69f6b648144a69 Mon Sep 17 00:00:00 2001 From: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com> Date: Wed, 11 Nov 2020 16:05:49 +0100 Subject: [PATCH 2/4] AzureStorageKeyDetector tests Co-authored-by: Dariusz Porowski --- tests/plugins/azure_storage_key_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/plugins/azure_storage_key_test.py diff --git a/tests/plugins/azure_storage_key_test.py b/tests/plugins/azure_storage_key_test.py new file mode 100644 index 000000000..aa6f8be5b --- /dev/null +++ b/tests/plugins/azure_storage_key_test.py @@ -0,0 +1,20 @@ +import pytest + +from detect_secrets.plugins.azure_storage_key import AzureStorageKeyDetector + + +class AzureStorageKeyDetector: + + @pytest.mark.parametrize( + 'payload, should_flag', + [ + ( + 'AccountKey=lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==', + True, + ), + ], + ) + def test_analyze(self, payload, should_flag): + logic = AzureStorageKeyDetector() + output = logic.analyze_line(payload, 1, 'mock_filename') + assert output From a9c13f5599134ac776f1073cbd19519fe32d0290 Mon Sep 17 00:00:00 2001 From: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com> Date: Wed, 11 Nov 2020 17:39:56 +0100 Subject: [PATCH 3/4] Feedback fixes Co-authored-by: Dariusz Porowski --- detect_secrets/plugins/azure_storage_key.py | 2 +- tests/plugins/azure_storage_key_test.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/detect_secrets/plugins/azure_storage_key.py b/detect_secrets/plugins/azure_storage_key.py index 505bf9e4a..a04dff58a 100644 --- a/detect_secrets/plugins/azure_storage_key.py +++ b/detect_secrets/plugins/azure_storage_key.py @@ -12,5 +12,5 @@ class AzureStorageKeyDetector(RegexBasedDetector): denylist = [ # Account Key (AccountKey=xxxxxxxxx) - re.compile(r'AccountKey=[a-zA-Z0-9+\/=]{88}') + re.compile(r'AccountKey=[a-zA-Z0-9+\/=]{88}'), ] diff --git a/tests/plugins/azure_storage_key_test.py b/tests/plugins/azure_storage_key_test.py index aa6f8be5b..9a3a2a74a 100644 --- a/tests/plugins/azure_storage_key_test.py +++ b/tests/plugins/azure_storage_key_test.py @@ -3,7 +3,7 @@ from detect_secrets.plugins.azure_storage_key import AzureStorageKeyDetector -class AzureStorageKeyDetector: +class TestAzureStorageKeyDetector: @pytest.mark.parametrize( 'payload, should_flag', @@ -16,5 +16,4 @@ class AzureStorageKeyDetector: ) def test_analyze(self, payload, should_flag): logic = AzureStorageKeyDetector() - output = logic.analyze_line(payload, 1, 'mock_filename') - assert output + assert logic.analyze_line(filename='mock_filename', line=payload) From fa4eb9cb243f3db8a76c611de089fca052293946 Mon Sep 17 00:00:00 2001 From: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com> Date: Thu, 12 Nov 2020 11:33:46 +0100 Subject: [PATCH 4/4] E501 fix Co-authored-by: Dariusz Porowski --- tests/plugins/azure_storage_key_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/azure_storage_key_test.py b/tests/plugins/azure_storage_key_test.py index 9a3a2a74a..f0b47b27c 100644 --- a/tests/plugins/azure_storage_key_test.py +++ b/tests/plugins/azure_storage_key_test.py @@ -9,7 +9,7 @@ class TestAzureStorageKeyDetector: 'payload, should_flag', [ ( - 'AccountKey=lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==', + 'AccountKey=lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==', # noqa: E501 True, ), ],