mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-01-03 15:21:41 +01:00
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).
This commit is contained in:
parent
3baa61e0e5
commit
8675be1d30
2 changed files with 58 additions and 58 deletions
|
@ -5,6 +5,25 @@ test_description="library config API"
|
||||||
|
|
||||||
add_email_corpus
|
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
|
cat <<EOF > c_head
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.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_LAST;
|
||||||
key = (notmuch_config_key_t)(key + 1)) {
|
key = (notmuch_config_key_t)(key + 1)) {
|
||||||
const char *val = notmuch_config_get (db, key);
|
const char *val = notmuch_config_get (db, key);
|
||||||
printf("%s\n", val ? val : "NULL" );
|
printf("%02d: '%s'\n", key, val ? val : "NULL" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
notmuch_passwd_sanitize < OUTPUT > OUTPUT.clean
|
_libconfig_sanitize < OUTPUT > OUTPUT.clean
|
||||||
|
|
||||||
cat <<'EOF' >EXPECTED
|
cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
MAIL_DIR
|
00: 'MAIL_DIR'
|
||||||
MAIL_DIR
|
01: 'MAIL_DIR'
|
||||||
MAIL_DIR/.notmuch/hooks
|
02: 'MAIL_DIR/.notmuch/hooks'
|
||||||
MAIL_DIR/.notmuch/backups
|
03: 'MAIL_DIR/.notmuch/backups'
|
||||||
|
04: ''
|
||||||
unread;inbox
|
05: 'unread;inbox'
|
||||||
|
06: ''
|
||||||
true
|
07: 'true'
|
||||||
USERNAME@FQDN
|
08: 'USERNAME@FQDN'
|
||||||
NULL
|
09: 'NULL'
|
||||||
USER_FULL_NAME
|
10: 'USER_FULL_NAME'
|
||||||
== stderr ==
|
== stderr ==
|
||||||
EOF
|
EOF
|
||||||
unset MAILDIR
|
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_LAST;
|
||||||
key = (notmuch_config_key_t)(key + 1)) {
|
key = (notmuch_config_key_t)(key + 1)) {
|
||||||
const char *val = notmuch_config_get (db, key);
|
const char *val = notmuch_config_get (db, key);
|
||||||
printf("%s\n", val ? val : "NULL" );
|
printf("%x: '%s'\n", key, val ? val : "NULL" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cat <<'EOF' >EXPECTED
|
cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
MAIL_DIR
|
0: 'MAIL_DIR'
|
||||||
MAIL_DIR
|
1: 'MAIL_DIR'
|
||||||
MAIL_DIR/.notmuch/hooks
|
2: 'MAIL_DIR/.notmuch/hooks'
|
||||||
MAIL_DIR/.notmuch/backups
|
3: 'MAIL_DIR/.notmuch/backups'
|
||||||
foo;bar;fub
|
4: 'foo;bar;fub'
|
||||||
unread;inbox
|
5: 'unread;inbox'
|
||||||
sekrit_junk
|
6: 'sekrit_junk'
|
||||||
true
|
7: 'true'
|
||||||
test_suite@notmuchmail.org
|
8: 'test_suite@notmuchmail.org'
|
||||||
test_suite_other@notmuchmail.org;test_suite@otherdomain.org
|
9: 'test_suite_other@notmuchmail.org;test_suite@otherdomain.org'
|
||||||
Notmuch Test Suite
|
a: 'Notmuch Test Suite'
|
||||||
== stderr ==
|
== stderr ==
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
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_LAST;
|
||||||
key = (notmuch_config_key_t)(key + 1)) {
|
key = (notmuch_config_key_t)(key + 1)) {
|
||||||
const char *val = notmuch_config_get (db, key);
|
const char *val = notmuch_config_get (db, key);
|
||||||
printf("%s\n", val ? val : "NULL" );
|
printf("%02d: '%s'\n", key, val ? val : "NULL" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
notmuch_passwd_sanitize < OUTPUT > OUTPUT.clean
|
_libconfig_sanitize < OUTPUT > OUTPUT.clean
|
||||||
|
|
||||||
cat <<'EOF' >EXPECTED
|
cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
MAIL_DIR
|
00: 'MAIL_DIR'
|
||||||
MAIL_DIR
|
01: 'MAIL_DIR'
|
||||||
MAIL_DIR/.notmuch/hooks
|
02: 'MAIL_DIR/.notmuch/hooks'
|
||||||
MAIL_DIR/.notmuch/backups
|
03: 'MAIL_DIR/.notmuch/backups'
|
||||||
|
04: ''
|
||||||
unread;inbox
|
05: 'unread;inbox'
|
||||||
|
06: ''
|
||||||
true
|
07: 'true'
|
||||||
USERNAME@FQDN
|
08: 'USERNAME@FQDN'
|
||||||
NULL
|
09: 'NULL'
|
||||||
USER_FULL_NAME
|
10: 'USER_FULL_NAME'
|
||||||
== stderr ==
|
== stderr ==
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT.clean
|
test_expect_equal_file EXPECTED OUTPUT.clean
|
||||||
|
|
|
@ -564,26 +564,6 @@ notmuch_built_with_sanitize () {
|
||||||
sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
|
sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch_passwd_sanitize () {
|
|
||||||
${NOTMUCH_PYTHON} -c'
|
|
||||||
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 user:
|
|
||||||
l = l.replace(user, "USERNAME")
|
|
||||||
if fqdn:
|
|
||||||
l = l.replace(fqdn, "FQDN").replace(".(none)","")
|
|
||||||
if name:
|
|
||||||
l = l.replace(name, "USER_FULL_NAME")
|
|
||||||
sys.stdout.write(l)
|
|
||||||
'
|
|
||||||
}
|
|
||||||
|
|
||||||
notmuch_config_sanitize () {
|
notmuch_config_sanitize () {
|
||||||
notmuch_dir_sanitize | notmuch_built_with_sanitize
|
notmuch_dir_sanitize | notmuch_built_with_sanitize
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue