From 21e8502e60465f5b5e1e7966cab9053945040ba5 Mon Sep 17 00:00:00 2001 From: Izhak Jakov Date: Thu, 31 Aug 2023 15:43:44 -0400 Subject: [PATCH 1/4] Indent JSONs with tabs instead of spaces Signed-off-by: Izhak Jakov --- detect_secrets/core/audit.py | 2 +- detect_secrets/core/baseline.py | 2 +- detect_secrets/core/report/output.py | 2 +- detect_secrets/core/secrets_collection.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/detect_secrets/core/audit.py b/detect_secrets/core/audit.py index 6146a3326..daa5987a8 100644 --- a/detect_secrets/core/audit.py +++ b/detect_secrets/core/audit.py @@ -331,7 +331,7 @@ def print_audit_results(baseline_filename): baseline, baseline_filename, ), - indent=2, + indent='\t', sort_keys=True, ), ) diff --git a/detect_secrets/core/baseline.py b/detect_secrets/core/baseline.py index 41692f266..04c867503 100644 --- a/detect_secrets/core/baseline.py +++ b/detect_secrets/core/baseline.py @@ -340,7 +340,7 @@ def format_baseline_for_output(baseline): return json.dumps( baseline, - indent=2, + indent='\t', sort_keys=True, separators=(',', ': '), ) diff --git a/detect_secrets/core/report/output.py b/detect_secrets/core/report/output.py index a3abcba06..4a8b1a8b9 100644 --- a/detect_secrets/core/report/output.py +++ b/detect_secrets/core/report/output.py @@ -70,7 +70,7 @@ def print_json_report( if fail_on_audited_real: secrets += audited_real_secrets - print(json.dumps({'stats': stats, 'secrets': secrets}, indent=4)) + print(json.dumps({'stats': stats, 'secrets': secrets}, indent='\t')) def print_table_report( diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index d3948c647..bcc8c0f7e 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -479,7 +479,7 @@ def json(self): def __str__(self): # pragma: no cover return json.dumps( self.json(), - indent=2, + indent='\t', sort_keys=True, ) From af74c783e044ed8b07661a1e0b4beea712c2408d Mon Sep 17 00:00:00 2001 From: Izhak Jakov Date: Thu, 31 Aug 2023 15:54:00 -0400 Subject: [PATCH 2/4] Update test for PR Signed-off-by: Izhak Jakov --- tests/pre_commit_hook_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pre_commit_hook_test.py b/tests/pre_commit_hook_test.py index bbe873504..3e79c953c 100644 --- a/tests/pre_commit_hook_test.py +++ b/tests/pre_commit_hook_test.py @@ -338,7 +338,7 @@ def _create_old_baseline(has_result=True, use_private_key_scan=True): baseline['exclude_regex'] = '' return json.dumps( baseline, - indent=2, + indent='\t', sort_keys=True, ) @@ -359,7 +359,7 @@ def _create_baseline(has_result=True, use_private_key_scan=True, audited=True, v } return json.dumps( baseline, - indent=2, + indent='\t', sort_keys=True, ) From 89507154b680065d428d967f4d0196e331f6b183 Mon Sep 17 00:00:00 2001 From: Izhak Jakov Date: Thu, 31 Aug 2023 16:40:07 -0400 Subject: [PATCH 3/4] Testing test json samples Signed-off-by: Izhak Jakov --- tests/core/report/output_test.py | 66 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/core/report/output_test.py b/tests/core/report/output_test.py index 6a433dff9..a38256ba1 100644 --- a/tests/core/report/output_test.py +++ b/tests/core/report/output_test.py @@ -641,13 +641,13 @@ def test_print_json_report_no_failed_conditions( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "live": 0, - "unaudited": 0, - "audited_real": 0 - }, - "secrets": [] + "stats": { + "reviewed": 3, + "live": 0, + "unaudited": 0, + "audited_real": 0 + }, + "secrets": [] }\n""" ) @@ -674,32 +674,32 @@ def test_print_json_report_failed_conditions( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "live": 1, - "unaudited": 1, - "audited_real": 1 - }, - "secrets": [ - { - "failed_condition": "Live", - "filename": "will_be_mocked", - "line": 90, - "type": "Private key" - }, - { - "failed_condition": "Unaudited", - "filename": "will_be_mocked", - "line": 120, - "type": "Hex High Entropy String" - }, - { - "failed_condition": "Audited as real", - "filename": "will_be_mocked", - "line": 60, - "type": "Hex High Entropy String" - } - ] + "stats": { + "reviewed": 3, + "live": 1, + "unaudited": 1, + "audited_real": 1 + }, + "secrets": [ + { + "failed_condition": "Live", + "filename": "will_be_mocked", + "line": 90, + "type": "Private key" + }, + { + "failed_condition": "Unaudited", + "filename": "will_be_mocked", + "line": 120, + "type": "Hex High Entropy String" + }, + { + "failed_condition": "Audited as real", + "filename": "will_be_mocked", + "line": 60, + "type": "Hex High Entropy String" + } + ] }\n""" ) From 6896d918bffcdeb3130b00ca9ffcc2be0cf8e3f7 Mon Sep 17 00:00:00 2001 From: Izhak Jakov Date: Thu, 31 Aug 2023 17:39:27 -0400 Subject: [PATCH 4/4] Testing test rest of json samples Signed-off-by: Izhak Jakov --- tests/core/report/output_test.py | 138 +++++++++++++++---------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/tests/core/report/output_test.py b/tests/core/report/output_test.py index a38256ba1..e63916008 100644 --- a/tests/core/report/output_test.py +++ b/tests/core/report/output_test.py @@ -641,13 +641,13 @@ def test_print_json_report_no_failed_conditions( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "live": 0, - "unaudited": 0, - "audited_real": 0 - }, - "secrets": [] +\t"stats": { +\t\t"reviewed": 3, +\t\t"live": 0, +\t\t"unaudited": 0, +\t\t"audited_real": 0 +\t}, +\t"secrets": [] }\n""" ) @@ -674,32 +674,32 @@ def test_print_json_report_failed_conditions( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "live": 1, - "unaudited": 1, - "audited_real": 1 - }, - "secrets": [ - { - "failed_condition": "Live", - "filename": "will_be_mocked", - "line": 90, - "type": "Private key" - }, - { - "failed_condition": "Unaudited", - "filename": "will_be_mocked", - "line": 120, - "type": "Hex High Entropy String" - }, - { - "failed_condition": "Audited as real", - "filename": "will_be_mocked", - "line": 60, - "type": "Hex High Entropy String" - } - ] +\t"stats": { +\t\t"reviewed": 3, +\t\t"live": 1, +\t\t"unaudited": 1, +\t\t"audited_real": 1 +\t}, +\t"secrets": [ +\t\t{ +\t\t\t"failed_condition": "Live", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 90, +\t\t\t"type": "Private key" +\t\t}, +\t\t{ +\t\t\t"failed_condition": "Unaudited", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 120, +\t\t\t"type": "Hex High Entropy String" +\t\t}, +\t\t{ +\t\t\t"failed_condition": "Audited as real", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 60, +\t\t\t"type": "Hex High Entropy String" +\t\t} +\t] }\n""" ) @@ -722,18 +722,18 @@ def test_print_json_report_only_live( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "live": 1 - }, - "secrets": [ - { - "failed_condition": "Live", - "filename": "will_be_mocked", - "line": 90, - "type": "Private key" - } - ] +\t"stats": { +\t\t"reviewed": 3, +\t\t"live": 1 +\t}, +\t"secrets": [ +\t\t{ +\t\t\t"failed_condition": "Live", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 90, +\t\t\t"type": "Private key" +\t\t} +\t] }\n""" ) @@ -756,18 +756,18 @@ def test_print_json_report_only_unaudited( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "unaudited": 1 - }, - "secrets": [ - { - "failed_condition": "Unaudited", - "filename": "will_be_mocked", - "line": 120, - "type": "Hex High Entropy String" - } - ] +\t"stats": { +\t\t"reviewed": 3, +\t\t"unaudited": 1 +\t}, +\t"secrets": [ +\t\t{ +\t\t\t"failed_condition": "Unaudited", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 120, +\t\t\t"type": "Hex High Entropy String" +\t\t} +\t] }\n""" ) @@ -790,18 +790,18 @@ def test_print_json_report_only_audited_true( assert ( captured.out == """{ - "stats": { - "reviewed": 3, - "audited_real": 1 - }, - "secrets": [ - { - "failed_condition": "Audited as real", - "filename": "will_be_mocked", - "line": 60, - "type": "Hex High Entropy String" - } - ] +\t"stats": { +\t\t"reviewed": 3, +\t\t"audited_real": 1 +\t}, +\t"secrets": [ +\t\t{ +\t\t\t"failed_condition": "Audited as real", +\t\t\t"filename": "will_be_mocked", +\t\t\t"line": 60, +\t\t\t"type": "Hex High Entropy String" +\t\t} +\t] }\n""" )