]> gitweb.michael.orlitzky.com - apply-default-acl.git/blob - run-tests.sh
Add a 'test' makefile target.
[apply-default-acl.git] / run-tests.sh
1 #!/bin/bash
2
3 # Our exit code.
4 RESULT=0
5
6 # The directory where we'll do all the ACL manipulation.
7 TESTDIR=test
8
9 acl_reset() {
10 # Remove any ACLs on our test directory and remove its contents.
11 setfacl --remove-all --recursive "$TESTDIR"
12 rm -rf "${TESTDIR}"/*
13 }
14
15 compare() {
16 if [[ "${ACTUAL}" == "${EXPECTED}" ]]; then
17 echo "Success."
18 acl_reset
19 else
20 echo "Failure."
21 echo "Expected result:"
22 echo "${EXPECTED}"
23 echo "Actual result:"
24 echo "${ACTUAL}"
25 RESULT=1
26 fi
27 }
28
29 # Start by removing and recreating the 'acl' directory.
30 rm -rf "${TESTDIR}"
31 mkdir "${TESTDIR}"
32
33
34 # When using a minimal ACL, the default user, group, and other
35 # permissions should all be propagated to the mode bits.
36 TARGET="${TESTDIR}"/foo
37 setfacl -d -m user::r-- "${TESTDIR}"
38 setfacl -d -m group::r-- "${TESTDIR}"
39 setfacl -d -m other::r-- "${TESTDIR}"
40 touch "${TARGET}"
41 chmod 777 "${TARGET}"
42 ./aclq "${TARGET}"
43
44 EXPECTED=$(cat <<EOF
45 user::r--
46 group::r--
47 other::r--
48
49 EOF
50 )
51
52 ACTUAL=`getfacl --omit-header "${TARGET}"`
53 compare
54
55 # Do the same thing as the last test, except with an extended ACL.
56 setfacl -d -m user::r-- "${TESTDIR}"
57 setfacl -d -m group::r-- "${TESTDIR}"
58 setfacl -d -m other::r-- "${TESTDIR}"
59 setfacl -d -m user:mail:rwx "${TESTDIR}"
60 touch "${TARGET}"
61 chmod 777 "${TARGET}"
62 ./aclq "${TARGET}"
63
64 EXPECTED=$(cat <<EOF
65 user::r--
66 user:mail:rwx
67 group::r--
68 mask::rwx
69 other::r--
70
71 EOF
72 )
73
74 ACTUAL=`getfacl --omit-header "${TARGET}"`
75 compare
76
77 # A directory shared by a group, should still be group-writable
78 # afterwards.
79 setfacl -d -m group:mail:rwx "${TESTDIR}"
80 touch "${TARGET}"
81 chmod 644 "${TARGET}"
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 setfacl -d -m group:mail:rwx "${TESTDIR}"
98 mkdir "${TARGET}"
99 chmod 755 "${TARGET}"
100 ./aclq "${TARGET}"
101
102 EXPECTED=$(cat <<EOF
103 user::rwx
104 group::r-x
105 group:mail:rwx
106 mask::rwx
107 other::r-x
108 default:user::rwx
109 default:group::r-x
110 default:group:mail:rwx
111 default:mask::rwx
112 default:other::r-x
113
114 EOF
115 )
116
117 ACTUAL=`getfacl --omit-header "${TARGET}"`
118 compare