]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - run-tests.sh
Fix command-line error handling.
[apply-default-acl.git] / run-tests.sh
index a5f7692b7e28e5d4d70a01a06235e48f3c4c6d10..4df37b9ec594d04744e35d9ed6d4044340be4d72 100755 (executable)
@@ -1,28 +1,25 @@
 #!/bin/bash
 
-# Our exit code.
-RESULT=0
-
 # The directory where we'll do all the ACL manipulation.
 TESTDIR=test
 
 acl_reset() {
     # Remove any ACLs on our test directory and remove its contents.
     setfacl --remove-all --recursive "$TESTDIR"
-    rm -f "${TESTDIR}"/*
+    rm -rf "${TESTDIR}"/*
 }
 
 compare() {
     if [[ "${ACTUAL}" == "${EXPECTED}" ]]; then
-       echo "Success."
+       echo "Success (#${TESTNUM})"
        acl_reset
     else
-       echo "Failure."
+       echo "Failure (#${TESTNUM})"
        echo "Expected result:"
        echo "${EXPECTED}"
        echo "Actual result:"
        echo "${ACTUAL}"
-       RESULT=1
+       exit 1
     fi
 }
 
@@ -33,6 +30,7 @@ mkdir "${TESTDIR}"
 
 # When using a minimal ACL, the default user, group, and other
 # permissions should all be propagated to the mode bits.
+TESTNUM=1
 TARGET="${TESTDIR}"/foo
 setfacl -d -m user::r--  "${TESTDIR}"
 setfacl -d -m group::r-- "${TESTDIR}"
@@ -53,6 +51,7 @@ ACTUAL=`getfacl --omit-header "${TARGET}"`
 compare
 
 # Do the same thing as the last test, except with an extended ACL.
+TESTNUM=2
 setfacl -d -m user::r--     "${TESTDIR}"
 setfacl -d -m group::r--    "${TESTDIR}"
 setfacl -d -m other::r--    "${TESTDIR}"
@@ -74,11 +73,12 @@ EOF
 ACTUAL=`getfacl --omit-header "${TARGET}"`
 compare
 
-# A directory shared by a group, should still be group-writable
+# A file shared by a group, should still be group-writable
 # afterwards.
-setfacl -d -m group:mail:rwx "${TESTDIR}"
+TESTNUM=3
 touch "${TARGET}"
 chmod 644 "${TARGET}"
+setfacl -d -m group:mail:rwx "${TESTDIR}"
 ./aclq "${TARGET}"
 
 EXPECTED=$(cat <<EOF
@@ -92,3 +92,165 @@ EOF
 
 ACTUAL=`getfacl --omit-header "${TARGET}"`
 compare
+
+# Same test as before except with a directory.
+TESTNUM=4
+setfacl -d -m group:mail:rwx "${TESTDIR}"
+mkdir "${TARGET}"
+chmod 755 "${TARGET}"
+./aclq "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+group::r-x
+group:mail:rwx
+mask::rwx
+other::r-x
+default:user::rwx
+default:group::r-x
+default:group:mail:rwx
+default:mask::rwx
+default:other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# With no default, things are left alone.
+TESTNUM=5
+touch "${TARGET}"
+chmod 744 "${TARGET}"
+./aclq "${TARGET}"
+
+
+EXPECTED=$(cat <<EOF
+user::rwx
+group::r--
+other::r--
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+
+# Since the default ACL will grant r-x to group/other, they will wind
+# up with it.
+TESTNUM=6
+touch "${TARGET}"
+chmod 744 "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+./aclq "${TARGET}"
+
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# Some named entries can be granted execute permissions as the result
+# of reapplication.
+TESTNUM=7
+touch "${TARGET}"
+chmod 744 "${TARGET}"
+setfacl -m user:news:rw "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+setfacl -d -m user:news:rwx "${TESTDIR}"
+./aclq "${TARGET}"
+
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+user:news:rwx
+group::r-x
+mask::rwx
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# We should not retain any entries that aren't in the default.
+TESTNUM=8
+touch "${TARGET}"
+chmod 644 "${TARGET}"
+setfacl -m user:news:rw "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+./aclq "${TARGET}"
+
+
+EXPECTED=$(cat <<EOF
+user::rw-
+user:mail:rwx  #effective:rw-
+group::r--
+mask::rw-
+other::r--
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# A slightly modified test #1 to make sure it works right.
+TESTNUM=9
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 777 "${TARGET}"
+setfacl -d -m user::r--  "${TESTDIR}"
+./aclq "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::r--
+group::r-x
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# If the default ACL mask denies execute, we should respect that
+# regardless of the existing execute permissions.
+TESTNUM=10
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 777 "${TARGET}"
+setfacl -m user:mail:rwx "${TESTDIR}"
+setfacl -d -m user:mail:rwx  "${TESTDIR}"
+setfacl -d -m mask::rw-  "${TESTDIR}"
+./aclq "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx  #effective:rw-
+group::r-x     #effective:r--
+mask::rw-
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare