From d12ee1848dacd4bb6d96240c121dff7f30818f81 Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Thu, 25 Jul 2019 01:23:15 +0300
Subject: [PATCH] Use `sudo journalctl` for non-privileged user in AA tests

Access to system journal is restricted for user after switching to
Debian. AppArmor tests need to check system log with journalctl but
without proper permissions they fail.
Adding sudo for non-root users allows to check the log entries and
compare the output with expected.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
---
 run-aa-test | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/run-aa-test b/run-aa-test
index 347676e..2ed2147 100755
--- a/run-aa-test
+++ b/run-aa-test
@@ -124,7 +124,14 @@ sleep 3
 
 # Get audit information from journal
 AUDIT_FILE=${TMP_DIR}/AUDIT
-journalctl -S "${START_TIME}" -t audit -o cat > ${AUDIT_FILE}
+
+uid=$(id -u)
+JOURNALCTL="journalctl"
+if [ "${UID}" != "0" ]
+then
+	JOURNALCTL="sudo journalctl"
+fi
+${JOURNALCTL} -S "${START_TIME}" -t audit -o cat > ${AUDIT_FILE}
 
 echo "#=== ${TEST_TITLE} ==="
 
-- 
GitLab