Skip to contentSkip to conversation

TEST: Add keyctl xpadd tests

PATCH New Mat Martineau 1 participant 1 message Jun 13, 2017 Keys/keyrings

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/6 TEST: Add keyctl xpadd tests

---
 tests/keyctl/xpadd/bad-args/runtest.sh | 86 ++++++++++++++++++++++++++++++++++
 tests/keyctl/xpadd/noargs/runtest.sh   | 31 ++++++++++++
 tests/keyctl/xpadd/useradd/runtest.sh  | 68 +++++++++++++++++++++++++++
 tests/toolbox.inc.sh                   | 29 ++++++++++++
 4 files changed, 214 insertions(+)
 create mode 100644 tests/keyctl/xpadd/bad-args/runtest.sh
 create mode 100644 tests/keyctl/xpadd/noargs/runtest.sh
 create mode 100644 tests/keyctl/xpadd/useradd/runtest.sh
tests/keyctl/xpadd/bad-args/runtest.sh new file +86 -0
new file mode 100644
index 0000000..d321fd6
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+. ../../../prepare.inc.sh
+. ../../../toolbox.inc.sh
+
+
+# ---- do the actual testing ----
+
+result=PASS
+echo "++++ BEGINNING TEST" >$OUTPUTFILE
+
+# check that non-hexadecimal input fails correctly
+marker "CHECK NON-HEXADECIMAL INPUT"
+xpcreate_key --failarg nothex user wibble @p
+
+# check that odd-length hexadecimal input fails correctly
+marker "CHECK ODD-LENGTH HEXADECIMAL INPUT"
+xpcreate_key --failarg "00 01 2 03" user wibble @p
+
+# check that non-hexadecimal trailing input fails correctly
+marker "CHECK TRAILING INPUT"
+xpcreate_key --failarg 0123. user wibble @p
+
+# check that an empty key type fails correctly
+marker "CHECK EMPTY KEY TYPE"
+xpcreate_key --fail 0f1e2c3d "" wibble @p
+expect_error EINVAL
+
+# check that an unsupported key type fails correctly
+marker "CHECK UNSUPPORTED KEY TYPE"
+xpcreate_key --fail 0f1e2c3d lizardsgizzards wibble @p
+expect_error ENODEV
+
+# check that an invalid key type fails correctly
+marker "CHECK INVALID KEY TYPE"
+xpcreate_key --fail 0f1e2c3d .user wibble @p
+expect_error EPERM
+
+# check that an maximum length invalid key type fails correctly
+marker "CHECK MAXLEN KEY TYPE"
+xpcreate_key --fail 0f1e2c3d $maxtype wibble @p
+expect_error ENODEV
+
+# check that an overlong key type fails correctly
+marker "CHECK OVERLONG KEY TYPE"
+xpcreate_key --fail 0f1e2c3d a$maxtype wibble @p
+expect_error EINVAL
+
+# check that creation of a keyring with non-empty payload fails correctly
+marker "CHECK ADD KEYRING WITH PAYLOAD"
+xpcreate_key --fail 0f1e2c3d keyring wibble @p
+expect_error EINVAL
+
+# check that an max length key description works correctly
+if [ $PAGE_SIZE -lt $maxsquota ]
+then
+    marker "CHECK MAXLEN DESC"
+    xpcreate_key 0f1e2c3d user $maxdesc @p
+    expect_keyid keyid
+else
+    marker "CHECK MAXLEN DESC FAILS WITH EDQUOT"
+    xpcreate_key --fail 0f1e2c3d user $maxdesc @p
+    expect_error EDQUOT
+fi
+
+# This doesn't work on MIPS earler than 3.19 because of a kernel bug
+kver=`uname -r`
+kmch=`uname -m`
+if kernel_at_or_later_than 3.19 ||
+	[ "$kmch" != "mips" -a "$kmch" != "mips64" ]
+then
+	# check that an overlong key description fails correctly (>4095 inc NUL)
+	marker "CHECK OVERLONG DESC"
+	xpcreate_key --fail 0f1e2c3d user a$maxdesc @p
+	expect_error EINVAL
+fi
+
+# check that a bad key ID fails correctly
+marker "CHECK BAD KEY ID"
+xpcreate_key --fail 0f1e2c3d user wibble 0
+expect_error EINVAL
+
+echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE
+
+# --- then report the results in the database ---
+toolbox_report_result $TEST $result
tests/keyctl/xpadd/noargs/runtest.sh new file +31 -0
new file mode 100644
index 0000000..cde2f8f
@@ -0,0 +1,31 @@
+#!/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 "ADD NO ARGS"
+expect_args_error keyctl xpadd
+
+# check that one argument fails correctly
+marker "ADD ONE ARG"
+expect_args_error keyctl xpadd user
+
+# check that two arguments fail correctly
+marker "ADD TWO ARGS"
+expect_args_error keyctl xpadd user wibble
+
+# check that four arguments fail correctly
+marker "ADD FOUR ARGS"
+expect_args_error keyctl xpadd user wibble @s x
+
+echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE
+
+# --- then report the results in the database ---
+toolbox_report_result $TEST $result
tests/keyctl/xpadd/useradd/runtest.sh new file +68 -0

68 lines not on this page · raw message

tests/toolbox.inc.sh +29 -0
index 602218c..5173c18 100644
@@ -345,6 +345,35 @@ function pcreate_key ()
 
 ###############################################################################
 #
+# create a key and attach it to the new keyring, piping in hex data
+#
+###############################################################################
+function xpcreate_key ()
+{
+    my_exitval=0
+    if [ "x$1" = "x--fail" ]
+    then
+	my_exitval=1
+	shift
+    elif [ "x$1" = "x--failarg" ]
+    then
+	my_exitval=2
+	shift
+    fi
+
+    data="$1"
+    shift
+
+    echo echo -n -e $data \| keyctl xpadd "$@" >>$OUTPUTFILE
+    echo -n -e $data | keyctl xpadd "$@" >>$OUTPUTFILE 2>&1
+    if [ $? != $my_exitval ]
+    then
+	failed
+    fi
+}
+
+###############################################################################
+#
 # create a key and attach it to the new keyring, piping in the data
 #
 ###############################################################################
Signature · 1 line
2.13.1