summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-03-18 22:54:13 -0300
committerDavid Bremner <david@tethera.net>2021-03-18 22:54:13 -0300
commit7d286f0272feb08aea8c1bee0b0ec6cd9766aee7 (patch)
treec489c49cb013d1f7239e5a1b47c2696b5a79a043
parent13efbd0e1c88fcbdb48b4c30c7852c5bf1fbd0b7 (diff)
test: Add tests for write access to database from hooks.
Recent changes to configuration handling meant the pre-new hook was run while the database was open read only, limiting what could be done in the hook. Add some known broken tests for this problem, as well as a regression test for write access from the post-new hook.
-rwxr-xr-xtest/T400-hooks.sh28
-rw-r--r--test/test-lib.sh1
2 files changed, 29 insertions, 0 deletions
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index a3dd4c63..a2b67d59 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -2,6 +2,8 @@
test_description='hooks'
. $(dirname "$0")/test-lib.sh || exit 1
+test_require_external_prereq xapian-delve
+
create_echo_hook () {
local TOKEN="${RANDOM}"
mkdir -p ${HOOK_DIR}
@@ -13,6 +15,19 @@ EOF
echo "${TOKEN}" > ${2}
}
+create_write_hook () {
+ local TOKEN="${RANDOM}"
+ mkdir -p ${HOOK_DIR}
+ cat <<EOF >"${HOOK_DIR}/${1}"
+#!/bin/sh
+if xapian-delve ${MAIL_DIR}/.notmuch/xapian | grep -q "writing = false"; then
+ echo "${TOKEN}" > ${3}
+fi
+EOF
+ chmod +x "${HOOK_DIR}/${1}"
+ echo "${TOKEN}" > ${2}
+}
+
create_failing_hook () {
local HOOK_DIR=${2}
mkdir -p ${HOOK_DIR}
@@ -137,6 +152,19 @@ EOF
chmod +x "${HOOK_DIR}/pre-new"
test_expect_code 1 "notmuch new"
+ test_begin_subtest "post-new with write access [${config}]"
+ rm -rf ${HOOK_DIR}
+ create_write_hook "post-new" write.expected write.output $HOOK_DIR
+ NOTMUCH_NEW
+ test_expect_equal_file write.expected write.output
+
+ test_begin_subtest "pre-new with write access [${config}]"
+ test_subtest_known_broken
+ rm -rf ${HOOK_DIR}
+ create_write_hook "pre-new" write.expected write.output $HOOK_DIR
+ NOTMUCH_NEW
+ test_expect_equal_file write.expected write.output
+
rm -rf ${HOOK_DIR}
done
test_done
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 29baa0c1..fc176af8 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -1271,3 +1271,4 @@ test_declare_external_prereq openssl
test_declare_external_prereq gpgsm
test_declare_external_prereq ${NOTMUCH_PYTHON}
test_declare_external_prereq xapian-metadata
+test_declare_external_prereq xapian-delve