[PATCH 06 of 10] tests: improve test-patchbomb-tls.t by by logging errors and data

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


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1687787499 -7200
#      Mon Jun 26 15:51:39 2023 +0200
# Branch stable
# Node ID 22a8aa225c38766ddd29c51348dd4484b5e58f59
# Parent  54a4e277ff2c32c7fd67bebfb04cac25034cc2b2
tests: improve test-patchbomb-tls.t by by logging errors and data

The actual SSL error might be like:
  ::1 ssl error: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1002)
and will probably vary so much that it can't be checked in the test. It is
however very useful when debugging failures.

diff --git a/tests/dummysmtpd.py b/tests/dummysmtpd.py
--- a/tests/dummysmtpd.py
+++ b/tests/dummysmtpd.py
@@ -28,7 +28,10 @@ class dummysmtpserver(smtpd.SMTPServer):
         smtpd.SMTPServer.__init__(self, localaddr, remoteaddr=None)
 
     def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
-        log('%s from=%s to=%s\n' % (peer[0], mailfrom, ', '.join(rcpttos)))
+        log(
+            '%s from=%s to=%s\n%s\n'
+            % (peer[0], mailfrom, ', '.join(rcpttos), data.decode())
+        )
 
     def handle_error(self):
         # On Windows, a bad SSL connection sometimes generates a WSAECONNRESET.
@@ -54,8 +57,8 @@ class dummysmtpsecureserver(dummysmtpser
         try:
             # wrap_socket() would block, but we don't care
             conn = sslutil.wrapserversocket(conn, ui, certfile=self._certfile)
-        except ssl.SSLError:
-            log('%s ssl error\n' % addr[0])
+        except ssl.SSLError as e:
+            log('%s ssl error: %s\n' % (addr[0], e))
             conn.close()
             return
         smtpd.SMTPChannel(self, conn, addr)
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
@@ -76,7 +76,7 @@ Without certificates:
   [150]
 
   $ cat ../log
-  * ssl error (glob)
+  * ssl error: * (glob)
   $ : > ../log
 
 With global certificates:
@@ -92,6 +92,35 @@ With global certificates:
 
   $ cat ../log
   * from=quux to=foo, bar (glob)
+  MIME-Version: 1.0
+  Content-Type: text/plain; charset="us-ascii"
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH] a
+  X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  X-Mercurial-Series-Index: 1
+  X-Mercurial-Series-Total: 1
+  Message-Id: <*@test-hostname> (glob)
+  X-Mercurial-Series-Id: <*@test-hostname> (glob)
+  User-Agent: Mercurial-patchbomb* (glob)
+  Date: * (glob)
+  From: quux
+  To: foo
+  Cc: bar
+  
+  # HG changeset patch
+  # User test
+  # Date 1 0
+  #      Thu Jan 01 00:00:01 1970 +0000
+  # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  # Parent  0000000000000000000000000000000000000000
+  a
+  
+  diff -r 0000000000000000000000000000000000000000 -r 8580ff50825a50c8f716709acdf8de0deddcd6ab a
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
   $ : > ../log
 
 With invalid certificates:
@@ -105,7 +134,7 @@ With invalid certificates:
   [255]
 
   $ cat ../log
-  * ssl error (glob)
+  * ssl error: * (glob)
   $ : > ../log
 
   $ cd ..



More information about the Mercurial-devel mailing list