mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
@@ -173,9 +173,15 @@ class HTML(Output):
|
||||
<li class="list-group-item">
|
||||
<b>Passed:</b> {str(stats.get("total_pass", 0))}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Passed (Muted):</b> {str(stats.get("total_muted_pass", 0))}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Failed:</b> {str(stats.get("total_fail", 0))}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Failed (Muted):</b> {str(stats.get("total_muted_fail", 0))}
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Total Resources:</b> {str(stats.get("resources_count", 0))}
|
||||
</li>
|
||||
|
||||
@@ -91,6 +91,8 @@ def extract_findings_statistics(findings: list) -> dict:
|
||||
stats = {}
|
||||
total_pass = 0
|
||||
total_fail = 0
|
||||
muted_pass = 0
|
||||
muted_fail = 0
|
||||
resources = set()
|
||||
findings_count = 0
|
||||
all_fails_are_muted = True
|
||||
@@ -98,17 +100,25 @@ def extract_findings_statistics(findings: list) -> dict:
|
||||
for finding in findings:
|
||||
# Save the resource_id
|
||||
resources.add(finding.resource_id)
|
||||
|
||||
if finding.status == "PASS":
|
||||
total_pass += 1
|
||||
findings_count += 1
|
||||
if finding.muted is True:
|
||||
muted_pass += 1
|
||||
|
||||
if finding.status == "FAIL":
|
||||
total_fail += 1
|
||||
findings_count += 1
|
||||
if finding.muted is True:
|
||||
muted_fail += 1
|
||||
if not finding.muted and all_fails_are_muted:
|
||||
all_fails_are_muted = False
|
||||
|
||||
stats["total_pass"] = total_pass
|
||||
stats["total_muted_pass"] = muted_pass
|
||||
stats["total_fail"] = total_fail
|
||||
stats["total_muted_fail"] = muted_fail
|
||||
stats["resources_count"] = len(resources)
|
||||
stats["findings_count"] = findings_count
|
||||
stats["all_fails_are_muted"] = all_fails_are_muted
|
||||
|
||||
@@ -14,10 +14,12 @@ from tests.providers.kubernetes.kubernetes_fixtures import (
|
||||
)
|
||||
|
||||
html_stats = {
|
||||
"total_pass": 0,
|
||||
"total_fail": 1,
|
||||
"total_pass": 25,
|
||||
"total_muted_pass": 20,
|
||||
"total_fail": 5,
|
||||
"total_muted_fail": 5,
|
||||
"resources_count": 1,
|
||||
"findings_count": 1,
|
||||
"findings_count": 30,
|
||||
}
|
||||
pass_html_finding = """
|
||||
<tr class="p-3 mb-2 bg-success-custom">
|
||||
@@ -300,13 +302,19 @@ def get_aws_html_header(args: list) -> str:
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">
|
||||
<b>Total Findings:</b> 1
|
||||
<b>Total Findings:</b> 30
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Passed:</b> 0
|
||||
<b>Passed:</b> 25
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Failed:</b> 1
|
||||
<b>Passed (Muted):</b> 20
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Failed:</b> 5
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Failed (Muted):</b> 5
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<b>Total Resources:</b> 1
|
||||
|
||||
@@ -252,6 +252,8 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 1
|
||||
assert stats["total_fail"] == 1
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 2
|
||||
assert stats["findings_count"] == 2
|
||||
|
||||
@@ -267,6 +269,8 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 2
|
||||
assert stats["total_fail"] == 0
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 2
|
||||
|
||||
@@ -282,6 +286,8 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 1
|
||||
assert stats["total_fail"] == 0
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 1
|
||||
|
||||
@@ -291,6 +297,8 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 0
|
||||
assert stats["total_fail"] == 0
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 0
|
||||
assert stats["findings_count"] == 0
|
||||
|
||||
@@ -304,6 +312,8 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 0
|
||||
assert stats["total_fail"] == 1
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 1
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 1
|
||||
assert stats["all_fails_are_muted"]
|
||||
@@ -322,10 +332,46 @@ class TestOutputs:
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 0
|
||||
assert stats["total_fail"] == 2
|
||||
assert stats["total_muted_pass"] == 0
|
||||
assert stats["total_muted_fail"] == 1
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 2
|
||||
assert not stats["all_fails_are_muted"]
|
||||
|
||||
def test_extract_findings_statistics_all_passes_are_not_muted(self):
|
||||
finding_1 = mock.MagicMock()
|
||||
finding_1.status = "PASS"
|
||||
finding_1.muted = True
|
||||
finding_1.resource_id = "test_resource_1"
|
||||
finding_2 = mock.MagicMock()
|
||||
finding_2.status = "PASS"
|
||||
finding_2.muted = False
|
||||
finding_2.resource_id = "test_resource_1"
|
||||
findings = [finding_1, finding_2]
|
||||
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 2
|
||||
assert stats["total_fail"] == 0
|
||||
assert stats["total_muted_pass"] == 1
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 2
|
||||
|
||||
def test_extract_findings_statistics_all_passes_are_muted(self):
|
||||
finding_1 = mock.MagicMock()
|
||||
finding_1.status = "PASS"
|
||||
finding_1.muted = True
|
||||
finding_1.resource_id = "test_resource_1"
|
||||
findings = [finding_1]
|
||||
|
||||
stats = extract_findings_statistics(findings)
|
||||
assert stats["total_pass"] == 1
|
||||
assert stats["total_fail"] == 0
|
||||
assert stats["total_muted_pass"] == 1
|
||||
assert stats["total_muted_fail"] == 0
|
||||
assert stats["resources_count"] == 1
|
||||
assert stats["findings_count"] == 1
|
||||
|
||||
def test_report_with_aws_provider_not_muted_pass(self):
|
||||
# Mocking check_findings and provider
|
||||
finding_1 = MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user