Revision 9d198e6f test/import-export_unittest.bash
b/test/import-export_unittest.bash | ||
---|---|---|
23 | 23 |
|
24 | 24 |
export PYTHON=${PYTHON:=python} |
25 | 25 |
|
26 |
impexpd="$PYTHON daemons/import-export --connect-timeout=1 --connect-retries=1" |
|
27 |
|
|
28 |
# Add "-d" for debugging |
|
29 |
#impexpd+=' -d' |
|
26 |
impexpd="$PYTHON daemons/import-export -d" |
|
30 | 27 |
|
31 | 28 |
err() { |
32 | 29 |
echo "$@" |
33 | 30 |
echo 'Aborting' |
31 |
show_output |
|
34 | 32 |
exit 1 |
35 | 33 |
} |
36 | 34 |
|
35 |
show_output() { |
|
36 |
if [[ -s "$dst_output" ]]; then |
|
37 |
echo |
|
38 |
echo 'Import output:' |
|
39 |
cat $dst_output |
|
40 |
fi |
|
41 |
if [[ -s "$src_output" ]]; then |
|
42 |
echo |
|
43 |
echo 'Export output:' |
|
44 |
cat $src_output |
|
45 |
fi |
|
46 |
} |
|
47 |
|
|
37 | 48 |
checkpids() { |
38 | 49 |
local result=0 |
39 | 50 |
|
... | ... | |
60 | 71 |
trap "rm -rf $statusdir" EXIT |
61 | 72 |
|
62 | 73 |
src_statusfile=$statusdir/src.status |
74 |
src_output=$statusdir/src.output |
|
63 | 75 |
src_x509=$statusdir/src.pem |
64 | 76 |
|
65 | 77 |
dst_statusfile=$statusdir/dst.status |
78 |
dst_output=$statusdir/dst.output |
|
66 | 79 |
dst_x509=$statusdir/dst.pem |
67 | 80 |
dst_portfile=$statusdir/dst.port |
68 | 81 |
|
... | ... | |
72 | 85 |
|
73 | 86 |
cmd_prefix= |
74 | 87 |
cmd_suffix= |
88 |
connect_timeout=10 |
|
89 |
connect_retries=1 |
|
75 | 90 |
|
76 | 91 |
$impexpd >/dev/null 2>&1 && |
77 | 92 |
err "daemon-util succeeded without parameters" |
... | ... | |
91 | 106 |
$PYTHON $(get_testpath)/import-export_unittest-helper "$@" |
92 | 107 |
} |
93 | 108 |
|
109 |
upto() { |
|
110 |
echo "$(date '+%F %T'):" "$@" '...' |
|
111 |
} |
|
112 |
|
|
94 | 113 |
reset_status() { |
95 |
rm -f $src_statusfile $dst_statusfile $dst_portfile
|
|
114 |
rm -f $src_statusfile $dst_output $dst_statusfile $dst_output $dst_portfile
|
|
96 | 115 |
} |
97 | 116 |
|
98 | 117 |
write_data() { |
... | ... | |
119 | 138 |
$impexpd $src_statusfile export --bind=127.0.0.1 \ |
120 | 139 |
--host=127.0.0.1 --port=$port \ |
121 | 140 |
--key=$src_x509 --cert=$src_x509 --ca=$dst_x509 \ |
122 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" |
|
141 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \ |
|
142 |
--connect-timeout=$connect_timeout \ |
|
143 |
--connect-retries=$connect_retries |
|
123 | 144 |
} |
124 | 145 |
|
125 | 146 |
do_import() { |
126 | 147 |
$impexpd $dst_statusfile import --bind=127.0.0.1 \ |
127 | 148 |
--host=127.0.0.1 \ |
128 | 149 |
--key=$dst_x509 --cert=$dst_x509 --ca=$src_x509 \ |
129 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" |
|
150 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \ |
|
151 |
--connect-timeout=$connect_timeout \ |
|
152 |
--connect-retries=$connect_retries |
|
130 | 153 |
} |
131 | 154 |
|
132 |
# Generate X509 certificates and keys
|
|
155 |
upto 'Generate X509 certificates and keys'
|
|
133 | 156 |
impexpd_helper $src_x509 gencert |
134 | 157 |
impexpd_helper $dst_x509 gencert |
135 | 158 |
impexpd_helper $other_x509 gencert |
136 | 159 |
|
137 |
# Normal case
|
|
160 |
upto 'Normal case'
|
|
138 | 161 |
reset_status |
139 |
do_import > $statusdir/recv1 & imppid=$! |
|
140 |
write_data | do_export & exppid=$!
|
|
162 |
do_import > $statusdir/recv1 2>$dst_output & imppid=$!
|
|
163 |
{ write_data | do_export; } &>$src_output & exppid=$!
|
|
141 | 164 |
checkpids $exppid $imppid || err 'An error occurred' |
142 | 165 |
cmp $testdata $statusdir/recv1 || err 'Received data does not match input' |
143 | 166 |
|
144 |
# Export using wrong CA
|
|
167 |
upto 'Export using wrong CA'
|
|
145 | 168 |
reset_status |
146 |
do_import > /dev/null 2>&1 & imppid=$! |
|
147 |
: | dst_x509=$other_x509 do_export 2>/dev/null & exppid=$! |
|
169 |
# Setting lower timeout to not wait for too long |
|
170 |
connect_timeout=1 do_import &>$dst_output & imppid=$! |
|
171 |
: | dst_x509=$other_x509 do_export &>$src_output & exppid=$! |
|
148 | 172 |
checkpids $exppid $imppid && err 'Export did not fail when using wrong CA' |
149 | 173 |
|
150 |
# Import using wrong CA
|
|
174 |
upto 'Import using wrong CA'
|
|
151 | 175 |
reset_status |
152 |
src_x509=$other_x509 do_import > /dev/null 2>&1 & imppid=$! |
|
153 |
: | do_export 2> /dev/null & exppid=$! |
|
176 |
# Setting lower timeout to not wait for too long |
|
177 |
src_x509=$other_x509 connect_timeout=1 do_import &>$dst_output & imppid=$! |
|
178 |
: | do_export &>$src_output & exppid=$! |
|
154 | 179 |
checkpids $exppid $imppid && err 'Import did not fail when using wrong CA' |
155 | 180 |
|
156 |
# Suffix command on import
|
|
181 |
upto 'Suffix command on import'
|
|
157 | 182 |
reset_status |
158 |
cmd_suffix="| cksum > $statusdir/recv2" do_import & imppid=$! |
|
159 |
write_data | do_export & exppid=$!
|
|
183 |
cmd_suffix="| cksum > $statusdir/recv2" do_import &>$dst_output & imppid=$!
|
|
184 |
{ write_data | do_export; } &>$src_output & exppid=$!
|
|
160 | 185 |
checkpids $exppid $imppid || err 'Testing additional commands failed' |
161 | 186 |
cmp $statusdir/recv2 <(cksum < $testdata) || \ |
162 | 187 |
err 'Checksum of received data does not match' |
163 | 188 |
|
164 |
# Prefix command on export
|
|
189 |
upto 'Prefix command on export'
|
|
165 | 190 |
reset_status |
166 |
do_import > $statusdir/recv3 & imppid=$! |
|
167 |
write_data | cmd_prefix="cksum |" do_export & exppid=$!
|
|
191 |
do_import > $statusdir/recv3 2>$dst_output & imppid=$!
|
|
192 |
{ write_data | cmd_prefix="cksum |" do_export; } &>$src_output & exppid=$!
|
|
168 | 193 |
checkpids $exppid $imppid || err 'Testing additional commands failed' |
169 | 194 |
cmp $statusdir/recv3 <(cksum < $testdata) || \ |
170 | 195 |
err 'Received checksum does not match' |
171 | 196 |
|
172 |
# Failing prefix command on export
|
|
197 |
upto 'Failing prefix command on export'
|
|
173 | 198 |
reset_status |
174 |
: | cmd_prefix='exit 1;' do_export_to_port 0 & exppid=$! |
|
199 |
: | cmd_prefix='exit 1;' do_export_to_port 0 &>$src_output & exppid=$!
|
|
175 | 200 |
checkpids $exppid && err 'Prefix command on export did not fail when it should' |
176 | 201 |
|
177 |
# Failing suffix command on export
|
|
202 |
upto 'Failing suffix command on export'
|
|
178 | 203 |
reset_status |
179 |
do_import > /dev/null & imppid=$!
|
|
180 |
: | cmd_suffix='| exit 1' do_export & exppid=$! |
|
204 |
do_import >&$src_output & imppid=$!
|
|
205 |
: | cmd_suffix='| exit 1' do_export &>$dst_output & exppid=$!
|
|
181 | 206 |
checkpids $imppid $exppid && \ |
182 | 207 |
err 'Suffix command on export did not fail when it should' |
183 | 208 |
|
184 |
# Failing prefix command on import
|
|
209 |
upto 'Failing prefix command on import'
|
|
185 | 210 |
reset_status |
186 |
cmd_prefix='exit 1;' do_import > /dev/null & imppid=$!
|
|
211 |
cmd_prefix='exit 1;' do_import &>$dst_output & imppid=$!
|
|
187 | 212 |
checkpids $imppid && err 'Prefix command on import did not fail when it should' |
188 | 213 |
|
189 |
# Failing suffix command on import
|
|
214 |
upto 'Failing suffix command on import'
|
|
190 | 215 |
reset_status |
191 |
cmd_suffix='| exit 1' do_import > /dev/null & imppid=$!
|
|
192 |
: | do_export & exppid=$! |
|
216 |
cmd_suffix='| exit 1' do_import &>$dst_output & imppid=$!
|
|
217 |
: | do_export &>$src_output & exppid=$!
|
|
193 | 218 |
checkpids $imppid $exppid && \ |
194 | 219 |
err 'Suffix command on import did not fail when it should' |
195 | 220 |
|
221 |
upto 'Listen timeout A' |
|
222 |
reset_status |
|
223 |
# Setting lower timeout to not wait too long (there won't be anything trying to |
|
224 |
# connect) |
|
225 |
connect_timeout=1 do_import &>$dst_output & imppid=$! |
|
226 |
checkpids $imppid && \ |
|
227 |
err 'Listening with timeout did not fail when it should' |
|
228 |
|
|
229 |
upto 'Listen timeout B' |
|
230 |
reset_status |
|
231 |
do_import &>$dst_output & imppid=$! |
|
232 |
{ sleep 1; : | do_export; } &>$src_output & exppid=$! |
|
233 |
checkpids $exppid $imppid || \ |
|
234 |
err 'Listening with timeout failed when it should not' |
|
235 |
|
|
196 | 236 |
exit 0 |
Also available in: Unified diff