Skip to content

Commit

Permalink
add regression test for closing down child on SSH connection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Nov 26, 2024
1 parent c8692f7 commit e55c7cb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/wolfsshd/test/run_all_sshd_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ run_test "sshd_exec_test.sh"
run_test "sshd_term_size_test.sh"
run_test "sshd_large_sftp_test.sh"
run_test "sshd_bad_sftp_test.sh"
run_test "sshd_term_close_test.sh"

#Github actions needs resolved for these test cases
#run_test "error_return.sh"
Expand Down
61 changes: 61 additions & 0 deletions apps/wolfsshd/test/sshd_term_close_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/sh

# sshd local test

ROOT_PWD=$(pwd)
cd ../../..

TEST_CLIENT="ssh"
USER=$(whoami)
PRIVATE_KEY="./keys/hansel-key-ecc.der"

if [ -z "$1" ] || [ -z "$2" ]; then
echo "expecting host and port as arguments"
echo "$0 127.0.0.1 22222"
exit 1
fi

# get the current wolfsshd pid count to compare with
WOLFSSHD_PID_COUNT=$(pgrep wolfsshd | wc -l)

COMMAND="timeout 2 $TEST_CLIENT -p $2 -i $PRIVATE_KEY $USER@$1"
echo "$COMMAND"
$COMMAND &
WOLFSSHD_PID_COUNT_AFTER=$(pgrep wolfsshd | wc -l)
if [ "$WOLFSSHD_PID_COUNT" = "$WOLFSSHD_PID_COUNT_AFTER" ]; then
echo "Expecting another wolfSSHd pid after connection"
exit 1
fi
netstat -nt | grep ESTABLISHED
RESULT=$?
if [ "$RESULT" != "0" ]; then
echo "Expecting to find the TCP connection established"
exit 1
fi

sleep 2

netstat -nt | grep CLOSE_WAIT
RESULT=$?
if [ "$RESULT" = "0" ]; then
echo "Found close wait and was not expecting it"
exit 1
fi

netstat -nt | grep TIME_WAIT
RESULT=$?
if [ "$RESULT" != "0" ]; then
echo "Did not find timed wait for TCP close down"
exit 1
fi

RESULT=$?
if [ "$RESULT" = "0" ]; then
echo "Expecting to fail transfer to folder"
exit 1
fi

cd "$ROOT_PWD"
exit 0


0 comments on commit e55c7cb

Please sign in to comment.