aboutsummaryrefslogtreecommitdiff
path: root/test/T590-libconfig.sh
diff options
context:
space:
mode:
authorTomi Ollila <tomi.ollila@iki.fi>2021-05-22 16:39:57 +0300
committerDavid Bremner <david@tethera.net>2021-05-22 11:51:29 -0300
commit8675be1d307bc2df882107744641f6a7858e65ad (patch)
treed7838780517218f73c4a9a6e831316e2d1077195 /test/T590-libconfig.sh
parent3baa61e0e58402bc50c5df529fcf669bf4b2facb (diff)
test: replace notmuch_passwd_sanitize() with _libconfig_sanitize()
notmuch_passwd_sanitize() in test-lib.sh is too generic, it cannot work in many cases... The more specific version _libconfig_sanitize() replaces it in T590-libconfig.sh and the code that uses it is modified to output the keys (ascending numbers printed in hex) so the sanitizer knows what to sanitize in which lines... "@" + fqdn -> "@FQDN" replacement is used as fqdn could -- in theory -- be substring of 'USERNAME'. 'user -> 'USER_FULL_NAME replacement to work in cases where user is empty -- as only first ' is replaced that works as expected. In addition to ".(none)" now also ".localdomain" is filtered from USERNAME@FQDN. /dev/fd/{n} is not defined in posix, but it is portable enough (if it weren't it is easy to fix -- now code looks clearer).
Diffstat (limited to 'test/T590-libconfig.sh')
-rwxr-xr-xtest/T590-libconfig.sh96
1 files changed, 58 insertions, 38 deletions
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 745e1bb4..bc7298f8 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -5,6 +5,25 @@ test_description="library config API"
add_email_corpus
+_libconfig_sanitize() {
+ ${NOTMUCH_PYTHON} /dev/fd/3 3<<'EOF'
+import os, sys, pwd, socket
+
+pw = pwd.getpwuid(os.getuid())
+user = pw.pw_name
+name = pw.pw_gecos.partition(",")[0]
+fqdn = socket.getaddrinfo(socket.gethostname(), 0, 0,
+ socket.SOCK_STREAM, 0, socket.AI_CANONNAME)[0][3]
+for l in sys.stdin:
+ if l[:4] == "08: ":
+ l = l.replace(user, "USERNAME", 1).replace("@" + fqdn, "@FQDN", 1)
+ l = l.replace(".(none)", "", 1).replace(".localdomain", "", 1)
+ elif l[:4] == "10: ":
+ l = l.replace("'" + name, "'USER_FULL_NAME", 1)
+ sys.stdout.write(l)
+EOF
+}
+
cat <<EOF > c_head
#include <string.h>
#include <stdlib.h>
@@ -380,26 +399,26 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} '' %NULL%
key < NOTMUCH_CONFIG_LAST;
key = (notmuch_config_key_t)(key + 1)) {
const char *val = notmuch_config_get (db, key);
- printf("%s\n", val ? val : "NULL" );
+ printf("%02d: '%s'\n", key, val ? val : "NULL" );
}
}
EOF
-notmuch_passwd_sanitize < OUTPUT > OUTPUT.clean
+_libconfig_sanitize < OUTPUT > OUTPUT.clean
cat <<'EOF' >EXPECTED
== stdout ==
-MAIL_DIR
-MAIL_DIR
-MAIL_DIR/.notmuch/hooks
-MAIL_DIR/.notmuch/backups
-
-unread;inbox
-
-true
-USERNAME@FQDN
-NULL
-USER_FULL_NAME
+00: 'MAIL_DIR'
+01: 'MAIL_DIR'
+02: 'MAIL_DIR/.notmuch/hooks'
+03: 'MAIL_DIR/.notmuch/backups'
+04: ''
+05: 'unread;inbox'
+06: ''
+07: 'true'
+08: 'USERNAME@FQDN'
+09: 'NULL'
+10: 'USER_FULL_NAME'
== stderr ==
EOF
unset MAILDIR
@@ -694,23 +713,23 @@ cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} %NULL% %NULL%
key < NOTMUCH_CONFIG_LAST;
key = (notmuch_config_key_t)(key + 1)) {
const char *val = notmuch_config_get (db, key);
- printf("%s\n", val ? val : "NULL" );
+ printf("%x: '%s'\n", key, val ? val : "NULL" );
}
}
EOF
cat <<'EOF' >EXPECTED
== stdout ==
-MAIL_DIR
-MAIL_DIR
-MAIL_DIR/.notmuch/hooks
-MAIL_DIR/.notmuch/backups
-foo;bar;fub
-unread;inbox
-sekrit_junk
-true
-test_suite@notmuchmail.org
-test_suite_other@notmuchmail.org;test_suite@otherdomain.org
-Notmuch Test Suite
+0: 'MAIL_DIR'
+1: 'MAIL_DIR'
+2: 'MAIL_DIR/.notmuch/hooks'
+3: 'MAIL_DIR/.notmuch/backups'
+4: 'foo;bar;fub'
+5: 'unread;inbox'
+6: 'sekrit_junk'
+7: 'true'
+8: 'test_suite@notmuchmail.org'
+9: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
+a: 'Notmuch Test Suite'
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -723,25 +742,26 @@ cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR} /nonexistent %NULL%
key < NOTMUCH_CONFIG_LAST;
key = (notmuch_config_key_t)(key + 1)) {
const char *val = notmuch_config_get (db, key);
- printf("%s\n", val ? val : "NULL" );
+ printf("%02d: '%s'\n", key, val ? val : "NULL" );
}
}
EOF
-notmuch_passwd_sanitize < OUTPUT > OUTPUT.clean
+_libconfig_sanitize < OUTPUT > OUTPUT.clean
+
cat <<'EOF' >EXPECTED
== stdout ==
-MAIL_DIR
-MAIL_DIR
-MAIL_DIR/.notmuch/hooks
-MAIL_DIR/.notmuch/backups
-
-unread;inbox
-
-true
-USERNAME@FQDN
-NULL
-USER_FULL_NAME
+00: 'MAIL_DIR'
+01: 'MAIL_DIR'
+02: 'MAIL_DIR/.notmuch/hooks'
+03: 'MAIL_DIR/.notmuch/backups'
+04: ''
+05: 'unread;inbox'
+06: ''
+07: 'true'
+08: 'USERNAME@FQDN'
+09: 'NULL'
+10: 'USER_FULL_NAME'
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT.clean