summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2019-08-16 11:29:35 +0100
committerDavid Howells <dhowells@redhat.com>2019-08-19 15:42:00 +0100
commit9a99f28afbabb48d2164ab7819b3fd981c978d46 (patch)
treeba16cea4bf6081bb93dba02e445c74267d600f51
parent877a60343810a46d4d2c3b66287211f12f1035d5 (diff)
downloadkeyutils-9a99f28afbabb48d2164ab7819b3fd981c978d46.tar.gz
test: Check that KEYCTL_SESSION_TO_PARENT works
Check that the KEYCTL_SESSION_TO_PARENT keyctl function works. Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r--tests/keyctl/session/valid2/runtest.sh46
-rw-r--r--tests/toolbox.inc.sh22
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/keyctl/session/valid2/runtest.sh b/tests/keyctl/session/valid2/runtest.sh
new file mode 100644
index 0000000..ca5c9fb
--- /dev/null
+++ b/tests/keyctl/session/valid2/runtest.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+. ../../../prepare.inc.sh
+. ../../../toolbox.inc.sh
+
+
+# ---- do the actual testing ----
+
+result=PASS
+echo "++++ BEGINNING TEST" >$OUTPUTFILE
+
+# Replace the script's session keyring with an anonymous keyring
+marker "ANON SESSION TO PARENT"
+id_key @s
+expect_keyid ses1
+new_session_to_parent
+id_key @s
+expect_keyid ses2
+
+if [ $ses2 = $ses1 ]
+then
+ failed
+fi
+
+describe_key @s "@"
+expect_key_rdesc rdesc "keyring@.*@.*@.*@_ses"
+
+# Replace the script's session keyring with a named keyring
+marker "NAMED SESSION TO PARENT"
+new_session_to_parent lizard
+id_key @s
+expect_keyid ses3
+
+if [ $ses3 = $ses2 -o $ses3 = $ses1 ]
+then
+ failed
+fi
+
+describe_key @s "@"
+expect_key_rdesc rdesc "keyring@.*@.*@.*@lizard"
+
+
+echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE
+
+# --- then report the results in the database ---
+toolbox_report_result $TEST $result
diff --git a/tests/toolbox.inc.sh b/tests/toolbox.inc.sh
index a281221..2b432a8 100644
--- a/tests/toolbox.inc.sh
+++ b/tests/toolbox.inc.sh
@@ -1028,6 +1028,28 @@ function new_session ()
###############################################################################
#
+# Create a new session and attach to the parent process (ie. the script)
+#
+###############################################################################
+function new_session_to_parent ()
+{
+ my_exitval=0
+ if [ "x$1" = "x--fail" ]
+ then
+ my_exitval=1
+ shift
+ fi
+
+ echo keyctl new_session "$@" >>$OUTPUTFILE
+ keyctl new_session "$@" >>$OUTPUTFILE 2>&1
+ if [ $? != $my_exitval ]
+ then
+ failed
+ fi
+}
+
+###############################################################################
+#
# instantiate a key
#
###############################################################################