Fix EXPIRE status message.
[pwmd.git] / tests / acl.test
blobfce012af57a628ec4e8d237c41e80962dc6c34b9
1 #!/bin/bash
2 source common.sh
3 source import-common.sh
5 do_import acl
7 cat > config << EOF
8 [global]
9 log_level=9
10 #enable_logging=true
11 invoking_user=nobody
12 [acl]
13 passphrase_file=`pwd`/passphrase.key
14 EOF
16 launch_pwmd acl
18 begin_test
19 test_header "Test 1. Invoking user '$USER' with _acl 'nobody'."
20 echo -ne 'LIST --recurse' | pwmc $PWMC_ARGS acl > result
21 cmp acl.result1 result
22 rm -f result
24 echo
25 test_header "Test 2. Retrieve content (fail)."
26 set +o errexit
27 echo -ne 'GET c' | pwmc $PWMC_ARGS acl > result
28 if [ ${PIPESTATUS[1]} == 0 ]; then
29 echo "The previous command should have failed. Stopping."
30 exit 1
33 set -e
34 rm -f result
36 echo
37 test_header "Test 3. Create new path."
38 echo -ne 'acl\tpath\tacl path value' | pwmc $PWMC_ARGS --inquire STORE -S acl
40 echo
41 test_header "Test 4. Delete _acl attribute of child (owner)."
42 echo -ne 'ATTR DELETE _acl acl\tpath' | pwmc $PWMC_ARGS -S acl
44 echo
45 test_header "Test 5. Access child (_acl re-added)."
46 echo -ne 'ATTR LIST acl\tpath' | pwmc $PWMC_ARGS acl > result
47 test -s result
48 rm -f result
50 echo
51 test_header "Test 6. Change ownership of child element."
52 echo -ne "ATTR SET _acl acl\tpath nobody,$USER" | pwmc $PWMC_ARGS -S acl
54 echo
55 test_header "Test 7. Access child (not owner)."
56 echo -ne 'ATTR LIST acl\tpath' | pwmc $PWMC_ARGS acl > result
57 test -s result
58 rm -f result
60 echo
61 test_header "Test 8. Delete child element (fail)."
62 set +o errexit
63 echo -ne 'DELETE acl\tpath' | pwmc $PWMC_ARGS acl
64 if [ ${PIPESTATUS[1]} == 0 ]; then
65 echo "The previous command should have failed. Stopping."
66 exit 1
69 set -e
70 echo
71 test_header "Test 9. Change ownership of child element (fail)."
72 set +o errexit
73 echo -ne "ATTR SET _acl acl\tpath $USER" | pwmc $PWMC_ARGS -S acl
74 if [ ${PIPESTATUS[1]} == 0 ]; then
75 echo "The previous command should have failed. Stopping."
76 exit 1
79 set -e
80 echo
81 test_header "Test 10. Create child element content (fail)."
82 set +o errexit
83 echo -ne 'acl\tpath\tupdate' | pwmc $PWMC_ARGS --inquire STORE acl
84 if [ ${PIPESTATUS[1]} == 0 ]; then
85 echo "The previous command should have failed. Stopping."
86 exit 1
89 set -e
90 echo
91 test_header "Test 11. Create parent element content."
92 echo -ne 'acl\tacl value' | pwmc $PWMC_ARGS --inquire STORE -S acl
93 echo -ne 'GET acl' | pwmc $PWMC_ARGS acl > result
94 cmp acl.result11 result
95 rm -f result
97 set -e
98 echo
99 test_header "Test 13. List attributes of un-owned root."
100 echo -ne 'ATTR LIST no-such-user' | pwmc $PWMC_ARGS acl > result
101 cmp acl.result13 result
102 rm -f result
104 echo
105 test_header "Test 14. List attributes of owned child of un-owned parent (fail)."
106 echo -ne 'attr\ta\tb\tvalue' | pwmc $PWMC_ARGS --inquire STORE -S acl
107 echo -ne 'ATTR SET _acl attr\ta nobody' | pwmc $PWMC_ARGS -S acl
108 set +o errexit
109 echo -ne "ATTR LIST attr\ta\tb" | pwmc $PWMC_ARGS acl
110 if [ ${PIPESTATUS[1]} == 0 ]; then
111 echo "The previous command should have failed. Stopping."
112 exit 1
115 set -e
116 echo
117 test_header "Test 15. List attributes of un-owned child."
118 echo -ne 'ATTR LIST attr\ta' | pwmc $PWMC_ARGS acl > /dev/null
120 echo
121 test_header "Test 16. List attributes of un-owned root with target."
122 echo -ne 'ATTR LIST b' | pwmc $PWMC_ARGS acl > result
123 cmp acl.result16 result
124 rm -f result
126 echo
127 test_header "Test 17. List attributes of un-owned child with un-owned root target (fail)."
128 set +o errexit
129 echo -ne "ATTR LIST b\tb" | pwmc $PWMC_ARGS acl
130 if [ ${PIPESTATUS[1]} == 0 ]; then
131 echo "The previous command should have failed. Stopping."
132 exit 1
135 set -e
136 echo
137 test_header "Test 18. List non-existant child of un-owned parent."
138 echo -ne 'new\ta\tb\tvalue' | pwmc $PWMC_ARGS --inquire STORE -S acl
139 echo -ne 'new2\ta\tb\tvalue' | pwmc $PWMC_ARGS --inquire STORE -S acl
140 echo -ne 'ATTR SET target new\ta new2\ta' | pwmc $PWMC_ARGS -S acl
141 echo -ne 'ATTR SET _acl new2\ta nobody' | pwmc $PWMC_ARGS -S acl
142 echo -ne 'LIST --recurse new\ta\tnon-existant' | pwmc $PWMC_ARGS acl > result
143 cmp acl.result18 result
144 rm -f result
146 echo
147 test_header "Test 19. List children of un-owned parent with target."
148 echo -ne 'LIST --recurse new' | pwmc $PWMC_ARGS acl > result
149 cmp acl.result19 result
150 rm -f result
152 echo
153 test_header "Test 20. Create target to visible restricted root."
154 echo -ne 'ATTR SET target zzz\ta a' | pwmc $PWMC_ARGS -S acl
155 echo -ne 'LIST --recurse' | pwmc $PWMC_ARGS acl > result
156 cmp acl.result20 result
157 rm -f result
159 echo
160 test_header "Test 21. Create target to visible restricted child."
161 echo -ne 'ATTR SET _acl zzz\ta non-existant' | pwmc $PWMC_ARGS -S acl
162 echo -ne 'ATTR SET target newzzz\tb zzz\ta' | pwmc $PWMC_ARGS -S acl
163 echo -ne 'LIST --recurse' | pwmc $PWMC_ARGS acl > result
164 cmp acl.result21 result
165 rm -f result
167 echo
168 test_header "Test 22. Get attribute of a bad permission element."
169 echo -ne 'ATTR GET _acl zzz\ta' | pwmc $PWMC_ARGS acl > result
170 cmp acl.result22 result
171 rm -f result
173 echo
174 test_header "Test 23. Get attribute of a bad permission elements child (fail)."
175 set +o errexit
176 echo -ne 'ATTR GET _acl zzz\ta\tblah' | pwmc $PWMC_ARGS acl
177 if [ ${PIPESTATUS[1]} == 0 ]; then
178 echo "The previous command should have failed. Stopping."
179 exit 1
182 set -e
184 echo
185 test_header "Test 24. Delete attribute of non-owner (fail)."
186 set +o errexit
187 echo -ne 'ATTR DELETE _mtime c' | pwmc $PWMC_ARGS acl
188 if [ ${PIPESTATUS[1]} == 0 ]; then
189 echo "The previous command should have failed. Stopping."
190 exit 1
193 set -e
195 echo
196 test_header "Test 25. Set non-existant attribute of non-owner (fail)."
197 set +o errexit
198 echo -ne 'ATTR SET blahblah c value' | pwmc $PWMC_ARGS acl
199 if [ ${PIPESTATUS[1]} == 0 ]; then
200 echo "The previous command should have failed. Stopping."
201 exit 1
204 set -e
206 echo
207 test_header "Test 26. Overwrite existing attribute of non-owner (fail)."
208 set +o errexit
209 echo -ne 'ATTR SET _mtime c 1234' | pwmc $PWMC_ARGS acl
210 if [ ${PIPESTATUS[1]} == 0 ]; then
211 echo "The previous command should have failed. Stopping."
212 exit 1
215 set -e
217 test_success