Skip to content

Commit 9e7a0d4

Browse files
authored
fix(threat detection): run single threat detection check (#7065)
1 parent 9c33b3f commit 9e7a0d4

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

prowler/lib/check/checks_loader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def load_checks_to_execute(
111111
):
112112
checks_to_execute.add(check_name)
113113
# Only execute threat detection checks if threat-detection category is set
114-
if not categories or "threat-detection" not in categories:
114+
if (not categories or "threat-detection" not in categories) and not check_list:
115115
for threat_detection_check in check_categories.get("threat-detection", []):
116116
checks_to_execute.discard(threat_detection_check)
117117

tests/lib/check/check_loader_test.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,15 @@ def test_load_checks_to_execute_no_bulk_compliance_frameworks(self):
253253
bulk_checks_metatada = {
254254
S3_BUCKET_LEVEL_PUBLIC_ACCESS_BLOCK_NAME: self.get_custom_check_s3_metadata()
255255
}
256-
with patch(
257-
"prowler.lib.check.checks_loader.CheckMetadata.get_bulk",
258-
return_value=bulk_checks_metatada,
259-
), patch(
260-
"prowler.lib.check.checks_loader.Compliance.get_bulk",
261-
return_value=bulk_compliance_frameworks,
256+
with (
257+
patch(
258+
"prowler.lib.check.checks_loader.CheckMetadata.get_bulk",
259+
return_value=bulk_checks_metatada,
260+
),
261+
patch(
262+
"prowler.lib.check.checks_loader.Compliance.get_bulk",
263+
return_value=bulk_compliance_frameworks,
264+
),
262265
):
263266
assert {S3_BUCKET_LEVEL_PUBLIC_ACCESS_BLOCK_NAME} == load_checks_to_execute(
264267
compliance_frameworks=compliance_frameworks,
@@ -302,3 +305,17 @@ def test_discard_threat_detection_checks(self):
302305
categories=categories,
303306
provider=self.provider,
304307
)
308+
309+
def test_threat_detection_single_check(self):
310+
bulk_checks_metatada = {
311+
CLOUDTRAIL_THREAT_DETECTION_ENUMERATION_NAME: self.get_threat_detection_check_metadata()
312+
}
313+
categories = {}
314+
check_list = [CLOUDTRAIL_THREAT_DETECTION_ENUMERATION_NAME]
315+
316+
assert {CLOUDTRAIL_THREAT_DETECTION_ENUMERATION_NAME} == load_checks_to_execute(
317+
bulk_checks_metadata=bulk_checks_metatada,
318+
check_list=check_list,
319+
categories=categories,
320+
provider=self.provider,
321+
)

0 commit comments

Comments
 (0)