Skip to content

Commit aaebd06

Browse files
committed
Add support for testing a fips app.
1 parent 92d40c3 commit aaebd06

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

test/test-lib-ruby.sh

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ function ct_pull_or_import_postgresql() {
2929
fi
3030
}
3131

32+
# "0" if system is not FIPS enabled, "1" if it is.
33+
function fips_enabled() {
34+
local is_fips_enabled
35+
36+
# Read fips mode from host in case exists
37+
if [[ -f /proc/sys/crypto/fips_enabled ]]; then
38+
is_fips_enabled=$(cat /proc/sys/crypto/fips_enabled)
39+
else
40+
is_fips_enabled="0"
41+
fi
42+
43+
return "$is_fips_enabled"
44+
}
45+
3246
function rails_ex_branch() {
3347
# Ruby 3.3 introduced too many incompatibilities to be able
3448
# to use the same Gemfile for RHEL 7 and also newer RHELs.
@@ -46,14 +60,39 @@ function rails_ex_branch() {
4660
echo "$rails_example_repo_branch"
4761
}
4862

49-
function test_ruby_fips_mode() {
50-
local is_fips_enabled="0"
63+
run_s2i_build_fips() {
64+
ct_s2i_build_as_df file://${test_dir}/test-fips ${IMAGE_NAME} ${IMAGE_NAME}-testfips ${s2i_args} $1
65+
}
5166

52-
if [[ -f /proc/sys/crypto/fips_enabled ]]; then
53-
is_fips_enabled=$(cat /proc/sys/crypto/fips_enabled)
54-
fi
67+
function run_test_application() {
68+
case "$1" in
69+
fips)
70+
cid_file=$CID_FILE_DIR/$(mktemp -u -p . --suffix=.cid)
71+
docker run -d --user=100001 $(ct_mount_ca_file) --rm --cidfile=${cid_file} $2 ${IMAGE_NAME}-test$1
72+
;;
73+
*)
74+
echo "No such test application"
75+
return 1
76+
;;
77+
esac
78+
}
79+
80+
function test_run_fips_app() {
81+
# Verify that the HTTP connection can be established to test application container
82+
run_test_application fips
83+
# Wait for the container to write it's CID file
84+
wait_for_cid
85+
ct_test_response "http://localhost:4567/symmetric/aes-256-cbc" 200 ""
86+
ct_test_response "http://localhost:4567/symmetric/des-ede-cbc" 200 ""
87+
ct_test_response "http://localhost:4567/symmetric/sha256" 200 ""
88+
ct_test_response "http://localhost:4567/symmetric/md5" 200 ""
89+
curl "http://localhost:4567/"
90+
ct_check_testcase_result $?
91+
kill_test_application
92+
}
5593

56-
if [[ "$is_fips_enabled" == "0" ]]; then
94+
function test_ruby_fips_mode() {
95+
if [[ "$(fips_enabled)" == "0" ]]; then
5796
# FIPS disabled -> OpenSSL#fips_enabled returns false
5897
echo "Fips should be disabled"
5998
docker run --rm "$IMAGE_NAME" /bin/bash -c 'ruby -ropenssl -e "exit !OpenSSL.fips_enabled"'

0 commit comments

Comments
 (0)