Skip to content

Commit ff398da

Browse files
Merge pull request #891 from jiridanek/jd_rootless_podman
NO-ISSUE: chore(tests/containers): fix fake fips tests for macOS rootless podman machine
2 parents c896084 + 4da2441 commit ff398da

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/containers/base_image_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import logging
77
import pathlib
8+
import platform
89
import re
910
import tempfile
1011
import textwrap
@@ -135,16 +136,24 @@ def test_oc_command_runs_fake_fips(self, image: str, subtests: pytest_subtests.S
135136
tmp_crypto.chmod(0o777)
136137

137138
container = testcontainers.core.container.DockerContainer(image=image, user=54321, group_add=[0])
138-
container.with_volume_mapping(str(tmp_crypto), "/proc/sys", mode="ro,z")
139+
140+
# if /proc/sys/crypto/fips_enabled exists, only replace this file,
141+
# otherwise (Ubuntu case), assume entire /proc/sys/crypto does not exist
142+
if platform.system().lower() == "darwin" or pathlib.Path("/proc/sys/crypto/fips_enabled").exists():
143+
container.with_volume_mapping(str(tmp_crypto / 'crypto' / 'fips_enabled'), "/proc/sys/crypto/fips_enabled", mode="ro,z")
144+
else:
145+
container.with_volume_mapping(str(tmp_crypto), "/proc/sys", mode="ro,z")
146+
139147
container.with_command("/bin/sh -c 'sleep infinity'")
140148

141149
try:
142150
container.start()
143151

144152
with subtests.test("/proc/sys/crypto/fips_enabled is 1"):
145-
ecode, output = container.exec(["/bin/sh", "-c", "sysctl crypto.fips_enabled"])
153+
# sysctl here works too, but it may not be present in image
154+
ecode, output = container.exec(["/bin/sh", "-c", "cat /proc/sys/crypto/fips_enabled"])
146155
assert ecode == 0, output.decode()
147-
assert "crypto.fips_enabled = 1\n" == output.decode(), output.decode()
156+
assert "1\n" == output.decode(), f"Unexpected crypto/fips_enabled content: {output.decode()}"
148157

149158
# 0: enabled, 1: partial success, 2: not enabled
150159
with subtests.test("/fips-mode-setup --is-enabled reports 1"):

0 commit comments

Comments
 (0)