#!/bin/sh
set -e

echo "@@@ Running upstream tests (root required) @@@"

if [ "`id -u`" -ne 0 ]
then
	echo "These tests must be run as root. Aborting." >&2
	exit 1
fi

echo "## Preparation ##"
cp pam_cap/capability.conf pam_cap/sudotest.conf "$AUTOPKGTEST_TMP"/
cd "$AUTOPKGTEST_TMP"

echo "## libcap2 tests ##"
echo exit | /usr/lib/libcap2/tests/uns_test
# Negative test cases print to stderr
/usr/lib/libcap2/tests/libcap_launch_test

echo "## PSX tests ##"
/usr/lib/libcap2/tests/libcap_psx_launch_test
# Negative test cases print to stderr

echo "## PAM tests ##"
/usr/lib/libcap2/tests/test_pam_cap
/usr/lib/libcap2/tests/test_pam_cap root 0x0 0x0 0x0 config=./capability.conf
/usr/lib/libcap2/tests/test_pam_cap root 0x0 0x0 0x0 config=./sudotest.conf
/usr/lib/libcap2/tests/test_pam_cap alpha 0x0 0x0 0x0 config=./capability.conf
/usr/lib/libcap2/tests/test_pam_cap alpha 0x0 0x1 0x80 config=./sudotest.conf
/usr/lib/libcap2/tests/test_pam_cap beta 0x0 0x1 0x0 config=./sudotest.conf
/usr/lib/libcap2/tests/test_pam_cap gamma 0x0 0x0 0x81 config=./sudotest.conf
/usr/lib/libcap2/tests/test_pam_cap delta 0x41 0x80 0x41 config=./sudotest.conf
