Skip to content

Commit 318cd45

Browse files
committed
Fix FIPS mode. Move the functionality to test-fips directory
as test.js file Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 3f3c62d commit 318cd45

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

test/test-fips/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const crypto = require('crypto');
2+
3+
process.exit(crypto.getFips());

test/test-lib-nodejs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,12 @@ function test_nodejs_fips_mode() {
495495
if [[ "$is_fips_enabled" == "0" ]]; then
496496
# FIPS disabled -- crypto.getFips() should return 0
497497
echo "Fips should be disabled"
498-
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
498+
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "node test.js"
499499
ct_check_testcase_result "$?"
500500
else
501501
# FIPS enabled -- crypto.getFips() should return 1
502502
echo "Fips should be enabled"
503-
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "! node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
503+
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "! node test.js"
504504
ct_check_testcase_result "$?"
505505
fi
506506
}

test/test_container_basics.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
from doctest import debug
2+
13
import pytest
24

5+
from pathlib import Path
6+
37
from container_ci_suite.container_lib import ContainerTestLib, PodmanCLIWrapper
8+
from container_ci_suite.utils import get_file_content
49

510
from conftest import VARS
611

12+
test_fips = VARS.TEST_DIR / "test-fips"
13+
14+
15+
def build_s2i_app(app_path: Path) -> ContainerTestLib:
16+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
17+
app_name = app_path.name
18+
s2i_app = container_lib.build_as_df(
19+
app_path=app_path,
20+
s2i_args=f"--pull-policy=never {container_lib.build_s2i_npm_variables()}",
21+
src_image=VARS.IMAGE_NAME,
22+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}"
23+
)
24+
return s2i_app
25+
726

827
class TestNodeJSAppContainer:
928

@@ -55,3 +74,45 @@ def test_dockerfiles(self, dockerfile):
5574
url=cip,
5675
expected_output="Node.js Crud Application"
5776
)
77+
78+
79+
class TestNodeJSFipsContainer:
80+
def setup_method(self):
81+
self.s2i_fips = build_s2i_app(test_fips)
82+
83+
def teardown_method(self):
84+
self.s2i_fips.cleanup()
85+
86+
def test_nodejs_fips_mode(self):
87+
if VARS.OS == "rhel8":
88+
pytest.skip("Do not execute on RHEL8")
89+
is_fips_enabled = 0
90+
fips_enabled_file = Path("/proc/sys/crypto/fips_enabled")
91+
if fips_enabled_file.exists():
92+
is_fips_enabled = int(get_file_content(fips_enabled_file))
93+
if is_fips_enabled == 1:
94+
fips_result = PodmanCLIWrapper.podman_run_command_and_remove(
95+
cid_file_name=f"{VARS.IMAGE_NAME}-{self.s2i_fips.app_name}",
96+
cmd="node test.js",
97+
return_output=False,
98+
)
99+
assert fips_result == 1
100+
else:
101+
fips_mode = PodmanCLIWrapper.podman_run_command_and_remove(
102+
cid_file_name=f"{VARS.IMAGE_NAME}-{self.s2i_fips.app_name}",
103+
cmd="node test.js",
104+
return_output=False,
105+
)
106+
assert fips_mode == 0
107+
108+
def test_run_fips_app_application(self):
109+
is_fips_enabled = 0
110+
fips_enabled_file = Path("/proc/sys/crypto/fips_enabled")
111+
if fips_enabled_file.exists():
112+
is_fips_enabled = int(get_file_content(fips_enabled_file))
113+
if is_fips_enabled == 1:
114+
assert self.s2i_fips.create_container(
115+
cid_file_name=self.s2i_fips.app_name,
116+
container_args="--user 100001"
117+
)
118+
assert self.s2i_fips.get_cid(cid_file_name=self.s2i_fips.app_name)

0 commit comments

Comments
 (0)