Skip to content

Commit

Permalink
feat(secrets): bump bc-detect-secrets to version 1.5.4 (#5998)
Browse files Browse the repository at this point in the history
* Updated bc-detect-secrets to version 1.5.4

* Filter only relevant checks for test

* Solve issue with pipenv-setup
  • Loading branch information
bo156 committed Feb 5, 2024
1 parent 0d72873 commit 993a0dc
Show file tree
Hide file tree
Showing 7 changed files with 571 additions and 569 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
args: []
additional_dependencies:
- vistir<0.7.0 # can be removed, when v4.0.0 of pipenv-setup comes out
- plette<1.0.0 # Solve issue of import error for plette.models
- repo: https://github.com/seddonym/import-linter # checks the import dependencies between each other
rev: v1.12.1
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ types-colorama = "<0.5.0,>=0.4.3"
# REMINDER: Update "install_requires" deps on setup.py when changing
#
bc-python-hcl2 = "==0.4.2"
bc-detect-secrets = "==1.4.30"
bc-detect-secrets = "==1.5.4"
bc-jsonpath-ng = "==1.6.1"
pycep-parser = "==0.4.1"
tabulate = ">=0.9.0,<0.10.0"
Expand Down
1,095 changes: 538 additions & 557 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(self) -> None:
},
install_requires=[
"bc-python-hcl2==0.4.2",
"bc-detect-secrets==1.4.30",
"bc-detect-secrets==1.5.4",
"bc-jsonpath-ng==1.6.1",
"pycep-parser==0.4.1",
"tabulate>=0.9.0,<0.10.0",
Expand Down
27 changes: 18 additions & 9 deletions tests/secrets/test_load_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from checkov.runner_filter import RunnerFilter
from checkov.secrets.plugins.load_detectors import modify_secrets_policy_to_detectors, get_runnable_plugins
from checkov.secrets.runner import Runner
from tests.secrets.utils_for_test import _filter_reports_for_incident_ids


class TestLoadDetectors(unittest.TestCase):
Expand Down Expand Up @@ -237,7 +238,8 @@ def test_custom_regex_detector(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 3)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 3)

def test_non_entropy_take_precedence_over_entropy(self):
# given: File with entropy secret and custom secret
Expand Down Expand Up @@ -283,8 +285,9 @@ def test_non_entropy_take_precedence_over_entropy(self):
report = runner.run(root_folder=valid_dir_path, runner_filter=RunnerFilter(framework=['secrets'], enable_secret_scan_all_files=True))

# then: Validating that the non-entropy is the one.
self.assertEqual(len(report.failed_checks), 1)
self.assertEqual(report.failed_checks[0].check_id, check_id)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1"])
self.assertEqual(len(interesting_failed_checks), 1)
self.assertEqual(interesting_failed_checks[0].check_id, check_id)

def test_custom_regex_detector_value_str(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -357,7 +360,8 @@ def test_custom_regex_detector_value_str(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 3)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 3)

def test_custom_regex_detector_in_custom_limit_characters(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -399,7 +403,8 @@ def test_custom_regex_detector_in_custom_limit_characters(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 1)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 1)

def test_custom_regex_detector_out_custom_limit_characters(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -441,7 +446,8 @@ def test_custom_regex_detector_out_custom_limit_characters(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 0)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 0)

def test_custom_regex_detector_skip_long_line(self):
# given
Expand Down Expand Up @@ -662,7 +668,8 @@ def test_custom_multiline_regex_detector(self):
runner_filter=RunnerFilter(
framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 3)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 3)

def test_custom_multiline_regex_detector_only_scan_file(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -727,7 +734,8 @@ def test_custom_multiline_regex_detector_only_scan_file(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 2)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 2)

def test_custom_multiline_regex_detector_only_supported_files(self):
current_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -792,4 +800,5 @@ def test_custom_multiline_regex_detector_only_supported_files(self):
report = runner.run(root_folder=valid_dir_path,
runner_filter=RunnerFilter(framework=['secrets'],
enable_secret_scan_all_files=True))
self.assertEqual(len(report.failed_checks), 1)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks, ["test1", "test2"])
self.assertEqual(len(interesting_failed_checks), 1)
5 changes: 4 additions & 1 deletion tests/secrets/test_plugin_multiline_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from checkov.secrets.plugins.entropy_keyword_combinator import REGEX_VALUE_KEYWORD_BY_FILETYPE
from checkov.secrets.plugins.entropy_keyword_combinator import REGEX_VALUE_SECRET_BY_FILETYPE
from checkov.secrets.runner import Runner
from tests.secrets.utils_for_test import _filter_reports_for_incident_ids


class TestCombinatorPluginMultilineYml(unittest.TestCase):
Expand Down Expand Up @@ -182,7 +183,9 @@ def test_non_multiline_pair_time_limit_creating_report(self):

# then
assert end_time-start_time < 1 # assert the time limit is not too long for parsing long lines.
self.assertEqual(len(report.failed_checks), 4)
interesting_failed_checks = _filter_reports_for_incident_ids(report.failed_checks,
["CKV_SECRET_4", "CKV_SECRET_6", "CKV_SECRET_13"])
self.assertEqual(len(interesting_failed_checks), 4)
self.assertEqual(report.parsing_errors, [])
self.assertEqual(report.passed_checks, [])
self.assertEqual(report.skipped_checks, [])
Expand Down
8 changes: 8 additions & 0 deletions tests/secrets/utils_for_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import List

from checkov.common.output.record import Record


def _filter_reports_for_incident_ids(failed_checks: List[Record], policy_names: List[str]) \
-> List[Record]:
return [failed_check for failed_check in failed_checks if failed_check.check_id in policy_names]

0 comments on commit 993a0dc

Please sign in to comment.