r46969 - 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 Thu, 10 Mar 2016 02:48:33 -0700 (MST)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Thu Mar 10 02:48:28 2016
New Revision: 46969
Added:
branches/release-16.0.0-8210/twisted/topfiles/8222.bugfix
Modified:
branches/release-16.0.0-8210/twisted/internet/endpoints.py
branches/release-16.0.0-8210/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: branches/release-16.0.0-8210/twisted/internet/endpoints.py
==============================================================================
--- branches/release-16.0.0-8210/twisted/internet/endpoints.py (original)
+++ branches/release-16.0.0-8210/twisted/internet/endpoints.py Thu Mar 10 02:48:28 2016
@@ -1138,10 +1138,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: branches/release-16.0.0-8210/twisted/internet/test/test_endpoints.py
==============================================================================
--- branches/release-16.0.0-8210/twisted/internet/test/test_endpoints.py (original)
+++ branches/release-16.0.0-8210/twisted/internet/test/test_endpoints.py Thu Mar 10 02:48:28 2016
@@ -2567,15 +2567,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):