From c39fc85f8045bb24f773a3eb5dee7738cdc4339f Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 13 Jun 2020 10:06:15 -0700 Subject: cli-tests/t_v1_policy: clean up user keyrings at end of test The test user's user keyring is still linked into root's user keyring at the end of the test. This is making the test flaky, as there is a failure that only occurs the first time it is run. Fix the test to restore the initial state. This makes it consistently fail (to be fixed by the next commit). --- cli-tests/common.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cli-tests/common.sh') diff --git a/cli-tests/common.sh b/cli-tests/common.sh index fcebfd6..79b42ae 100644 --- a/cli-tests/common.sh +++ b/cli-tests/common.sh @@ -128,6 +128,18 @@ _user_do_and_expect_failure() _expect_failure "_user_do '$1'" } +# Clear the test user's user keyring and unlink it from root's user keyring, if +# it is linked into it. +_cleanup_user_keyrings() +{ + local ringid + + ringid=$(_user_do "keyctl show @u" | awk '/keyring: _uid/{print $1}') + + _user_do "keyctl clear $ringid" + keyctl unlink "$ringid" @u &> /dev/null || true +} + # Gives the test a new session keyring which contains the test user's keyring # but not root's keyring. Also clears the test user's keyring. This must be # called at the beginning of the test script as it may re-execute the script. -- cgit v1.2.3