r46886 - Merge cert-chain-reg-8222: Fix serverFromString's SSL parsing having an incorrect error message when an empty chain file is given

hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: hawkowl
Date: Wed Mar  2 23:55:23 2016
New Revision: 46886

Added:
   trunk/twisted/topfiles/8222.bugfix
Modified:
   trunk/twisted/internet/endpoints.py
   trunk/twisted/internet/test/test_endpoints.py

Log:
Merge cert-chain-reg-8222: Fix serverFromString's SSL parsing having an incorrect error message when an empty chain file is given

Author: hawkowl
Reviewer: adiroiban
Fixes: #8222

Modified: trunk/twisted/internet/endpoints.py
==============================================================================
--- trunk/twisted/internet/endpoints.py	(original)
+++ trunk/twisted/internet/endpoints.py	Wed Mar  2 23:55:23 2016
@@ -1137,10 +1137,9 @@
     keyPEM = FilePath(privateKey).getContent()
     privateCertificate = ssl.PrivateCertificate.loadPEM(certPEM + keyPEM)
     if extraCertChain is not None:
-        extraCertChain = FilePath(extraCertChain).getContent()
         matches = re.findall(
             r'(-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----)',
-            nativeString(extraCertChain),
+            nativeString(FilePath(extraCertChain).getContent()),
             flags=re.DOTALL
         )
         chainCertificates = [ssl.Certificate.loadPEM(chainCertPEM).original

Modified: trunk/twisted/internet/test/test_endpoints.py
==============================================================================
--- trunk/twisted/internet/test/test_endpoints.py	(original)
+++ trunk/twisted/internet/test/test_endpoints.py	Wed Mar  2 23:55:23 2016
@@ -2575,15 +2575,20 @@
         # The endpoint string is the same as in the valid case except for
         # a different chain file.  We use an empty temp file which obviously
         # will never contain any certificates.
-        self.assertRaises(
-            ValueError,
-            endpoints.serverFromString,
-            object(),
-            self.SSL_CHAIN_TEMPLATE % (
-                escapedPEMPathName,
-                endpoints.quoteStringArgument(fp.path),
+        with self.assertRaises(ValueError) as caught:
+            endpoints.serverFromString(
+                object(),
+                self.SSL_CHAIN_TEMPLATE % (
+                    escapedPEMPathName,
+                    endpoints.quoteStringArgument(fp.path),
+                )
             )
-        )
+
+        # The raised exception should list what file it is attempting to find
+        # the chain in.
+        self.assertEqual(str(caught.exception),
+                         ("Specified chain file '%s' doesn't contain any valid"
+                          " certificates in PEM format.") % (fp.path,))
 
 
     def test_sslDHparameters(self):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.