[PATCH 05 of 10] tests: show test-patchbomb-tls.t smtp server log

Mads Kiilerich mads at kiilerich.com
Wed Jun 28 00:06:50 UTC 2023


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1679586524 -3600
#      Thu Mar 23 16:48:44 2023 +0100
# Branch stable
# Node ID 54a4e277ff2c32c7fd67bebfb04cac25034cc2b2
# Parent  8687d17528a1fe764572c402f2d0198d5a6c8fbc
tests: show test-patchbomb-tls.t smtp server log

Improve test coverage by exposing what the smtp server actually receives.
Make dummystmtpd redirect stderr to a log file.

diff --git a/tests/dummysmtpd.py b/tests/dummysmtpd.py
--- a/tests/dummysmtpd.py
+++ b/tests/dummysmtpd.py
@@ -93,6 +93,7 @@ def main():
     op.add_option('--pid-file', metavar='FILE')
     op.add_option('--tls', choices=['none', 'smtps'], default='none')
     op.add_option('--certificate', metavar='FILE')
+    op.add_option('--logfile', metavar='FILE')
 
     opts, args = op.parse_args()
     if opts.tls == 'smtps' and not opts.certificate:
@@ -113,6 +114,7 @@ def main():
         runfn=run,
         runargs=[pycompat.sysexecutable, pycompat.fsencode(__file__)]
         + pycompat.sysargv[1:],
+        logfile=opts.logfile,
     )
 
 
diff --git a/tests/test-patchbomb-tls.t b/tests/test-patchbomb-tls.t
--- a/tests/test-patchbomb-tls.t
+++ b/tests/test-patchbomb-tls.t
@@ -5,7 +5,7 @@ Set up SMTP server:
   $ CERTSDIR="$TESTDIR/sslcerts"
   $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub.pem" >> server.pem
 
-  $ "$PYTHON" "$TESTDIR/dummysmtpd.py" -p $HGPORT --pid-file a.pid -d \
+  $ "$PYTHON" "$TESTDIR/dummysmtpd.py" -p $HGPORT --pid-file a.pid --logfile log -d \
   > --tls smtps --certificate `pwd`/server.pem
   listening at localhost:$HGPORT (?)
   $ cat a.pid >> $DAEMON_PIDS
@@ -75,6 +75,10 @@ Without certificates:
   (see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error or set hostsecurity.localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e to trust this server)
   [150]
 
+  $ cat ../log
+  * ssl error (glob)
+  $ : > ../log
+
 With global certificates:
 
   $ try --debug --config web.cacerts="$CERTSDIR/pub.pem"
@@ -86,6 +90,10 @@ With global certificates:
   (verifying remote certificate)
   sending [PATCH] a ...
 
+  $ cat ../log
+  * from=quux to=foo, bar (glob)
+  $ : > ../log
+
 With invalid certificates:
 
   $ try --config web.cacerts="$CERTSDIR/pub-other.pem"
@@ -96,4 +104,8 @@ With invalid certificates:
   (?i)abort: .*?certificate.verify.failed.* (re)
   [255]
 
+  $ cat ../log
+  * ssl error (glob)
+  $ : > ../log
+
   $ cd ..



More information about the Mercurial-devel mailing list