Skip to content

Commit d9f9c28

Browse files
committed
Add support for running FIPS aplication only for FIPS enabled host.
Couple test fixes caught by testing on RHEL9 host. Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 3cb876b commit d9f9c28

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

test/run

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ test_init_wrapper_false_development
6363

6464
TEST_LIST_FIPS="\
6565
test_nodejs_fips_mode
66+
test_run_fips_app_application
6667
"
6768
source "${THISDIR}/test-lib.sh"
6869
source "${THISDIR}/test-lib-nodejs.sh"
@@ -167,8 +168,8 @@ cleanup
167168
echo "Testing fips mode"
168169
prepare fips
169170
check_prep_result $? fips || exit
170-
echo "Testing the production image build"
171-
run_s2i_fips
171+
echo "Testing the production image build for fips"
172+
run_s2i_build_fips
172173
evaluate_build_result $? "default"
173174

174175
TEST_SET=${TESTS:-$TEST_LIST_FIPS} ct_run_tests_from_testset "fips"

test/test-lib-nodejs.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ run_s2i_build() {
4545
ct_s2i_build_as_df file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp ${s2i_args} $(ct_build_s2i_npm_variables) $1
4646
}
4747

48-
run_s2i_fips() {
49-
ct_s2i_build_as_df file://${test_dir}/test-fips${IMAGE_NAME} ${IMAGE_NAME}-testfips ${s2i_args} $(ct_build_s2i_npm_variables) $1
48+
run_s2i_build_fips() {
49+
ct_s2i_build_as_df file://${test_dir}/test-fips ${IMAGE_NAME} ${IMAGE_NAME}-testfips ${s2i_args} $(ct_build_s2i_npm_variables) $1
5050
}
5151

5252
run_s2i_build_proxy() {
@@ -157,7 +157,7 @@ prepare() {
157157

158158
run_test_application() {
159159
case "$1" in
160-
app|hw|express-webapp|binary)
160+
app|fips|hw|express-webapp|binary)
161161
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix=.cid)
162162
docker run -d --user=100001 $(ct_mount_ca_file) --rm --cidfile=${cid_file} $2 ${IMAGE_NAME}-test$1
163163
;;
@@ -170,7 +170,7 @@ run_test_application() {
170170

171171
run_test_application_with_quoted_args() {
172172
case "$1" in
173-
app | hw | express-webapp | binary)
173+
app | fips | hw | express-webapp | binary)
174174
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix=.cid)
175175
docker run -d --user=100001 $(ct_mount_ca_file) --rm --cidfile=${cid_file} "$2" ${IMAGE_NAME}-test$1
176176
;;
@@ -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}-testapp /bin/bash -c "node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
498+
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
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}-testapp /bin/bash -c "! node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
503+
docker run --rm ${IMAGE_NAME}-testfips /bin/bash -c "! node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
504504
ct_check_testcase_result "$?"
505505
fi
506506
}
@@ -575,6 +575,25 @@ function test_run_app_application() {
575575
wait_for_cid
576576
}
577577

578+
function test_run_fips_app_application() {
579+
local is_fips_enabled
580+
581+
# Read fips mode from host in case exists
582+
if [[ -f /proc/sys/crypto/fips_enabled ]]; then
583+
is_fips_enabled=$(cat /proc/sys/crypto/fips_enabled)
584+
else
585+
is_fips_enabled="0"
586+
fi
587+
if [[ "$is_fips_enabled" == "1" ]]; then
588+
# Verify that the HTTP connection can be established to test application container
589+
run_test_application fips
590+
# Wait for the container to write it's CID file
591+
wait_for_cid
592+
ct_check_testcase_result $?
593+
kill_test_application
594+
fi
595+
}
596+
578597
function test_run_hw_application() {
579598
# Verify that the HTTP connection can be established to test application container
580599
run_test_application hw

0 commit comments

Comments
 (0)