diff options
author | David Howells <dhowells@redhat.com> | 2019-10-31 13:22:23 +0000 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2020-07-07 16:58:07 +0100 |
commit | 496a09a43713cfe09877fcba82db72ce5902f781 (patch) | |
tree | b4caf269872728a5ca8cdc946ce7aaf845867d7d /tests | |
parent | 1570dce7a114e8b907e7b80c56bb798a888675c6 (diff) | |
download | keyutils-496a09a43713cfe09877fcba82db72ce5902f781.tar.gz |
Add the ability to supply filters to watches set with keyctl
Add the ability to supply filters to watches set with "keyctl watch" and
"keyctl watch_session".
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/keyctl/watch/bad-args/runtest.sh | 45 | ||||
-rw-r--r-- | tests/keyctl/watch/noargs/runtest.sh | 27 | ||||
-rw-r--r-- | tests/toolbox.inc.sh | 94 |
3 files changed, 166 insertions, 0 deletions
diff --git a/tests/keyctl/watch/bad-args/runtest.sh b/tests/keyctl/watch/bad-args/runtest.sh new file mode 100644 index 0000000..c3dcab5 --- /dev/null +++ b/tests/keyctl/watch/bad-args/runtest.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +if [ $have_notify = 0 ] +then + toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF NOTIFICATION SUPPORT" + exit 0 +fi + +result=PASS +echo "++++ BEGINNING TEST" >$OUTPUTFILE + +# Attempt to watch an invalid key +marker "CHECK WATCH INVALID KEY" +watch_key --fail 0 +expect_error EINVAL + +# Add a user key to the session keyring for us to play with +marker "ADD USER KEY" +create_key --new=keyid user wibble stuff @s + +# Remove the key we just added +marker "UNLINK KEY" +unlink_key --wait $keyid @s + +# It should fail when we attempt to watch it +marker "UPDATE UNLINKED KEY" +watch_key --fail $keyid +expect_error ENOKEY + +# Try a number of dodgy filters +marker "CHECK DODGY FILTERS" +watch_key --fail2 -fZ @s +watch_key --fail2 -fZ -fQ @s +watch_key --fail2 -f: @s + +echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE + +# --- then report the results in the database --- +toolbox_report_result $TEST $result diff --git a/tests/keyctl/watch/noargs/runtest.sh b/tests/keyctl/watch/noargs/runtest.sh new file mode 100644 index 0000000..e2bc7d7 --- /dev/null +++ b/tests/keyctl/watch/noargs/runtest.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +result=PASS +echo "++++ BEGINNING TEST" >$OUTPUTFILE + +# check that no arguments fails correctly +marker "WATCH NO ARGS" +expect_args_error keyctl watch + +# check that two arguments fail correctly +marker "WATCH TWO ARGS" +expect_args_error keyctl watch @s @s + +# Try a dodgy filter +marker "CHECK BAD FILTER" +expect_args_error keyctl watch_key -f 0 + +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 81d639c..609a6c7 100644 --- a/tests/toolbox.inc.sh +++ b/tests/toolbox.inc.sh @@ -1834,6 +1834,100 @@ function set_gc_delay() ############################################################################### # +# watch a key +# +############################################################################### +function watch_key () +{ + my_exitval=0 + if [ "x$1" = "x--fail" ] + then + my_exitval=1 + shift + elif [ "x$1" = "x--fail2" ] + then + my_exitval=2 + shift + fi + + echo keyctl watch "$@" >>$OUTPUTFILE + nice --adjustment=-3 keyctl watch "$@" >>$PWD/notify.log 2>>$OUTPUTFILE + if [ $? != $my_exitval ] + then + failed + fi +} + +############################################################################### +# +# Check for a notification +# +# expect_notification [--filter=[i|p|l|n|c|r|v|s]] <keyid> <op> [<alt>] +# +############################################################################### +function expect_notification () +{ + local want + + local filter="" + case "x$1" in + x--filter*) + case $1 in + --filter=) filter=;; + --filter=i) filter=inst;; + --filter=p) filter=upd;; + --filter=l) filter=link;; + --filter=n) filter=unlk;; + --filter=c) filter=clr;; + --filter=r) filter=rev;; + --filter=v) filter=inv;; + --filter=s) filter=attr;; + *) + echo "Unknown param $1 to expect_notification()" >&2 + exit 2 + ;; + esac + shift + ;; + esac + + if [ $# = 2 ] + then + want="$1 $2" + op=$2 + elif [ $# = 3 ] + then + want="$1 $2 $3" + op=$2 + else + echo "Wrong parameters to expect_notification" >&2 + exit 2 + fi + + if tail -3 $PWD/notify.log | grep "^${want}\$" >/dev/null + then + echo "Found notification '$*'" >>$OUTPUTFILE + if [ "$filter" != "" -a $op != "$filter" ] + then + echo "Notification '$want' should be filtered" >&2 + failed + fi + else + echo "Notification '$*' not present" >>$OUTPUTFILE + if [ "$filter" = "" ] + then + echo "Missing notification '$want'" >&2 + failed + elif [ $op = "$filter" ] + then + echo "Notification unexpectedly filtered '$want' $filter" >&2 + failed + fi + fi +} + +############################################################################### +# # Note the creation of a new key # # expect_new_key <variable_name> <keyring> [<expected_id>] |