From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0JEeDLdWo2C2xAAAgWs5BA (envelope-from ) for ; Tue, 18 May 2021 07:55:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id +B7SB7dWo2BrTAAAB5/wlQ (envelope-from ) for ; Tue, 18 May 2021 05:55:03 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A042E2F99C for ; Tue, 18 May 2021 07:55:02 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 42A332AA57; Tue, 18 May 2021 01:54:57 -0400 (EDT) Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) by mail.notmuchmail.org (Postfix) with ESMTPS id 945042AA15 for ; Tue, 18 May 2021 01:54:54 -0400 (EDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: too) by meesny.iki.fi (Postfix) with ESMTPSA id 8EDED2006F; Tue, 18 May 2021 08:54:47 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1621317287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kfv7hNyLBzjl7s5rdHVPRkLc4XmY7LWGzTJSgSyXVsc=; b=qdxyaWMc/W2te+ypbpdyWUrWl3jqQisOqfQ7dHnOB8fHt4LS30qVl4gw/v7hlR+SAm86U+ JE9YuEGxEnasZ1ClJrNLMzLJfKuM6W1pOyuK4bERAMkQvEbrHT+DH1IRW86LOohUfm+yiv zZN6Ft6JsPODiooS5Q40C13JON0bMQk= From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH v3] test: replace notmuch_passwd_sanitize() with _libconfig_sanitize() Date: Tue, 18 May 2021 08:54:43 +0300 Message-Id: <20210518055443.21964-1-tomi.ollila@iki.fi> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1621317287; a=rsa-sha256; cv=none; b=C+TCHwUibBdtroywClKZYVPkkt+5hqdJHr5l+PBupT88GzqsB1tGHzQF7Jzu0hEDErmFbZ sdFWvEkY2YSDVa+4xAX77VtP33/ga6Qy4zrdx0VWqvjdJyi0i9zV4+SQutTBSjJMC+gRjI Ai0rSmeflfn/+FCnFz7/mfK7HP9y16g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1621317287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kfv7hNyLBzjl7s5rdHVPRkLc4XmY7LWGzTJSgSyXVsc=; b=G+GRUUxoNrqDk0eBuxVbChM85ikiG1GuI6+iIEUJ5PaIgTvJ9qf9Dw0wBmp6tvA4iCDaSj ZZ8SZ7nOU8hg4+xpgSqX88ztjZwP6F4rcdOPOzy8nVxWoZvNaGHyusfr+wtYbroLtpJWO+ DBJS3C82GTiQTmtFc4dlpvf0HwfdnYc= Message-ID-Hash: B5HJNPCKDC2GSLIIAVTM6YKVROQI2H7E X-Message-ID-Hash: B5HJNPCKDC2GSLIIAVTM6YKVROQI2H7E X-MailFrom: tomi.ollila@iki.fi X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: tomi.ollila@iki.fi X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621317303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=T1NQbiwgMDrPOTyA27+/3fSEty9dSKWzetfOhEsaV30=; b=VjrXBCDNOBNPcPxTXCiKCln3VRAhVyYnirDZAx+M5IVEMNZykwvRWTG4ME9DhS3HMaQUT+ IfiFGHaqVkVP866OlvaAinpL2qNOAXo32FEMrHfehEu8FLSavoyEiAi/u7oPqzsfMWj96R ziGCq/wQLg84lfHz+0SdWK+LhI6zxTpe49UubNO34IbL/hhbEz6NwHyhwft17n9s9MGVfL VQXV0YILzU9irdd68In9pYHGHjt4kkpxhq1KRva1ockpKRk3hPuqX55Jk7yK9NZuwIwSpP Oe7bH1lmk3Y8s3VGB2F4WRLYQqC40+gL4GOkyd6qPMfz7Go1U7uAlpXWvoag8w== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1621317303; a=rsa-sha256; cv=fail; b=DrDiOalwAWoTSODv2433TkIJNQxR15OziYq6UvxPMtglY4ArGIvahEtLu8mufkTKk+v7ca YHTtHfFlrxXgRcaJzWJ/C339KiI8DngrUB/vP/Iu1uNd4xUdz9j2KCY3JSnn4EeXtEcN7E pxd9ag3IHmoFshB9CqhCvQiqzRcCHkR5zBMD7aONtynJ9W3ejCRB21j9uv2i5w4yMS+sNN DOJfnX6U57SYyMnm6wGLa4suI+J0lFS4x+InkW7U4XnPDKqWv72E1kVquvhqM4elWoNQuu UvxtKqg5LW1YrtWscH40UFmtSBGj3hBt9R5jXbGD2A9Wpw4QKYzN64XzPGxRUA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=qdxyaWMc; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 1.92 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=qdxyaWMc; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A042E2F99C X-Spam-Score: 1.92 X-Migadu-Scanner: scn0.migadu.com X-TUID: lX8FdWwx3Vbr 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. --- Changes to [v2]: * work in cases of empty user (e.g. in passwd gecos field) * replace only 1st match; e.g. fqdn could contain substring of user v2: id:20210517193315.11343-1-tomi.ollila@iki.fi v1: id:20210502181535.31292-1-tomi.ollila@iki.fi When tried w/ one replacement and w/o sq usage and emptied gecos, got . @@ -9,5 +9,5 @@ . 7: 'true' . 8: 'USERNAME@FQDN' . 9: 'NULL' . -a: 'USER_FULL_NAME' . +USER_FULL_NAMEa: '' test/T590-libconfig.sh | 97 +++++++++++++++++++++++++----------------- test/test-lib.sh | 20 --------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 745e1bb4..42cbe6e0 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -5,6 +5,26 @@ test_description="library config API" add_email_corpus +_libconfig_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 l[:3] == "8: ": + l = l.replace(user, "USERNAME", 1).replace("@" + fqdn, "@FQDN", 1) + l = l.replace(".(none)", "", 1).replace(".localdomain", "", 1) + elif l[:3] == "a: ": + sq = chr(39) # single quote + l = l.replace(sq + name, sq + "USER_FULL_NAME", 1) + sys.stdout.write(l) +' +} + cat < c_head #include #include @@ -380,26 +400,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("%x: '%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 +0: 'MAIL_DIR' +1: 'MAIL_DIR' +2: 'MAIL_DIR/.notmuch/hooks' +3: 'MAIL_DIR/.notmuch/backups' +4: '' +5: 'unread;inbox' +6: '' +7: 'true' +8: 'USERNAME@FQDN' +9: 'NULL' +a: 'USER_FULL_NAME' == stderr == EOF unset MAILDIR @@ -694,23 +714,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 +743,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("%x: '%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 +0: 'MAIL_DIR' +1: 'MAIL_DIR' +2: 'MAIL_DIR/.notmuch/hooks' +3: 'MAIL_DIR/.notmuch/backups' +4: '' +5: 'unread;inbox' +6: '' +7: 'true' +8: 'USERNAME@FQDN' +9: 'NULL' +a: 'USER_FULL_NAME' == stderr == EOF test_expect_equal_file EXPECTED OUTPUT.clean diff --git a/test/test-lib.sh b/test/test-lib.sh index 6be5d11f..35bea097 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -561,26 +561,6 @@ notmuch_built_with_sanitize () { 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_dir_sanitize | notmuch_built_with_sanitize } -- 2.25.1