|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# scp local test |
| 4 | + |
| 5 | +no_pid=-1 |
| 6 | +server_pid=$no_pid |
| 7 | +ready_file=`pwd`/wolfssh_scp_ready$$ |
| 8 | +counter=0 |
| 9 | + |
| 10 | +[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nwolfscp client doesn't exist" && exit 1 |
| 11 | + |
| 12 | +create_port() { |
| 13 | + while [ ! -s "$ready_file" ] && [ "$counter" -lt 20 ]; do |
| 14 | + echo -e "waiting for ready file..." |
| 15 | + sleep 0.1 |
| 16 | + counter=$((counter+ 1)) |
| 17 | + done |
| 18 | + |
| 19 | + if test -e $ready_file; then |
| 20 | + echo -e "found ready file, starting client..." |
| 21 | + |
| 22 | + # get created port 0 ephemeral port |
| 23 | + port=`cat $ready_file` |
| 24 | + else |
| 25 | + echo -e "NO ready file ending test..." |
| 26 | + do_cleanup |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +remove_ready_file() { |
| 32 | + if test -e $ready_file; then |
| 33 | + echo -e "removing existing ready file" |
| 34 | + rm $ready_file |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +do_cleanup() { |
| 39 | + echo "in cleanup" |
| 40 | + |
| 41 | + if [ $server_pid != $no_pid ] |
| 42 | + then |
| 43 | + echo "killing server" |
| 44 | + kill -9 $server_pid |
| 45 | + fi |
| 46 | + remove_ready_file |
| 47 | +} |
| 48 | + |
| 49 | +do_trap() { |
| 50 | + echo "got trap" |
| 51 | + do_cleanup |
| 52 | + exit -1 |
| 53 | +} |
| 54 | + |
| 55 | +trap do_trap INT TERM |
| 56 | + |
| 57 | +[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nClient doesn't exist" && exit 1 |
| 58 | + |
| 59 | +echo "Test basic copy from server to local" |
| 60 | +./examples/echoserver/echoserver -1 -R $ready_file & |
| 61 | +server_pid=$! |
| 62 | +create_port |
| 63 | +./examples/scpclient/wolfscp -u jill -P upthehill -p $port -S $PWD/scripts/scp.test:$PWD/scp.test |
| 64 | +RESULT=$? |
| 65 | +remove_ready_file |
| 66 | + |
| 67 | +if test -e $PWD/scp.test; then |
| 68 | + rm $PWD/scp.test |
| 69 | +else |
| 70 | + echo -e "\n\nfailed to get file" |
| 71 | + do_cleanup |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +echo "Test basic copy from local to server" |
| 76 | +./examples/echoserver/echoserver -1 -R $ready_file & |
| 77 | +server_pid=$! |
| 78 | +create_port |
| 79 | +./examples/scpclient/wolfscp -u jill -P upthehill -p $port -L $PWD/scripts/scp.test:$PWD/scp.test |
| 80 | +RESULT=$? |
| 81 | +remove_ready_file |
| 82 | + |
| 83 | +if test -e $PWD/scp.test; then |
| 84 | + rm $PWD/scp.test |
| 85 | +else |
| 86 | + echo -e "\n\nfailed to send file" |
| 87 | + do_cleanup |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +echo "Test of getting empty file" |
| 92 | +touch $PWD/scripts/empty |
| 93 | +./examples/echoserver/echoserver -1 -R $ready_file & |
| 94 | +server_pid=$! |
| 95 | +create_port |
| 96 | +./examples/scpclient/wolfscp -u jill -P upthehill -p $port -S $PWD/scripts/empty:$PWD/empty |
| 97 | +RESULT=$? |
| 98 | +remove_ready_file |
| 99 | +rm -f $PWD/scripts/empty |
| 100 | + |
| 101 | +if test -e $PWD/empty ; then |
| 102 | + rm $PWD/empty |
| 103 | +else |
| 104 | + echo -e "\n\nfailed to get empty file" |
| 105 | + do_cleanup |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | + |
| 109 | +echo "Test of sending empty file" |
| 110 | +touch $PWD/scripts/empty |
| 111 | +./examples/echoserver/echoserver -1 -R $ready_file & |
| 112 | +server_pid=$! |
| 113 | +create_port |
| 114 | +./examples/scpclient/wolfscp -u jill -P upthehill -p $port -L $PWD/scripts/empty:$PWD/empty |
| 115 | +RESULT=$? |
| 116 | +remove_ready_file |
| 117 | +rm -f $PWD/scripts/empty |
| 118 | + |
| 119 | +if test -e $PWD/empty ; then |
| 120 | + rm $PWD/empty |
| 121 | +else |
| 122 | + echo -e "\n\nfailed to send empty file" |
| 123 | + do_cleanup |
| 124 | + exit 1 |
| 125 | +fi |
| 126 | + |
| 127 | +echo -e "\nALL Tests Passed" |
| 128 | + |
| 129 | +exit 0 |
| 130 | + |
0 commit comments