|
5 | 5 | import json
|
6 | 6 | import logging
|
7 | 7 | import pathlib
|
| 8 | +import platform |
8 | 9 | import re
|
9 | 10 | import tempfile
|
10 | 11 | import textwrap
|
@@ -135,16 +136,24 @@ def test_oc_command_runs_fake_fips(self, image: str, subtests: pytest_subtests.S
|
135 | 136 | tmp_crypto.chmod(0o777)
|
136 | 137 |
|
137 | 138 | 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 | + |
139 | 147 | container.with_command("/bin/sh -c 'sleep infinity'")
|
140 | 148 |
|
141 | 149 | try:
|
142 | 150 | container.start()
|
143 | 151 |
|
144 | 152 | 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"]) |
146 | 155 | 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()}" |
148 | 157 |
|
149 | 158 | # 0: enabled, 1: partial success, 2: not enabled
|
150 | 159 | with subtests.test("/fips-mode-setup --is-enabled reports 1"):
|
|
0 commit comments