diff options
author | David Howells <dhowells@redhat.com> | 2011-09-01 11:13:57 +0100 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2011-11-15 18:44:33 +0000 |
commit | 9fff5e86992c81b23f14fcb94c2b6d2e4c888ac5 (patch) | |
tree | ce83627f49f3a5882c92e0b7b096cc057fb7f85d | |
parent | e96a3dfae2882ea6e6af7fdfac7f8072b2d3a3d0 (diff) | |
download | keyutils-9fff5e86992c81b23f14fcb94c2b6d2e4c888ac5.tar.gz |
TEST: Unlink can now take a single argument
Remove the unlink argument validity check that checks that just one argument
fails as it's now valid to pass a single argument.
Add a test for the unlink with single argument case (which searches the process
keyrings for all instances of the specified key and attempts to unlink them
all).
Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r-- | tests/keyctl/unlink/all/runtest.sh | 103 | ||||
-rw-r--r-- | tests/keyctl/unlink/noargs/runtest.sh | 9 | ||||
-rw-r--r-- | tests/toolbox.inc.sh | 25 |
3 files changed, 134 insertions, 3 deletions
diff --git a/tests/keyctl/unlink/all/runtest.sh b/tests/keyctl/unlink/all/runtest.sh new file mode 100644 index 0000000..2014470 --- /dev/null +++ b/tests/keyctl/unlink/all/runtest.sh @@ -0,0 +1,103 @@ +#!/bin/sh + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +result=PASS + +if keyutils_at_or_later_than 1.5 +then + echo "++++ BEGINNING TEST" >$OUTPUTFILE + + # create a keyring and attach it to the session keyring + marker "ADD KEYRING" + create_keyring wibble @s + expect_keyid keyringid + + # stick a key in the keyring + marker "ADD KEY" + create_key user lizard gizzard $keyringid + expect_keyid keyid + + # check that we can list it + marker "LIST KEYRING WITH ONE" + list_keyring $keyringid + expect_keyring_rlist rlist $keyid + + # dispose of the key and make sure it gets destroyed + marker "UNLINK KEY FROM KEYRING" + unlink_key --wait $keyid $keyringid + + # trying a tree-wide unlink should succeed with no links removed + marker "CHECK NO UNLINK KEY FROM TREE" + unlink_key $keyid + expect_unlink_count n_unlinked 0 + + # check that the keyring is now empty + marker "LIST KEYRING" + list_keyring $keyringid + expect_keyring_rlist rlist empty + + # create a key to be massively linked + marker "ADD MULTI KEY" + create_key user lizard gizzard $keyringid + expect_keyid keyid + + # stick twenty keyrings in the keyring with twenty links + marker "ADD TWENTY KEYRINGS WITH LINKS" + subrings= + for ((i=0; i<20; i++)) + do + create_keyring ring$i $keyringid + expect_keyid x + keys="$keys $x" + subrings="$subrings $x" + list_keyring $keyringid + expect_keyring_rlist rlist $x + + link_key $keyid $x + list_keyring $x + expect_keyring_rlist rlist $keyid + done + + marker "SHOW" + if ! keyctl show >>$OUTPUTFILE 2>&1 + then + failed + fi + + # delete all the keys from the keyring tree + marker "REMOVE ALL LINKS TO KEY" + unlink_key $keyid + expect_unlink_count n_unlinked 21 + + # there should not now be any left + unlink_key $keyid + expect_unlink_count n_unlinked 0 + + # check that the key is no longer in the main keyring + marker "CHECK GONE" + list_keyring $keyringid + expect_keyring_rlist rlist $keyid --absent + + for i in $subrings + do + list_keyring $i + expect_keyring_rlist rlist $keyid --absent + done + + # remove the keyring we added + marker "UNLINK KEY" + unlink_key $keyringid @s + + echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE +else + echo "++++ SKIPPING TEST" >>$OUTPUTFILE + marker SKIP on version +fi + +# --- then report the results in the database --- +toolbox_report_result $TEST $result diff --git a/tests/keyctl/unlink/noargs/runtest.sh b/tests/keyctl/unlink/noargs/runtest.sh index a33ff3c..1ed9f26 100644 --- a/tests/keyctl/unlink/noargs/runtest.sh +++ b/tests/keyctl/unlink/noargs/runtest.sh @@ -13,9 +13,12 @@ echo "++++ BEGINNING TEST" >$OUTPUTFILE marker "NO ARGS" expect_args_error keyctl unlink -# check that one argument fails correctly -marker "ONE ARGS" -expect_args_error keyctl unlink 0 +if keyutils_older_than 1.5 +then + # check that one argument fails correctly + marker "ONE ARGS" + expect_args_error keyctl unlink 0 +fi # check that three arguments fails correctly marker "THREE ARGS" diff --git a/tests/toolbox.inc.sh b/tests/toolbox.inc.sh index 26d5f2e..058e398 100644 --- a/tests/toolbox.inc.sh +++ b/tests/toolbox.inc.sh @@ -749,6 +749,31 @@ function unlink_key () ############################################################################### # +# extract a message about the number of keys unlinked +# +############################################################################### +function expect_unlink_count () +{ + my_varname=$1 + + my_nunlinks="`tail -1 $OUTPUTFILE`" + + if ! expr "$my_nunlinks" : '^[0-9][0-9]* links removed$' + then + failed + fi + + my_nunlinks=`echo $my_nunlinks | awk '{printf $1}'` + eval $my_varname="\"$my_nunlinks\"" + + if [ $# == 2 -a $my_nunlinks != $2 ] + then + failed + fi +} + +############################################################################### +# # update a key from a keyring # ############################################################################### |