forked from wolfSSL/wolfssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-put.test
More file actions
executable file
·148 lines (122 loc) · 3.03 KB
/
Copy pathget-put.test
File metadata and controls
executable file
·148 lines (122 loc) · 3.03 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
#!/bin/bash
if test ! -x ./examples/sftpclient/wolfsftp
then
echo "This test requires the wolfSFTP client."
exit 1
fi
# test SFTP client is working (that NO_WOLFSSH_CLIENT was not used)
./examples/sftpclient/wolfsftp -h
if [ $? -ne 0 ]
then
./examples/sftpclient/wolfsftp -h | grep NO_WOLFSSH_CLIENT
if [ $? -eq 0 ]
then
echo "macro NO_WOLFSSH_CLIENT was used"
echo "skipping test"
exit 77
else
echo "wolfSFTP client not compiled in or not working"
exit 1
fi
fi
# test for nonblocking only
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
if [ $? -eq 0 ]
then
echo "macro WOLFSSH_TEST_BLOCK was used"
exit 77
fi
if test ! -x ./examples/echoserver/echoserver
then
echo "This test requires the wolfSSH echoserver."
exit 1
fi
SERVER_PID=0
READY_FILE=$(pwd)/wolfssh_sftp_ready$$
READY_COUNTER=0
wait_for_server() {
while [ ! -s "$READY_FILE" ] && [ "$READY_COUNTER" -lt 20 ]; do
sleep 0.1
READY_COUNTER=$((READY_COUNTER+ 1))
done
if test -e "$READY_FILE"
then
# get created port 0 ephemeral port
PORT=$(cat "$READY_FILE")
else
echo "Echoserver never started."
do_cleanup
exit 1
fi
}
do_cleanup() {
rm -f "$READY_FILE" sample1.txt sample2.txt sample1-copy.txt sample2-copy.txt
if test $SERVER_PID != 0
then
kill -9 $SERVER_PID
fi
}
do_trap() {
do_cleanup
exit 1
}
trap do_trap INT TERM
./examples/echoserver/echoserver -d "$(pwd)" -R "$READY_FILE" >/dev/null 2>&1 &
SERVER_PID=$!
wait_for_server
echo "This is some sample test to make a file to copy back and forth." > sample1.txt
echo "This is a different set of sample text to copy back and forth." > sample2.txt
# Get test.
if ! ./examples/sftpclient/wolfsftp -u jill -P upthehill -p "$PORT" \
-G -l sample1-copy.txt -r sample1.txt
then
echo "Unable to get file."
do_cleanup
exit 1
fi
# Test fail on file that does not exist
rm -rf sample1-does-not-exist
if ./examples/sftpclient/wolfsftp -u jill -P upthehill -p "$PORT" \
-G -l sample1-copy.txt -r sample1-does-not-exist
then
echo "Success when expecting fail to get file."
do_cleanup
exit 1
fi
# Put test.
if ! ./examples/sftpclient/wolfsftp -u jill -P upthehill -p "$PORT" \
-g -l sample2.txt -r sample2-copy.txt
then
echo "Unable to put file."
do_cleanup
exit 1
fi
if ! diff sample1.txt sample1-copy.txt >/dev/null
then
echo "Get test files do not match."
do_cleanup
exit 1
fi
if ! diff sample2.txt sample2-copy.txt >/dev/null
then
echo "Put test files do not match."
do_cleanup
exit 1
fi
# using full path test.
rm -rf sample2-copy.txt
PWD=`pwd`
if ! ./examples/sftpclient/wolfsftp -u jill -P upthehill -p "$PORT" \
-g -l sample2.txt -r $PWD/sample2-copy.txt
then
echo "Unable to put file using full path."
do_cleanup
exit 1
fi
if ! diff sample2.txt sample2-copy.txt >/dev/null
then
echo "Put test files do not match after using full path."
do_cleanup
exit 1
fi
do_cleanup