Add tests for scp, even empty file transfer.

pull/399/head
Anthony Hu 2022-03-25 10:23:11 -04:00
parent eae46da927
commit f589ea275d
3 changed files with 156 additions and 0 deletions

0
scripts/empty 100644
View File

View File

@ -7,4 +7,8 @@ dist_noinst_SCRIPTS+= scripts/sftp.test
dist_noinst_SCRIPTS+= scripts/get-put.test
endif
if BUILD_SCP
dist_noinst_SCRIPTS+= scripts/scp.test
endif
dist_noinst_SCRIPTS+= scripts/external.test

152
scripts/scp.test 100755
View File

@ -0,0 +1,152 @@
#!/bin/sh
# scp local test
no_pid=-1
server_pid=$no_pid
ready_file=`pwd`/wolfssh_scp_ready$$
counter=0
[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nwolfscp client doesn't exist" && exit 1
create_port() {
while [ ! -s "$ready_file" ] && [ "$counter" -lt 20 ]; do
echo -e "waiting for ready file..."
sleep 0.1
counter=$((counter+ 1))
done
if test -e $ready_file; then
echo -e "found ready file, starting client..."
# get created port 0 ephemeral port
port=`cat $ready_file`
else
echo -e "NO ready file ending test..."
do_cleanup
exit 1
fi
}
remove_ready_file() {
if test -e $ready_file; then
echo -e "removing existing ready file"
rm $ready_file
fi
}
do_cleanup() {
echo "in cleanup"
if [ $server_pid != $no_pid ]
then
echo "killing server"
kill -9 $server_pid
fi
remove_ready_file
}
do_trap() {
echo "got trap"
do_cleanup
exit -1
}
trap do_trap INT TERM
[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nClient doesn't exist" && exit 1
echo "Test basic copy from server to local"
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
./examples/scpclient/wolfscp -u jill -P upthehill -p $port -S $PWD/scripts/scp.test:$PWD/scp.test
RESULT=$?
remove_ready_file
if test -e $PWD/scp.test; then
rm $PWD/scp.test
else
echo -e "\n\nfailed to get file"
do_cleanup
exit 1
fi
if [ $RESULT -ne 0 ]; then
echo -e "\n\nbad return code"
do_cleanup
exit 1
fi
echo "Test basic copy from local to server"
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
./examples/scpclient/wolfscp -u jill -P upthehill -p $port -L $PWD/scripts/scp.test:$PWD/scp.test
RESULT=$?
remove_ready_file
if test -e $PWD/scp.test; then
rm $PWD/scp.test
else
echo -e "\n\nfailed to send file"
do_cleanup
exit 1
fi
if [ $RESULT -ne 0 ]; then
echo -e "\n\n bad return code"
do_cleanup
exit 1
fi
echo "Test of getting empty file"
PWD=`pwd`
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
./examples/scpclient/wolfscp -u jill -P upthehill -p $port -S $PWD/scripts/empty:$PWD/empty
RESULT=$?
remove_ready_file
if test -e $PWD/empty ; then
rm $PWD/empty
else
echo -e "\n\nfailed to get empty file"
do_cleanup
exit 1
fi
if [ $RESULT -ne 0 ]; then
echo -e "\n\n bad return code"
do_cleanup
exit 1
fi
echo "Test of sending empty file"
PWD=`pwd`
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
./examples/scpclient/wolfscp -u jill -P upthehill -p $port -L $PWD/scripts/empty:$PWD/empty
RESULT=$?
remove_ready_file
if test -e $PWD/empty ; then
rm $PWD/empty
else
echo -e "\n\nfailed to send empty file"
do_cleanup
exit 1
fi
if [ $RESULT -ne 0 ]; then
echo -e "\n\n bad return code"
do_cleanup
exit 1
fi
echo -e "\nALL Tests Passed"
exit 0