summaryrefslogtreecommitdiff
path: root/tests/keyctl/search/bad-args/runtest.sh
blob: 21287906eb5339ee9e26edb8dcb39c3366c565ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash

. ../../../prepare.inc.sh
. ../../../toolbox.inc.sh


# ---- do the actual testing ----

result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE

# check that an empty key type fails correctly
marker "CHECK EMPTY KEY TYPE"
search_for_key --fail @s "" wibble
expect_error EINVAL
search_for_key --fail @s "" wibble @p
expect_error EINVAL

# check that an unsupported key type fails correctly
marker "CHECK UNSUPPORTED KEY TYPE"
search_for_key --fail @s lizardsgizzards wibble
expect_error ENOKEY
search_for_key --fail @s lizardsgizzards wibble @p
expect_error ENOKEY

# check that an invalid key type fails correctly
marker "CHECK INVALID KEY TYPE"
search_for_key --fail @s .user wibble
expect_error EPERM
search_for_key --fail @s .user wibble @p
expect_error EPERM

# check that an overlong key type fails correctly
marker "CHECK OVERLONG KEY TYPE"
search_for_key --fail @s $maxtype wibble
expect_error ENOKEY
search_for_key --fail @s a$maxtype wibble @p
expect_error EINVAL

# check that an max length key description works correctly (4095 inc NUL)
marker "CHECK MAXLEN DESC"
search_for_key --fail @s user $maxdesc
expect_error ENOKEY

search_for_key --fail @s user $maxdesc @p
expect_error ENOKEY

# 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"
	search_for_key --fail @s user a$maxdesc
	expect_error EINVAL
fi

search_for_key --fail @s user a$maxdesc @p
expect_error EINVAL

# check that a bad key ID fails correctly
marker "CHECK BAD KEY ID"
search_for_key --fail @s user wibble -2000
expect_error EINVAL

# create a non-keyring key
marker "CREATE KEY"
create_key --new=keyid user a a @s

# search the non-keyring key
marker "SEARCH KEY"
search_for_key --fail $keyid user a
expect_error ENOTDIR
search_for_key --fail $keyid user a @p
expect_error ENOTDIR

# dispose of the key
marker "UNLINK KEY"
unlink_key $keyid @s

echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE

# --- then report the results in the database ---
toolbox_report_result $TEST $result