Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / copy / copy-tls.sh
blob9f4ce539b33a3618a0d4d9a7ae8083c9ed20066d
1 #!/usr/bin/env bash
2 # nbd client library in userspace
3 # Copyright Red Hat
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 # Check that TLS to/from NBD servers works. It should be transparent
20 # as far as nbdcopy code is concerned, but using nbdcopy and TLS
21 # together stresses the library in unusual ways.
23 . ../tests/functions.sh
25 set -e
26 set -x
28 requires test "x$PSKTOOL" != "x"
29 requires nbdkit --exit-with-parent --version
30 requires bash -c "nbdkit --dump-config | grep tls=yes"
31 requires cmp /dev/null /dev/null
32 requires hexdump -C /dev/null
34 pskfile=copy-tls.psk
35 pidfile1=copy-tls.pid1
36 pidfile2=copy-tls.pid2
37 file1=copy-tls.file1
38 file2=copy-tls.file2
39 sock1=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX)
40 sock2=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX)
41 cleanup_fn rm -f $pskfile $pidfile1 $pidfile2 $file1 $file2 $sock1 $sock2
43 $PSKTOOL -u alice -p $pskfile
45 nbdkit --exit-with-parent -f -v -P $pidfile1 -U $sock1 \
46 --tls=require --tls-psk=$pskfile \
47 pattern size=100M &
48 uri1="nbds+unix://alice@/?socket=$sock1&tls-psk-file=$pskfile"
49 # Wait for the pidfile to appear.
50 for i in {1..60}; do
51 if test -f $pidfile1; then
52 break
54 sleep 1
55 done
56 if ! test -f $pidfile1; then
57 echo "$0: nbdkit did not start up"
58 exit 1
61 nbdkit --exit-with-parent -f -v -P $pidfile2 -U $sock2 \
62 --tls=require --tls-psk=$pskfile \
63 memory size=100M &
64 uri2="nbds+unix://alice@/?socket=$sock2&tls-psk-file=$pskfile"
65 # Wait for the pidfile to appear.
66 for i in {1..60}; do
67 if test -f $pidfile2; then
68 break
70 sleep 1
71 done
72 if ! test -f $pidfile2; then
73 echo "$0: nbdkit did not start up"
74 exit 1
77 $VG nbdcopy "$uri1" "$uri2"
79 # Download the file from both servers and check they are the same.
80 $VG nbdcopy "$uri1" $file1
81 $VG nbdcopy "$uri2" $file2
83 ls -l $file1 $file2
84 cmp $file1 $file2
86 # Test the data is at least non-zero.
87 test "$(hexdump -C $file1 | head -1)" = "00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 |................|"