3 # Copyright (C) 2019-2022 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 requires nbdsh
-c 'exit(not h.supports_tls())'
38 # Does the nbdkit binary support TLS?
39 if ! nbdkit
--dump-config |
grep -sq tls
=yes; then
40 echo "$0: nbdkit built without TLS support"
44 # Did we create the PSK keys file?
45 # Probably 'certtool' is missing.
46 if [ ! -s keys.psk
]; then
47 echo "$0: PSK keys file was not created by the test harness"
51 plugin
=.libs
/test-disconnect-plugin.
$SOEXT
52 requires
test -f $plugin
54 sock
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
55 files
="disconnect-tls.pid $sock"
56 cleanup_fn
rm -f $files
58 # Start nbdkit with the disconnect plugin, which has delayed reads and
59 # does disconnect on write based on export name.
60 start_nbdkit
-P disconnect-tls.pid
--tls require
--tls-psk=keys.psk \
63 pid
=`cat disconnect-tls.pid`
65 # We can't use 'nbdsh -u "$uri" because of nbd_set_uri_allow_local_file.
66 # Empty export name does soft disconnect on write; the write and the
67 # pending read should still succeed, but second read attempt should fail.
71 h.set_tls(nbd.TLS_REQUIRE)
72 h.set_tls_psk_file("keys.psk")
73 h.set_tls_username("qemu")
74 h.connect_unix("'"$sock"'")
78 c = h.aio_peek_command_completed()
85 c1 = h.aio_pread(buf, 1)
86 c2 = h.aio_pwrite(buf, 2)
88 h.aio_command_completed(c2)
89 c3 = h.aio_pread(buf, 3)
92 h.aio_command_completed(c3)
94 except nbd.Error as ex:
95 assert ex.errnum == errno.ESHUTDOWN
97 h.aio_command_completed(c1)
101 # Non-empty export name does hard disconnect on write. The write and the
102 # pending read should fail with lost connection.
106 h.set_tls(nbd.TLS_REQUIRE)
107 h.set_tls_psk_file("keys.psk")
108 h.set_tls_username("qemu")
109 h.set_export_name("a")
110 h.connect_unix("'"$sock"'")
113 c1 = h.aio_pread(buf, 1)
114 c2 = h.aio_pwrite(buf, 2)
115 while h.aio_in_flight() > 1:
117 assert h.aio_is_ready() is False
119 h.aio_command_completed(c1)
121 except nbd.Error as ex:
122 assert ex.errnum == errno.ENOTCONN
124 h.aio_command_completed(c2)
126 except nbd.Error as ex:
127 assert ex.errnum == errno.ENOTCONN
130 # nbdkit should still be running