4 # Copyright (C) 2010 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 export PYTHON=${PYTHON:=python}
26 impexpd="$PYTHON daemons/import-export -d"
36 if [[ -s "$dst_output" ]]; then
41 if [[ -s "$src_output" ]]; then
51 # Unlike combining the "wait" commands using || or &&, this ensures we
52 # actually wait for all PIDs.
63 echo "${TOP_SRCDIR:-.}/test"
67 echo "$(get_testpath)/data/$1"
70 statusdir=$(mktemp -d)
71 trap "rm -rf $statusdir" EXIT
73 src_statusfile=$statusdir/src.status
74 src_output=$statusdir/src.output
75 src_x509=$statusdir/src.pem
77 dst_statusfile=$statusdir/dst.status
78 dst_output=$statusdir/dst.output
79 dst_x509=$statusdir/dst.pem
80 dst_portfile=$statusdir/dst.port
82 other_x509=$statusdir/other.pem
84 testdata=$statusdir/data1
92 $impexpd >/dev/null 2>&1 &&
93 err "daemon-util succeeded without parameters"
95 $impexpd foo bar baz moo boo >/dev/null 2>&1 &&
96 err "daemon-util succeeded with wrong parameters"
98 $impexpd $src_statusfile >/dev/null 2>&1 &&
99 err "daemon-util succeeded with insufficient parameters"
101 $impexpd $src_statusfile invalidmode >/dev/null 2>&1 &&
102 err "daemon-util succeeded with invalid mode"
104 $impexpd $src_statusfile import --compression=rot13 >/dev/null 2>&1 &&
105 err "daemon-util succeeded with invalid compression"
107 cat $(get_testfile proc_drbd8.txt) $(get_testfile cert1.pem) > $testdata
110 $PYTHON $(get_testpath)/import-export_unittest-helper "$@"
114 echo "$(date '+%F %T'):" "$@" '...'
118 rm -f $src_statusfile $dst_output $dst_statusfile $dst_output $dst_portfile
122 # Wait for connection to be established
123 impexpd_helper $dst_statusfile connected
129 # Wait for listening port
130 impexpd_helper $dst_statusfile listen-port > $dst_portfile
132 local port=$(< $dst_portfile)
134 test -n "$port" || err 'Empty port file'
136 do_export_to_port $port
139 do_export_to_port() {
142 $impexpd $src_statusfile export --bind=127.0.0.1 \
143 --host=127.0.0.1 --port=$port \
144 --key=$src_x509 --cert=$src_x509 --ca=$dst_x509 \
145 --cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
146 --connect-timeout=$connect_timeout \
147 --connect-retries=$connect_retries \
152 $impexpd $dst_statusfile import --bind=127.0.0.1 \
154 --key=$dst_x509 --cert=$dst_x509 --ca=$src_x509 \
155 --cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
156 --connect-timeout=$connect_timeout \
157 --connect-retries=$connect_retries \
161 upto 'Generate X509 certificates and keys'
162 impexpd_helper $src_x509 gencert
163 impexpd_helper $dst_x509 gencert
164 impexpd_helper $other_x509 gencert
168 do_import > $statusdir/recv1 2>$dst_output & imppid=$!
169 { write_data | do_export; } &>$src_output & exppid=$!
170 checkpids $exppid $imppid || err 'An error occurred'
171 cmp $testdata $statusdir/recv1 || err 'Received data does not match input'
173 upto 'Export using wrong CA'
175 # Setting lower timeout to not wait for too long
176 connect_timeout=1 do_import &>$dst_output & imppid=$!
177 : | dst_x509=$other_x509 do_export &>$src_output & exppid=$!
178 checkpids $exppid $imppid && err 'Export did not fail when using wrong CA'
180 upto 'Import using wrong CA'
182 # Setting lower timeout to not wait for too long
183 src_x509=$other_x509 connect_timeout=1 do_import &>$dst_output & imppid=$!
184 : | do_export &>$src_output & exppid=$!
185 checkpids $exppid $imppid && err 'Import did not fail when using wrong CA'
187 upto 'Suffix command on import'
189 cmd_suffix="| cksum > $statusdir/recv2" do_import &>$dst_output & imppid=$!
190 { write_data | do_export; } &>$src_output & exppid=$!
191 checkpids $exppid $imppid || err 'Testing additional commands failed'
192 cmp $statusdir/recv2 <(cksum < $testdata) || \
193 err 'Checksum of received data does not match'
195 upto 'Prefix command on export'
197 do_import > $statusdir/recv3 2>$dst_output & imppid=$!
198 { write_data | cmd_prefix="cksum |" do_export; } &>$src_output & exppid=$!
199 checkpids $exppid $imppid || err 'Testing additional commands failed'
200 cmp $statusdir/recv3 <(cksum < $testdata) || \
201 err 'Received checksum does not match'
203 upto 'Failing prefix command on export'
205 : | cmd_prefix='exit 1;' do_export_to_port 0 &>$src_output & exppid=$!
206 checkpids $exppid && err 'Prefix command on export did not fail when it should'
208 upto 'Failing suffix command on export'
210 do_import >&$src_output & imppid=$!
211 : | cmd_suffix='| exit 1' do_export &>$dst_output & exppid=$!
212 checkpids $imppid $exppid && \
213 err 'Suffix command on export did not fail when it should'
215 upto 'Failing prefix command on import'
217 cmd_prefix='exit 1;' do_import &>$dst_output & imppid=$!
218 checkpids $imppid && err 'Prefix command on import did not fail when it should'
220 upto 'Failing suffix command on import'
222 cmd_suffix='| exit 1' do_import &>$dst_output & imppid=$!
223 : | do_export &>$src_output & exppid=$!
224 checkpids $imppid $exppid && \
225 err 'Suffix command on import did not fail when it should'
227 upto 'Listen timeout A'
229 # Setting lower timeout to not wait too long (there won't be anything trying to
231 connect_timeout=1 do_import &>$dst_output & imppid=$!
232 checkpids $imppid && \
233 err 'Listening with timeout did not fail when it should'
235 upto 'Listen timeout B'
237 do_import &>$dst_output & imppid=$!
238 { sleep 1; : | do_export; } &>$src_output & exppid=$!
239 checkpids $exppid $imppid || \
240 err 'Listening with timeout failed when it should not'
242 upto 'No compression'
244 compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$!
245 { write_data | compress=none do_export; } &>$src_output & exppid=$!
246 checkpids $exppid $imppid || err 'An error occurred'
247 cmp $testdata $statusdir/recv-nocompr || \
248 err 'Received data does not match input'
250 upto 'Compression mismatch A'
252 compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$!
253 { write_data | compress=gzip do_export; } &>$src_output & exppid=$!
254 checkpids $exppid $imppid || err 'An error occurred'
255 cmp -s $testdata $statusdir/recv-miscompr && \
256 err 'Received data matches input when it should not'
258 upto 'Compression mismatch B'
260 compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$!
261 { write_data | compress=none do_export; } &>$src_output & exppid=$!
262 checkpids $exppid $imppid && err 'Did not fail when it should'
263 cmp -s $testdata $statusdir/recv-miscompr2 && \
264 err 'Received data matches input when it should not'