Add and use a new HTTPS handler, error reporting, and urlopen wrapper.
Review Request #14943 — Created March 18, 2026 and updated
This introduces
reviewboard.certs.http, which contains a URL opener,
CertificateVerificationHTTPSHandler. This takes care of generating a
suitable SSL context based on the certificate manager, and handles the
conversion of SSL/TLS errors to our own exceptions.If an
SSLErroris raised, it will be converted into a
CertificateVerificationError, complete with aCertificateinstance
fetched from the server (asSSLErrordoesn't contain this). This means
individual call sites don't have to convert SSL errors anymore.A
urlopen()method in the same module is available, which can be used
as a direct replacement forurllib.request.urlopen(). If communicating
over HTTPS, this will make use of our new handler. Otherwise, it's the
exact same as calling the originalurlopen().All
urlopen()call sites have been updated to use this. They were
recently updated to usebuild_urlopen_kwargs(), but that's no longer
required. In fact, this method is now deprecated in favor of the new
handler.The hosting service HTTP support makes use of the new handler directly,
allowing it to leverage the central context building and error handling.Unless a legacy
UnverifiedCertificateErroris explicitly returned by a
hosting service or SCMTool, all call sites will now use the modern
CertificateVerificationError.
All unit tests pass.
Manually tried adding repositories using bare SCMTools and hosting
services, verifying I received the cert verification banner each time.
Tested this with a variety of https://badssl.com endpoints.Verified that trusting the cert created a stored cert entry and that
further access worked.
| Summary | ID |
|---|---|
| be82b52f07607f360f9bb63fcfa26fbd479b320e |
| Description | From | Last Updated |
|---|---|---|
|
Can we add some tests for the new urlopen? Would be nice to at least check these: https URL uses … |
|
|
|
line too long (101 > 79 characters) Column: 80 Error code: E501 |
|
|
|
Typo: Reqest -> Request |
|
|
|
Should we be getting urlopen from reviewboard.certs.http here? This change is going back to just pure regular stdlib urlopen. |
|
|
|
This used to be guarded with the if context is not None check. We probably should only add the handler … |
|
|
|
multiple spaces before keyword Column: 28 Error code: E272 |
|
-
-
Can we add some tests for the new
urlopen? Would be nice to at least check these:- https URL uses the custom handler
- Non-https URL falls through to stdlib urlopen
- Request objects are handled correctly
- local_site and cert_manager kwargs are forwarded
-
-
Should we be getting
urlopenfromreviewboard.certs.httphere? This change is going back to just pure regular stdlib urlopen. -
This used to be guarded with the
if context is not Nonecheck. We probably should only add the handler whenparsed_url.scheme == 'https'