diff options
author | David Howells <dhowells@redhat.com> | 2013-12-17 18:07:23 +0000 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2013-12-17 18:07:23 +0000 |
commit | f1e414a3e8ef6761666df7ed6ad24559f8e1cc31 (patch) | |
tree | 4ca0ffb90186a8b93fc61b1fe8925aa5ccf7166d | |
parent | d9a53cbab42c293962f2f78f7190253fc73bd32e (diff) | |
download | keyutils-f1e414a3e8ef6761666df7ed6ad24559f8e1cc31.tar.gz |
TEST: Key invalidation
Test the key invalidation functionality.
Signed-off-by: David Howells <dhowells@redhat.com>
-rw-r--r-- | tests/keyctl/invalidate/bad-args/runtest.sh | 34 | ||||
-rw-r--r-- | tests/keyctl/invalidate/noargs/runtest.sh | 23 | ||||
-rw-r--r-- | tests/keyctl/invalidate/valid/runtest.sh | 71 | ||||
-rw-r--r-- | tests/toolbox.inc.sh | 22 |
4 files changed, 150 insertions, 0 deletions
diff --git a/tests/keyctl/invalidate/bad-args/runtest.sh b/tests/keyctl/invalidate/bad-args/runtest.sh new file mode 100644 index 0000000..72fc2c4 --- /dev/null +++ b/tests/keyctl/invalidate/bad-args/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +result=PASS +echo "++++ BEGINNING TEST" >$OUTPUTFILE + +# check that a bad key ID fails correctly +marker "CHECK INVALIDATE BAD KEY ID" +invalidate_key --fail 0 +expect_error EINVAL + +# create a key +marker "CREATE KEY" +create_key user lizard gizzard @s +expect_keyid keyid + +# and dispose of it +marker "UNLINK KEY" +unlink_key --wait $keyid @s + +# check that a non-existent key ID fails correctly +marker "CHECK INVALIDATE NON-EXISTENT KEY ID" +invalidate_key --fail $keyid +expect_error ENOKEY + +echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE + +# --- then report the results in the database --- +toolbox_report_result $TEST $result diff --git a/tests/keyctl/invalidate/noargs/runtest.sh b/tests/keyctl/invalidate/noargs/runtest.sh new file mode 100644 index 0000000..51cb045 --- /dev/null +++ b/tests/keyctl/invalidate/noargs/runtest.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +result=PASS +echo "++++ BEGINNING TEST" >$OUTPUTFILE + +# check that no arguments fails correctly +marker "NO ARGS" +expect_args_error keyctl invalidate + +# check that two arguments fail correctly +marker "TWO ARGS" +expect_args_error keyctl invalidate 0 0 + +echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE + +# --- then report the results in the database --- +toolbox_report_result $TEST $result diff --git a/tests/keyctl/invalidate/valid/runtest.sh b/tests/keyctl/invalidate/valid/runtest.sh new file mode 100644 index 0000000..6274164 --- /dev/null +++ b/tests/keyctl/invalidate/valid/runtest.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +. ../../../prepare.inc.sh +. ../../../toolbox.inc.sh + + +# ---- do the actual testing ---- + +result=PASS +echo "++++ BEGINNING TEST" >$OUTPUTFILE + +# create a keyring and attach it to the session keyring +marker "ADD KEYRING" +create_keyring wibble @s +expect_keyid keyringid + +# check that we have an empty keyring +marker "LIST KEYRING" +list_keyring $keyringid +expect_keyring_rlist rlist empty + +# 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 2" +list_keyring $keyringid +expect_keyring_rlist rlist $keyid + +# invalidate the key +marker "INVALIDATE KEY" +invalidate_key $keyid + +# check that it's now empty again +marker "LIST KEYRING 3" +list_keyring $keyringid +expect_keyring_rlist rlist empty + +# stick another key in the keyring +marker "ADD KEY" +create_key user lizard2 gizzard $keyringid +expect_keyid keyid + +# check that we can list it +marker "LIST KEYRING 4" +list_keyring $keyringid +expect_keyring_rlist rlist $keyid + +# invalidate the keyring +marker "INVALIDATE KEYRING" +invalidate_key $keyringid + +# need to wait for the gc +sleep 1 + +# check that the keyring no longer exists +marker "CHECK KEYRING" +list_keyring --fail $keyringid +expect_error ENOKEY + +# check that the key got gc'd also +marker "CHECK KEY" +describe_key --fail $keyid +expect_error ENOKEY + +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 8cc5c04..2035003 100644 --- a/tests/toolbox.inc.sh +++ b/tests/toolbox.inc.sh @@ -1036,6 +1036,28 @@ function timeout_key () ############################################################################### # +# Invalidate a key +# +############################################################################### +function invalidate_key () +{ + my_exitval=0 + if [ "x$1" = "x--fail" ] + then + my_exitval=1 + shift + fi + + echo keyctl invalidate $1 >>$OUTPUTFILE + keyctl invalidate $1 >>$OUTPUTFILE 2>&1 + if [ $? != $my_exitval ] + then + failed + fi +} + +############################################################################### +# # Make sure we sleep at least N seconds # ############################################################################### |