Skip to content

Commit 41910c8

Browse files
committed
Scan images using trivy
1 parent f770264 commit 41910c8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_all.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pytest_container import get_extra_run_args
1212
from pytest_container import MultiStageBuild
1313
from pytest_container.container import ContainerData
14+
from pytest_container.runtime import LOCALHOST
1415

1516
from bci_tester.data import ALL_CONTAINERS
1617
from bci_tester.data import BUSYBOX_CONTAINER
@@ -20,6 +21,7 @@
2021
from bci_tester.data import OS_VERSION
2122
from bci_tester.data import PCP_CONTAINER
2223
from bci_tester.data import POSTGRESQL_CONTAINERS
24+
from bci_tester.runtime_choice import DOCKER_SELECTED
2325

2426
CONTAINER_IMAGES = ALL_CONTAINERS
2527

@@ -170,6 +172,33 @@ def test_zypper_verify_passes(container_per_test: ContainerData) -> None:
170172
)
171173

172174

175+
@pytest.mark.skipif(
176+
DOCKER_SELECTED, reason="Trivy-Scan images only with podman"
177+
)
178+
@pytest.mark.skipif(
179+
LOCALHOST.system_info.arch not in ("x86_64",),
180+
reason=f"{LOCALHOST.system_info.arch} is not supported to run trivy",
181+
)
182+
def test_trivy_image_scan(host, auto_container: ContainerData) -> None:
183+
"""Check that trivy image is able to scan the container."""
184+
185+
trivy_container = "docker.io/aquasec/trivy:latest"
186+
baseurl = auto_container.container.baseurl
187+
if not baseurl:
188+
pytest.skip(
189+
reason=f"container {auto_container.container} has no baseurl"
190+
)
191+
192+
host.run_expect(
193+
[0],
194+
(
195+
f"podman run -v trivy:/root {trivy_container} image {baseurl} "
196+
"--exit-code 1 --exit-on-eol 2 -f template "
197+
"--template '@contrib/sarif.tpl'"
198+
),
199+
)
200+
201+
173202
@pytest.mark.parametrize(
174203
"container",
175204
[

0 commit comments

Comments
 (0)