[PATCH 09/10] nvme/043: test bi-directional authentication

Hannes Reinecke
2022-06-10T11:33:57Z

tests/nvme/043 | 106 +++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/043.out | 8 ++++
2 files changed, 114 insertions(+)
create mode 100644 tests/nvme/043
create mode 100644 tests/nvme/043.out

diff --git a/tests/nvme/043 b/tests/nvme/043
new file mode 100644
index 0000000..fdccb10
--- /dev/null
+++ b/tests/nvme/043
@@ -0,0 +1,106 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2021 Hannes Reinecke, SUSE Labs
+#
+# Test bi-directional authentication
+
+. tests/nvme/rc
+
+DESCRIPTION="Test bi-directional authentication"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _require_nvme_trtype_is_fabrics
+ _require_nvme_cli_auth
+}
+
+
+test() {
+ local port
+ local subsys_name="blktests-subsystem-1"
+ local hostid="$(uuidgen)"
+ local hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}"
+ local file_path="${TMPDIR}/img"
+ local hostkey
+ local ctrlkey
+ local ctrldev
+
+ echo "Running ${TEST_NAME}"
+
+ hostkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)"
+ if [ $? -ne 0 ] ; then
+ echo "nvme gen-dhchap-key command missing"
+ return 1
+ fi
+
+ ctrlkey="$(nvme gen-dhchap-key -n ${subsys_name} 2> /dev/null)"
+ if [ $? -ne 0 ] ; then
+ echo "nvme gen-dhchap-key command missing"
+ return 1
+ fi
+
+ _setup_nvmet
+
+ truncate -s 512M "${file_path}"
+
+ _create_nvmet_subsystem "${subsys_name}" "${file_path}"
+ port="$(_create_nvmet_port "${nvme_trtype}")"
+ _add_nvmet_subsys_to_port "${port}" "${subsys_name}"
+ _create_nvmet_host "${subsys_name}" "${hostnqn}" "${hostkey}" "${ctrlkey}"
+
+ _set_nvmet_dhgroup "${hostnqn}" "ffdhe2048"
+
+ # Step 1: Connect with host authentication only
+ echo "Test host authentication"
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \
+ "${def_traddr}" "${def_trsvcid}" \
+ "${hostnqn}" "${hostid}" \
+ "${hostkey}"
+ if [ $? -ne 0 ] ; then
+ echo "nvme connect failed"
+ fi
+
+ udevadm settle
+
+ _nvme_disconnect_subsys "${subsys_name}"
+
+ # Step 2: Connect with host authentication
+ # and invalid ctrl authentication
+ echo "Test host authentication and invalid ctrl authentication"
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \
+ "${def_traddr}" "${def_trsvcid}" \
+ "${hostnqn}" "${hostid}" \
+ "${hostkey}" "${hostkey}"
+ if [ $? -eq 0 ] ; then
+ echo "nvme connect succeeded (should have failed)"
+ _nvme_disconnect_subsys "${subsys_name}"
+ fi
+
+ # Step 3: Connect with host authentication
+ # and valid ctrl authentication
+ echo "Test host authentication and valid ctrl authentication"
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \
+ "${def_traddr}" "${def_trsvcid}" \
+ "${hostnqn}" "${hostid}" \
+ "${hostkey}" "${ctrlkey}"
+ if [ $? -ne 0 ] ; then
+ echo "nvme connect failed"
+ fi
+
+ udevadm settle
+
+ _nvme_disconnect_subsys "${subsys_name}"
+
+ _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}"
+ _remove_nvmet_subsystem "${subsys_name}"
+
+ _remove_nvmet_port "${port}"
+
+ _remove_nvmet_host "${hostnqn}"
+
+ rm ${file_path}
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/043.out b/tests/nvme/043.out
new file mode 100644
index 0000000..a49408d
--- /dev/null
+++ b/tests/nvme/043.out
@@ -0,0 +1,8 @@
+Running nvme/043
+Test host authentication
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Test host authentication and invalid ctrl authentication
+no controller found: failed to write to nvme-fabrics device
+Test host authentication and valid ctrl authentication
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Test complete
--
2.26.2