]> gitweb.michael.orlitzky.com - apply-default-acl.git/blobdiff - run-tests.sh
Add a new command-line option, --no-exec-mask, that disables the exec bit masking...
[apply-default-acl.git] / run-tests.sh
index 0ce549c84ca1e6a64a1a7cb9f1dd50d19d3b57e8..4186b38054812aef3e951d6d791eb30cfd4a97b6 100755 (executable)
@@ -8,7 +8,8 @@ TESTDIR=test
 
 acl_reset() {
     # Remove any ACLs on our test directory and remove its contents.
-    setfacl --remove-all --recursive "$TESTDIR"
+    setfacl --remove-all --recursive "${TESTDIR}"
+    chmod 755 "${TESTDIR}"
     rm -rf "${TESTDIR}"/*
 }
 
@@ -18,10 +19,14 @@ compare() {
        acl_reset
     else
        echo "Failure (#${TESTNUM})"
-       echo "Expected result:"
+       echo 'Expected result:'
+       echo '================'
        echo "${EXPECTED}"
-       echo "Actual result:"
+       echo '================'
+       echo 'Actual result:'
+       echo '================'
        echo "${ACTUAL}"
+       echo '================'
        exit 1
     fi
 }
@@ -35,11 +40,11 @@ mkdir "${TESTDIR}"
 # permissions should all be propagated to the mode bits.
 TESTNUM=1
 TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 777 "${TARGET}"
 setfacl -d -m user::r--  "${TESTDIR}"
 setfacl -d -m group::r-- "${TESTDIR}"
 setfacl -d -m other::r-- "${TESTDIR}"
-touch "${TARGET}"
-chmod 777 "${TARGET}"
 $BIN "${TARGET}"
 
 EXPECTED=$(cat <<EOF
@@ -76,6 +81,7 @@ EOF
 ACTUAL=`getfacl --omit-header "${TARGET}"`
 compare
 
+
 # A file shared by a group, should still be group-writable
 # afterwards.
 TESTNUM=3
@@ -90,12 +96,14 @@ group::r--
 group:mail:rwx #effective:rw-
 mask::rw-
 other::r--
+
 EOF
 )
 
 ACTUAL=`getfacl --omit-header "${TARGET}"`
 compare
 
+
 # Same test as before except with a directory.
 TESTNUM=4
 setfacl -d -m group:mail:rwx "${TESTDIR}"
@@ -171,6 +179,11 @@ TESTNUM=7
 touch "${TARGET}"
 chmod 744 "${TARGET}"
 setfacl -m user:news:rw "${TARGET}"
+# If we don't add 'x' to the mask here, nobody can execute the file.
+# setfacl will update the mask for us under most circumstances, but
+# note that we didn't create an entry with an 'x' bit using setfacl --
+# therefore, setfacl won't unmask 'x' for us.
+setfacl -m mask::rwx "${TARGET}"
 setfacl -d -m user:mail:rwx "${TESTDIR}"
 setfacl -d -m user:news:rwx "${TESTDIR}"
 $BIN "${TARGET}"
@@ -329,8 +342,213 @@ other::r--
 default:user::rwx
 default:group::r--
 default:other::r--
+
 EOF
 )
 
 ACTUAL=`getfacl --omit-header "${TARGET}"/bar`
 compare
+
+
+# Test double application on a directory.
+#
+TESTNUM=14
+TARGET="${TESTDIR}"/baz
+mkdir "${TARGET}"
+chmod 644 "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+
+$BIN "${TARGET}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+default:user::rwx
+default:user:mail:rwx
+default:group::r-x
+default:mask::rwx
+default:other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# Same as previous test, with 755 initial perms.
+#
+TESTNUM=15
+TARGET="${TESTDIR}"/baz
+mkdir "${TARGET}"
+chmod 755 "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+
+$BIN "${TARGET}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+default:user::rwx
+default:user:mail:rwx
+default:group::r-x
+default:mask::rwx
+default:other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# Same as previous two tests, only with a file.
+#
+TESTNUM=16
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 644 "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+
+$BIN "${TARGET}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rw-
+user:mail:rwx  #effective:rw-
+group::r--
+mask::rw-
+other::r--
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# User-executable files should not wind up exec-masked.
+TESTNUM=17
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 700 "${TARGET}"
+setfacl -d -m user:mail:rwx  "${TESTDIR}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# Group-executable files should not wind up exec-masked.
+TESTNUM=18
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 670 "${TARGET}"
+setfacl -d -m user:mail:rwx  "${TESTDIR}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+# Other-executable files should not wind up exec-masked.
+TESTNUM=19
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 607 "${TARGET}"
+setfacl -d -m user:mail:rwx  "${TESTDIR}"
+$BIN "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+
+# Test #16's setup repeated with the --no-exec-mask flag.
+#
+TESTNUM=20
+TARGET="${TESTDIR}"/foo
+touch "${TARGET}"
+chmod 644 "${TARGET}"
+# The directory allows execute for user, group, and other, so the file
+# should actually inherit them regardless of its initial mode when the
+# --no-exec-mask flag is passed.
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+
+$BIN --no-exec-mask "${TARGET}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+
+
+
+# Test #20 repeated recursively to make sure the flags play nice
+# together.
+TESTNUM=21
+PARENT_DIR="${TESTDIR}"/foo
+TARGET="${PARENT_DIR}"/bar
+mkdir "${PARENT_DIR}"
+touch "${TARGET}"
+chmod 644 "${TARGET}"
+setfacl -d -m user:mail:rwx "${TESTDIR}"
+
+$BIN --recursive --no-exec-mask "${PARENT_DIR}"
+
+EXPECTED=$(cat <<EOF
+user::rwx
+user:mail:rwx
+group::r-x
+mask::rwx
+other::r-x
+EOF
+)
+
+ACTUAL=`getfacl --omit-header "${TARGET}"`
+compare
+