Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: tls test without sleep #319

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 43 additions & 44 deletions tests/ttls
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@

source "${TESTSSRCDIR}/helpers.sh"

SLEEP=0.5
# with valgrind/asan, it might take a bit longer
if [ -n "$CHECKER" ]; then
SLEEP=10
fi

title PARA "Test SSL_CTX creation"
$CHECKER ./tlsctx

title PARA "Test an actual TLS connection"
rm -f "${TMPPDIR}/s_server_input"
rm -f "${TMPPDIR}/s_server_output"

# Set up command fifo
mkfifo "${TMPPDIR}/s_server_input"
exec 3<>"${TMPPDIR}/s_server_input"
rm -f "${TMPPDIR}/s_server_output"
rm -f "${TMPPDIR}/s_server_ready"
mkfifo "${TMPPDIR}/s_server_ready"

SERVER_PID=-1
# Make sure we terminate programs if test fails in the middle
# shellcheck disable=SC2317 # Shellcheck for some reason does not follow trap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this comment before the trap function to avoid the shellcheck failure.

kill_children_print() {
kill_children
wait_for_server_at_exit() {
wait "$1"
echo "Server output:"
cat "${TMPPDIR}/s_server_output"
}
trap kill_children_print EXIT
PORT=23456
$CHECKER openssl s_server -accept "${PORT}" -key "${PRIURI}" -cert "${CRTURI}" <&3 &

sleep $SLEEP

# The client will error when the server drops the connection
set +e
$CHECKER openssl s_client -connect "localhost:${PORT}" -quiet > "${TMPPDIR}/s_server_output" &
set -e

# Wait to make sure client is connected
sleep $SLEEP
trap 'wait_for_server_at_exit $SERVER_PID;' EXIT

# Send command to the client
echo " TLS SUCCESSFUL " >&3

# s_server seem to be confused if Q comes in too early
sleep $SLEEP

echo "Q" >&3

# Tear down command fifo
exec 3>&-
rm -f "${TMPPDIR}/s_server_input"

echo "Check message was successfully delivered over TLS"
grep " TLS SUCCESSFUL " "${TMPPDIR}/s_server_output"

title PARA "Kill any remaining children and wait for them"
kill_children
PORT=23456

exit 0
expect -c "spawn $CHECKER openssl s_server -accept \"${PORT}\" -naccept 1 -key \"${PRIURI}\" -cert \"${CRTURI}\";
set timeout 60;
expect {
\"ACCEPT\" {};
default {exit 1;};
}
set server_ready [open \"${TMPPDIR}/s_server_ready\" w+];
puts \$server_ready \"READY\n\";
close \$server_ready;
expect {
\"END SSL SESSION PARAMETERS\" {};
default {exit 1;};
}
send \" TLS SUCCESSFUL \n\"
send \"Q\n\"
expect {
eof {exit 0;};
default {exit 1;};
}" > "${TMPPDIR}/s_server_output" &
SERVER_PID=$!

read -r < "${TMPPDIR}/s_server_ready"

expect -c "spawn $CHECKER openssl s_client -connect \"localhost:${PORT}\";
set timeout 60;
expect {
\" TLS SUCCESSFUL \" {};
default {exit 1;};
}
expect {
eof {exit 0;};
default {exit 1;};
}"

exit 0;
Loading