From 7e300b5109e446eb94b8f480a89391ec676d6ed0 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 1 Dec 2023 13:38:24 -0800 Subject: [PATCH] add terminal size test case --- apps/wolfsshd/test/run_all_sshd_tests.sh | 5 +- apps/wolfsshd/test/sshd_term_size_test.sh | 98 +++++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100755 apps/wolfsshd/test/sshd_term_size_test.sh diff --git a/apps/wolfsshd/test/run_all_sshd_tests.sh b/apps/wolfsshd/test/run_all_sshd_tests.sh index 638391d48..4c082d2cd 100755 --- a/apps/wolfsshd/test/run_all_sshd_tests.sh +++ b/apps/wolfsshd/test/run_all_sshd_tests.sh @@ -25,7 +25,7 @@ else start_wolfsshd "sshd_config_test" if [ -z "$PID" ]; then echo "Issue starting up wolfSSHd" - exit -1 + exit 1 fi fi @@ -46,11 +46,12 @@ run_test() { printf "Shutting down test wolfSSHd\n" stop_wolfsshd fi - exit -1 + exit 1 fi } run_test "sshd_exec_test.sh" +run_test "sshd_term_size_test.sh" # add aditional tests here, check on var USING_LOCAL_HOST if can make sshd # server start/restart with changes diff --git a/apps/wolfsshd/test/sshd_term_size_test.sh b/apps/wolfsshd/test/sshd_term_size_test.sh new file mode 100755 index 000000000..22d2f3a33 --- /dev/null +++ b/apps/wolfsshd/test/sshd_term_size_test.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# sshd local test + +pushd ../../.. + +TEST_CLIENT="./examples/client/client" +USER=`whoami` +PRIVATE_KEY="./keys/hansel-key-ecc.der" +PUBLIC_KEY="./keys/hansel-key-ecc.pub" + +if [ -z "$1" ] || [ -z "$2" ]; then + echo "expecting host and port as arguments" + echo "./sshd_exec_test.sh 127.0.0.1 22222" + exit 1 +fi + +set -e +echo "Creating tmux session at $PWD with command :" +tmux new-session -d -s test "$TEST_CLIENT -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"" + +# give the command a second to establish SSH connection +sleep 0.5 + +COL=`tmux display -p -t test '#{pane_width}'` +ROW=`tmux display -p -t test '#{pane_height}'` + +# get the terminals columns and lines +tmux send-keys -t test 'echo col=$COLUMNS row=$LINES' +tmux send-keys -t test 'ENTER' +tmux capture-pane -t test +RESULT=`tmux show-buffer | grep -v echo | grep -v rejecting | grep "col="` + +echo "$RESULT" +echo "" +echo "" +ROW_FOUND=`echo "$RESULT" | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'` +COL_FOUND=`echo "$RESULT" | sed -r 's/^[^0-9]*([0-9]+).*$/\1/'` + +if [ "$COL" != "$COL_FOUND" ]; then + echo "Col found was $COL_FOUND which does not match expected $COL" + exit 1 +fi + +if [ "$ROW" != "$ROW_FOUND" ]; then + echo "Row found was $ROW_FOUND which does not match expected $ROW" + exit 1 +fi + +# resize tmux after connection is open is not working @TODO +#tmux set-window-option -g aggressive-resize +#printf '\e[8;50;100t' +#tmux resize-pane -x 50 -y 10 -t test + +# close down the SSH session +tmux send-keys -t test 'exit' +tmux send-keys -t test 'ENTER' +set +e + +# kill off the session if it's still running, but don't error out if the session +# has already closed down +tmux kill-session -t test +set -e + +tmux new-session -d -x 50 -y 10 -s test "$TEST_CLIENT -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"" + +# give the command a second to establish SSH connection +sleep 0.5 + +echo "New COL=$COL ROW=$ROW" + +tmux send-keys -t test 'echo col=$COLUMNS row=$LINES' +tmux send-keys -t test 'ENTER' +tmux capture-pane -t test +RESULT=`tmux show-buffer | grep -v echo | grep -v rejecting | grep "col="` + +ROW_FOUND=`echo "$RESULT" | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'` +COL_FOUND=`echo "$RESULT" | sed -r 's/^[^0-9]*([0-9]+).*$/\1/'` + +if [ "50" != "$COL_FOUND" ]; then + echo "Col found was $COL_FOUND which does not match expected 50" + exit 1 +fi + +if [ "10" != "$ROW_FOUND" ]; then + echo "Row found was $ROW_FOUND which does not match expected 10" + exit 1 +fi + +# close down the SSH session +tmux send-keys -t test 'exit' +tmux send-keys -t test 'ENTER' +set +e +tmux kill-session -t test + +popd +exit 0 +