Skip to content

Commit 2c3f72f

Browse files
committed
Add nodejs fips test
Add test that verifies that if: Container is in fips mode, node is also using fips mode. Container isnt in fips mode, node also isnt using fips mode.
1 parent f94a1ec commit 2c3f72f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/run

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ test_node_cmd_development_init_wrapper_true
6161
test_init_wrapper_false_development
6262
"
6363

64+
TEST_LIST_FIPS="\
65+
test_nodejs_fips_mode
66+
"
6467
source "${THISDIR}/test-lib.sh"
6568
source "${THISDIR}/test-lib-nodejs.sh"
6669

@@ -160,3 +163,12 @@ evaluate_build_result $? "proxy"
160163
TEST_SET=${TESTS:-$TEST_LIST_HW} ct_run_tests_from_testset "hw"
161164

162165
cleanup
166+
167+
echo "Testing fips mode"
168+
prepare app
169+
check_prep_result $? app || exit
170+
echo "Testing the production image build"
171+
run_s2i_build
172+
evaluate_build_result $? "default"
173+
174+
TEST_SET=${TESTS:-$TEST_LIST_FIPS} ct_run_tests_from_testset "fips"

test/test-lib-nodejs.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,29 @@ function test_nodemon_present() {
478478
ct_check_testcase_result "$?"
479479
}
480480

481+
function test_nodejs_fips_mode() {
482+
# Test that nodejs behaves as expected in fips mode
483+
local is_fips_enabled
484+
485+
# Read fips mode from host in case exists
486+
if [[ -f /proc/sys/crypto/fips_enabled ]]; then
487+
is_fips_enabled=$(cat /proc/sys/crypto/fips_enabled)
488+
else
489+
is_fips_enabled="0"
490+
fi
491+
if [[ "$is_fips_enabled" == "0" ]]; then
492+
# FIPS disabled -- crypto.getFips() should return 0
493+
echo "Fips should be disabled"
494+
docker run --rm ${IMAGE_NAME}-testapp /bin/bash -c "node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
495+
ct_check_testcase_result "$?"
496+
else
497+
# FIPS enabled -- crypto.getFips() should return 1
498+
echo "Fips should be enabled"
499+
docker run --rm ${IMAGE_NAME}-testapp /bin/bash -c "! node -e 'const crypto = require(\"crypto\"); process.exit(crypto.getFips());'"
500+
ct_check_testcase_result "$?"
501+
fi
502+
}
503+
481504
function test_npm_cache_cleared() {
482505
# Test that the npm cache has been cleared
483506
cache_loc=$(docker run --rm ${IMAGE_NAME}-testapp /bin/bash -c "npm config get cache")

0 commit comments

Comments
 (0)