#!/bin/sh # sftp local test no_pid=-1 server_pid=$no_pid ready_file=`pwd`/wolfssh_sftp_ready$$ counter=0 nonblockingOnly=0 [ ! -x ./examples/sftpclient/wolfsftp ] && echo -e "\n\nwolfSFTP client doesn't exist" && exit 1 # test for if the SFTP client works ./examples/sftpclient/wolfsftp -h | grep NO_WOLFSSH_CLIENT if [ $? -eq 0 ] then echo "macro NO_WOLFSSH_CLIENT was used" echo "skipping test" exit 77 fi # test for nonblocking only ./examples/client/client -h | grep WOLFSSH_TEST_BLOCK if [ $? -eq 0 ] then echo "macro NO_WOLFSSH_CLIENT was used" nonblockingOnly=1 fi #echo "ready file $ready_file" 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/sftpclient/wolfsftp ] && echo -e "\n\nClient doesn't exist" && exit 1 if [ $nonblockingOnly = 0 ]; then echo "Test basic connection" ./examples/echoserver/echoserver -1 -R $ready_file & server_pid=$! create_port echo "exit" | ./examples/sftpclient/wolfsftp -u jill -P upthehill -p $port RESULT=$? remove_ready_file if [ $RESULT -ne 0 ]; then echo -e "\n\nfailed to connect" do_cleanup exit 1 fi fi # Test non blocking connection echo "Test non blocking connection" ./examples/echoserver/echoserver -N -1 -R $ready_file & server_pid=$! create_port echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port RESULT=$? remove_ready_file if [ $RESULT -ne 0 ]; then echo -e "\n\nfailed to connect" do_cleanup exit 1 fi # Test want write return from highwater callback if [ $nonblockingOnly = 0 ]; then echo "Test want write return from highwater callback" ./examples/echoserver/echoserver -H -N -1 -R $ready_file & server_pid=$! create_port ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port -g -r $PWD/README.md-2 -l $PWD/README.md RESULT=$? remove_ready_file rm -f $PWD/README.md-2 if [ $RESULT -ne 0 ]; then echo -e "\n\nfailed to connect" do_cleanup exit 1 fi fi # Test of setting directory if [ $nonblockingOnly = 0 ]; then echo "Test of setting directory" PWD=`pwd` ./examples/echoserver/echoserver -d $PWD/examples -1 -R $ready_file & server_pid=$! create_port echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port RESULT=$? remove_ready_file if [ $RESULT -ne 0 ]; then echo -e "\n\nfailed to connect" do_cleanup exit 1 fi fi echo -e "\nALL Tests Passed" exit 0