]> gitweb.michael.orlitzky.com - apply-default-acl.git/blob - run-tests.sh
Add a few more tricky tests.
[apply-default-acl.git] / run-tests.sh
1 #!/bin/bash
2
3 # The directory where we'll do all the ACL manipulation.
4 TESTDIR=test
5
6 acl_reset() {
7 # Remove any ACLs on our test directory and remove its contents.
8 setfacl --remove-all --recursive "$TESTDIR"
9 rm -rf "${TESTDIR}"/*
10 }
11
12 compare() {
13 if [[ "${ACTUAL}" == "${EXPECTED}" ]]; then
14 echo "Success (#${TESTNUM})"
15 acl_reset
16 else
17 echo "Failure (#${TESTNUM})"
18 echo "Expected result:"
19 echo "${EXPECTED}"
20 echo "Actual result:"
21 echo "${ACTUAL}"
22 exit 1
23 fi
24 }
25
26 # Start by removing and recreating the 'acl' directory.
27 rm -rf "${TESTDIR}"
28 mkdir "${TESTDIR}"
29
30
31 # When using a minimal ACL, the default user, group, and other
32 # permissions should all be propagated to the mode bits.
33 TESTNUM=1
34 TARGET="${TESTDIR}"/foo
35 setfacl -d -m user::r-- "${TESTDIR}"
36 setfacl -d -m group::r-- "${TESTDIR}"
37 setfacl -d -m other::r-- "${TESTDIR}"
38 touch "${TARGET}"
39 chmod 777 "${TARGET}"
40 ./aclq "${TARGET}"
41
42 EXPECTED=$(cat <<EOF
43 user::r--
44 group::r--
45 other::r--
46
47 EOF
48 )
49
50 ACTUAL=`getfacl --omit-header "${TARGET}"`
51 compare
52
53 # Do the same thing as the last test, except with an extended ACL.
54 TESTNUM=2
55 setfacl -d -m user::r-- "${TESTDIR}"
56 setfacl -d -m group::r-- "${TESTDIR}"
57 setfacl -d -m other::r-- "${TESTDIR}"
58 setfacl -d -m user:mail:rwx "${TESTDIR}"
59 touch "${TARGET}"
60 chmod 777 "${TARGET}"
61 ./aclq "${TARGET}"
62
63 EXPECTED=$(cat <<EOF
64 user::r--
65 user:mail:rwx
66 group::r--
67 mask::rwx
68 other::r--
69
70 EOF
71 )
72
73 ACTUAL=`getfacl --omit-header "${TARGET}"`
74 compare
75
76 # A file shared by a group, should still be group-writable
77 # afterwards.
78 TESTNUM=3
79 touch "${TARGET}"
80 chmod 644 "${TARGET}"
81 setfacl -d -m group:mail:rwx "${TESTDIR}"
82 ./aclq "${TARGET}"
83
84 EXPECTED=$(cat <<EOF
85 user::rw-
86 group::r--
87 group:mail:rwx #effective:rw-
88 mask::rw-
89 other::r--
90 EOF
91 )
92
93 ACTUAL=`getfacl --omit-header "${TARGET}"`
94 compare
95
96 # Same test as before except with a directory.
97 TESTNUM=4
98 setfacl -d -m group:mail:rwx "${TESTDIR}"
99 mkdir "${TARGET}"
100 chmod 755 "${TARGET}"
101 ./aclq "${TARGET}"
102
103 EXPECTED=$(cat <<EOF
104 user::rwx
105 group::r-x
106 group:mail:rwx
107 mask::rwx
108 other::r-x
109 default:user::rwx
110 default:group::r-x
111 default:group:mail:rwx
112 default:mask::rwx
113 default:other::r-x
114
115 EOF
116 )
117
118 ACTUAL=`getfacl --omit-header "${TARGET}"`
119 compare
120
121
122 # With no default, things are left alone.
123 TESTNUM=5
124 touch "${TARGET}"
125 chmod 744 "${TARGET}"
126 ./aclq "${TARGET}"
127
128
129 EXPECTED=$(cat <<EOF
130 user::rwx
131 group::r--
132 other::r--
133
134 EOF
135 )
136
137 ACTUAL=`getfacl --omit-header "${TARGET}"`
138 compare
139
140
141
142 # Make sure execute permission is removed for group/other after the
143 # reapplication.
144 TESTNUM=6
145 touch "${TARGET}"
146 chmod 744 "${TARGET}"
147 setfacl -d -m user:mail:rwx "${TESTDIR}"
148 ./aclq "${TARGET}"
149
150
151 EXPECTED=$(cat <<EOF
152 user::rwx
153 user:mail:rwx
154 group::r--
155 mask::rwx
156 other::r--
157
158 EOF
159 )
160
161 ACTUAL=`getfacl --omit-header "${TARGET}"`
162 compare
163
164
165 # In fact, no existing named entries without execute permissions
166 # should be granted execute permissions as the result of
167 # reapplication.
168 TESTNUM=7
169 touch "${TARGET}"
170 chmod 744 "${TARGET}"
171 setfacl -m user:news:rw "${TARGET}"
172 setfacl -d -m user:mail:rwx "${TESTDIR}"
173 setfacl -d -m user:news:rwx "${TESTDIR}"
174 ./aclq "${TARGET}"
175
176
177 EXPECTED=$(cat <<EOF
178 user::rwx
179 user:mail:rwx
180 user:news:rw-
181 group::r--
182 mask::rwx
183 other::r--
184
185 EOF
186 )
187
188 ACTUAL=`getfacl --omit-header "${TARGET}"`
189 compare