summaryrefslogtreecommitdiff
path: root/tests/keyctl/requesting/bad-args/runtest.sh
blob: cf822e260cdf75a872e6dd64dee432431f85df7b (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash

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


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

result=PASS
if [ $skip_install_required -eq 1 ]
then
    echo "++++ SKIPPING TEST" >$OUTPUTFILE
    marker "SKIP BECAUSE TEST REQUIRES FULL INSTALL (for /sbin/request-key)"
    toolbox_report_result $TEST PASS
    exit 0
else
    echo "++++ BEGINNING TEST" >$OUTPUTFILE
fi

# check that an empty key type fails correctly
marker "CHECK EMPTY KEY TYPE"
request_key --fail "" debug:wibble
expect_error EINVAL
request_key --fail "" debug:wibble @p
expect_error EINVAL
request_key_callout --fail "" debug:wibble stuff
expect_error EINVAL
request_key_callout --fail "" debug:wibble stuff @p
expect_error EINVAL
prequest_key_callout --fail stuff "" debug:wibble
expect_error EINVAL
prequest_key_callout --fail stuff "" debug:wibble @p
expect_error EINVAL

# check that an unsupported key type fails correctly
marker "CHECK UNSUPPORTED KEY TYPE"
request_key --fail "lizardsgizzards" debug:wibble
expect_error ENOKEY
request_key --fail "lizardsgizzards" debug:wibble @p
expect_error ENOKEY
request_key_callout --fail "lizardsgizzards" debug:wibble stuff
expect_error ENOKEY
request_key_callout --fail "lizardsgizzards" debug:wibble stuff @p
expect_error ENOKEY
prequest_key_callout --fail stuff "lizardsgizzards" debug:wibble
expect_error ENOKEY
prequest_key_callout --fail stuff "lizardsgizzards" debug:wibble @p
expect_error ENOKEY

# check that an invalid key type fails correctly
# - key types beginning with a dot are internal use only
marker "CHECK INVALID KEY TYPE"
request_key --fail ".user" debug:wibble
expect_error EPERM
request_key --fail ".user" debug:wibble @p
expect_error EPERM
request_key_callout --fail ".user" debug:wibble stuff
expect_error EPERM
request_key_callout --fail ".user" debug:wibble stuff @p
expect_error EPERM
prequest_key_callout --fail stuff ".user" debug:wibble
expect_error EPERM
prequest_key_callout --fail stuff ".user" debug:wibble @p
expect_error EPERM

# check that an maximum length invalid key type fails correctly
marker "CHECK MAXLEN INVALID KEY TYPE"
request_key --fail $maxtype debug:wibble
expect_error ENOKEY
request_key --fail $maxtype debug:wibble @p
expect_error ENOKEY
request_key_callout --fail $maxtype debug:wibble stuff
expect_error ENOKEY
request_key_callout --fail $maxtype debug:wibble stuff @p
expect_error ENOKEY

# check that an overlong key type fails correctly
marker "CHECK OVERLONG KEY TYPE"
request_key --fail a$maxtype debug:wibble
expect_error EINVAL
request_key --fail a$maxtype debug:wibble @p
expect_error EINVAL
request_key_callout --fail a$maxtype debug:wibble stuff
expect_error EINVAL
request_key_callout --fail a$maxtype debug:wibble stuff @p
expect_error EINVAL

# check that an max length key description works correctly
marker "CHECK MAXLEN DESC"
request_key --fail user $maxdesc
expect_error ENOKEY

# This doesn't work on MIPS earlier 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
	marker "CHECK OVERLONG DESC"
	request_key --fail user a$maxdesc
	expect_error EINVAL
fi

# check that a max length callout info works correctly
marker "CHECK MAXLEN CALLOUT"
request_key_callout --fail user wibble $maxdesc @p
expect_error ENOKEY

# check that an overlong callout info fails correctly
marker "CHECK OVERLONG CALLOUT"
request_key_callout --fail user wibble a$maxcall
expect_error EINVAL

# check that a max length callout info works correctly
marker "CHECK MAXLEN PIPED CALLOUT"
prequest_key_callout --fail $maxcall user wibble @p
expect_error ENOKEY

# check that an overlong callout info fails correctly
marker "CHECK OVERLONG PIPED CALLOUT"
prequest_key_callout --fail a$maxcall user wibble
expect_error EINVAL

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

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