add container names

This commit is contained in:
David Duran Rosich committed 2026-10-23 22:47:04 +02:00
1 parent f6e723a63e
commit 3003585a04
3 files changed
+93 -15

No files matched your search

+38
View File
@@ -274,6 +274,12 @@ class ImageListTests(unittest.TestCase):
self.assertEqual(
targets[0].container_suffix, " (used by containers web, web-worker)"
)
self.assertEqual(
targets[0].notification_context, " [containers: web, web-worker]"
)
self.assertEqual(
targets[0].container_detail, "Containers: web, web-worker"
)
def test_collect_targets_explicit_images_have_no_containers(self) -> None:
settings = scan.Settings(explicit_images=["nginx:1.27"])
@@ -381,6 +387,18 @@ class ReportTests(unittest.TestCase):
self.assertIn("CVE-5", body)
self.assertIn("no fix available", body)
def test_build_body_includes_container_detail(self) -> None:
result = scan.summarise(REPORT)
body = scan.build_body(
"nginx:1.27",
result,
"/reports/x.json",
max_findings=15,
container_detail="Containers: web, web-worker",
)
self.assertIn("Image: nginx:1.27", body)
self.assertIn("Containers: web, web-worker", body)
class TrivyCommandTests(unittest.TestCase):
def test_run_trivy_passes_vex_sources_in_order(self) -> None:
@@ -503,6 +521,26 @@ printf '%s\\n' "$*" >> "$APPRISE_LOG"
"Scanning testphp-php (used by container testphp)", stderr.getvalue()
)
def test_notification_includes_container(self) -> None:
containers = [container("a" * 64, "testphp-php", name="testphp")]
with FakeDocker(containers) as docker:
code = self.run_main([], docker.socket_path)
self.assertEqual(code, 1)
notification = Path(self.apprise_log).read_text()
self.assertIn("[container: testphp]", notification)
self.assertIn("Container: testphp", notification)
def test_scan_failure_notification_includes_container(self) -> None:
containers = [container("a" * 64, "testphp-php", name="testphp")]
with FakeDocker(containers) as docker:
code = self.run_main([], docker.socket_path, FAKE_TRIVY_FAIL="1")
self.assertEqual(code, 2)
notification = Path(self.apprise_log).read_text()
self.assertIn("Scan failed: testphp-php [container: testphp]", notification)
self.assertIn("Container: testphp", notification)
def test_exit_code_zero_when_policy_does_not_fail(self) -> None:
with FakeDocker([container("a" * 64, "testphp-php")]) as docker:
code = self.run_main([], docker.socket_path, FAIL_ON="NONE", NOTIFY_MIN_SEVERITY="NONE")