Skip to content

Commit dcd8091

Browse files
committed
Scan images using trivy
1 parent 4a8b107 commit dcd8091

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_all.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pytest_container import get_extra_run_args
1313
from pytest_container import MultiStageBuild
1414
from pytest_container.container import ContainerData
15+
from pytest_container.runtime import LOCALHOST
1516

1617
from bci_tester.data import ALL_CONTAINERS
1718
from bci_tester.data import BCI_REPO_NAME
@@ -24,6 +25,7 @@
2425
from bci_tester.data import PCP_CONTAINER
2526
from bci_tester.data import POSTGRESQL_CONTAINERS
2627
from bci_tester.data import TARGET
28+
from bci_tester.runtime_choice import DOCKER_SELECTED
2729

2830
CONTAINER_IMAGES = ALL_CONTAINERS
2931

@@ -260,6 +262,34 @@ def test_zypper_verify_passes(container_per_test: ContainerData) -> None:
260262
)
261263

262264

265+
@pytest.mark.skipif(
266+
DOCKER_SELECTED, reason="Trivy-Scan images only with podman"
267+
)
268+
@pytest.mark.skipif(
269+
(LOCALHOST.system_info.arch not in ("x86_64",)
270+
or OS_VERSION in ("15.3", "basalt", "tumbleweed")),
271+
reason=f"{LOCALHOST.system_info.arch} is not supported to run trivy",
272+
)
273+
def test_trivy_image_scan(host, auto_container: ContainerData) -> None:
274+
"""Check that trivy image is able to scan the container."""
275+
276+
trivy_container = "docker.io/aquasec/trivy:latest"
277+
baseurl = auto_container.container.baseurl
278+
if not baseurl:
279+
pytest.skip(
280+
reason=f"container {auto_container.container} has no baseurl"
281+
)
282+
283+
host.run_expect(
284+
[0],
285+
(
286+
f"podman run -v trivy:/root {trivy_container} image {baseurl} "
287+
"--scanners vuln --exit-code 1 --exit-on-eol 2 -f template "
288+
"--format sarif"
289+
),
290+
)
291+
292+
263293
@pytest.mark.parametrize(
264294
"container",
265295
[

0 commit comments

Comments
 (0)