mirror of
https://github.com/stefanberger/swtpm.git
synced 2025-08-22 19:04:35 +00:00

Replace usage of samples/swtpm_setup.conf, use the one from tests/ instead. This allows installed-tests to refer to it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
110 lines
2.4 KiB
Bash
Executable File
110 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# For the license, see the LICENSE file in the root directory.
|
|
|
|
ROOT=${abs_top_builddir:-$(dirname "$0")/..}
|
|
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
|
|
|
|
source "${TESTDIR}/common"
|
|
skip_test_no_tpm12 "${SWTPM_EXE}"
|
|
STATEBASENAME="tpm-00.permall"
|
|
|
|
trap "cleanup" SIGTERM EXIT
|
|
|
|
function cleanup()
|
|
{
|
|
rm -rf "${workdir}"
|
|
}
|
|
|
|
# Test 1: --not-overwrite with dummy state file
|
|
|
|
workdir="$(mktemp -d)" || exit 1
|
|
statefile="${workdir}/${STATEBASENAME}"
|
|
dummydata="DUMMY"
|
|
echo "$dummydata" > "${statefile}"
|
|
|
|
if ! $SWTPM_SETUP \
|
|
--not-overwrite \
|
|
--tpm-state "${workdir}" \
|
|
--config "${SWTPM_SETUP_CONF}" \
|
|
--logfile "${workdir}/logfile" \
|
|
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
|
|
then
|
|
echo "Test 1 failed: Error: Could not run $SWTPM_SETUP."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -q "${dummydata}" "${statefile}"; then
|
|
echo "Test 1 failed: Error: The state file was unexpectedly overwritten."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Test 1 passed"
|
|
cleanup
|
|
|
|
# Test 2: --overwrite with dummy state file
|
|
|
|
workdir="$(mktemp -d)" || exit 1
|
|
statefile="${workdir}/${STATEBASENAME}"
|
|
dummydata="DUMMY"
|
|
echo "$dummydata" > "${statefile}"
|
|
|
|
if ! $SWTPM_SETUP \
|
|
--overwrite \
|
|
--tpm-state "${workdir}" \
|
|
--config "${SWTPM_SETUP_CONF}" \
|
|
--logfile "${workdir}/logfile" \
|
|
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}";
|
|
then
|
|
echo "Test 2 failed: Error: Could not run $SWTPM_SETUP."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
if grep -q "${dummydata}" "${statefile}"; then
|
|
echo "Test 2 failed: Error: The state file was not overwritten."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Test 2 passed"
|
|
cleanup
|
|
|
|
# Test 3: neither "--overwrite" nor "--not-overwrite" with dummy state file
|
|
|
|
workdir="$(mktemp -d)" || exit 1
|
|
statefile="${workdir}/${STATEBASENAME}"
|
|
dummydata="DUMMY"
|
|
echo "$dummydata" > "${statefile}"
|
|
|
|
$SWTPM_SETUP \
|
|
--tpm-state "${workdir}" \
|
|
--config "${SWTPM_SETUP_CONF}" \
|
|
--logfile "${workdir}/logfile" \
|
|
--tpm "${SWTPM_EXE} socket ${SWTPM_TEST_SECCOMP_OPT}"
|
|
|
|
if [ $? -ne 1 ]; then
|
|
echo "Test 3 failed: Error: $SWTPM_SETUP did not exit with exit code 1."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -q "${dummydata}" "${statefile}"; then
|
|
echo "Test 3 failed: Error: The state file was unexpectedly overwritten."
|
|
echo "Setup Logfile:"
|
|
cat "${workdir}/logfile"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Test 3 passed"
|
|
cleanup
|
|
|
|
exit 0
|