swtpm/tests/test_tpm2_file_permissions
Stefan Berger 30510820fe tests: Add a test case for testing --runas and ability to access files
Add a test case for testing the --runas parameter and the ability to access
existing files that have restrictive access permission so that only allow
the --runas user is able to access these files. This is to ensure that
swtpm can access these files properly when the handling of options and the
changing to the --runas user is moved around within swtpm.

Skip the test case if swtpm is linked with ASAN since then we get these
types of error messages that fail tests:

==== Starting swtpm with interfaces socket+socket ====
==3303263==LeakSanitizer has encountered a fatal error.
==3303263==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==3303263==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-28 09:23:28 -04:00

42 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
if [ "$(id -u)" -ne 0 ]; then
echo "Need to be root to run this test."
exit 77
fi
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
ROOT=${abs_top_builddir:-$(dirname "$0")/..}
source ${TESTDIR}/common
skip_test_linked_with_asan "${SWTPM_EXE}"
# Determine a test user and group
id -u nobody &>/dev/null && export TESTUSER=nobody
export TESTGROUP="$(getent group $(id -g "${TESTUSER}") | cut -d':' -f1)"
if [ -z "${TESTUSER}" ] || [ -z "${TESTGROUP}" ]; then
echo "Could not find suitable user/group for testing with."
exit 77
fi
TESTDIR=${abs_top_testdir:-$(dirname "$0")}
ROOT=${abs_top_builddir:-$(dirname "$0")/..}
source ${TESTDIR}/common
cd "$(dirname "$0")"
export SWTPM_INTERFACE=cuse
bash _test_tpm2_file_permissions
ret=$?
[ $ret -ne 0 ] && [ $ret -ne 77 ] && exit $ret
export SWTPM_INTERFACE=socket+socket
export SWTPM_SERVER_NAME=localhost
export SWTPM_SERVER_PORT=65458
export SWTPM_CTRL_PORT=65459
bash _test_tpm2_file_permissions
ret=$?
[ $ret -ne 0 ] && [ $ret -ne 77 ] && exit $ret
exit 0