tests: Add a test case for the new swtpm_setup option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-10-07 08:41:47 -04:00 committed by Stefan Berger
parent 5d4dd13e80
commit bcd5523b08
2 changed files with 81 additions and 1 deletions

View File

@ -42,7 +42,8 @@ TESTS += \
test_print_capabilities \
test_print_states \
test_swtpm_setup_overwrite \
test_swtpm_setup_file_backend
test_swtpm_setup_file_backend \
test_swtpm_setup_misc
TESTS += \
test_tpm2_ctrlchannel2 \

79
tests/test_swtpm_setup_misc Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# For the license, see the LICENSE file in the root directory.
if [ "$(id -u)" -eq 0 ]; then
echo "Not running this test as root."
exit 77
fi
ROOT=${abs_top_builddir:-$(dirname "$0")/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
SRCDIR=${abs_top_srcdir:-$(dirname "$0")/..}
source ${TESTDIR}/common
trap "cleanup" SIGTERM EXIT
function cleanup()
{
rm -rf ${workdir}
}
workdir=$(mktemp -d)
FILES="swtpm-localca.conf swtpm-localca.options swtpm_setup.conf"
XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
--create-config-files 1>/dev/null
if [ $? -ne 0 ]; then
echo "Error: Could not created config files (without parameters)"
exit 1
fi
for f in ${FILES}; do
if ! [ -f "${workdir}/${f}" ]; then
echo "Error: File ${workedir}/${f} was not created"
exit 1
fi
done
if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
echo "Error: Directory var/lib/swtpm-localca was not created"
exit 1
fi
XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
--create-config-files skip-if-exist 1>/dev/null
if [ $? -ne 0 ]; then
echo "Error: skip-if-exists should have exit'ed with 0."
exit 1
fi
echo "Test 1: Ok"
cleanup
workdir=$(mktemp -d)
XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
--create-config-files skip-if-exist 1>/dev/null
if [ $? -ne 0 ]; then
echo "Error: skip-if-exists should have exit'ed with 0."
exit 1
fi
for f in ${FILES}; do
if ! [ -f "${workdir}/${f}" ]; then
echo "Error: File ${workedir}/${f} was not created"
exit 1
fi
done
if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
echo "Error: Directory var/lib/swtpm-localca was not created"
exit 1
fi
echo "Test 2: Ok"
cleanup
exit 0