forked from wolfSSL/wolfssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsftp.test
More file actions
executable file
·171 lines (148 loc) · 4.17 KB
/
sftp.test
File metadata and controls
executable file
·171 lines (148 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/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
# Test SFTP status failure for non-existing file
if [ $nonblockingOnly = 0 ]; then
echo "Test SFTP status failure for non-existing file"
./examples/echoserver/echoserver -N -1 -R $ready_file &
server_pid=$!
create_port
./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port -G -r $PWD/this_file_does_not_exist_12345.txt -l $PWD/test_output.txt > sftp_status_failure.log 2>&1
RESULT=$?
grep "Unable to copy remote file" sftp_status_failure.log > /dev/null
RESULT_MSG=$?
remove_ready_file
rm -f sftp_status_failure.log
rm -f $PWD/test_output.txt
if [ $RESULT -eq 0 ]; then
echo -e "\n\nERROR: Should have failed for non-existing file"
do_cleanup
exit 1
fi
if [ $RESULT_MSG -ne 0 ]; then
echo -e "\n\nERROR: Unexpected failure path while testing missing remote file"
do_cleanup
exit 1
fi
echo "Successfully received failure status packet"
fi
echo -e "\nALL Tests Passed"
exit 0