Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions cheroot/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,21 @@ def test_https_over_http_error(http_server, ip_addr):
http.client.HTTPSConnection(
f'{interface}:{port}',
).request('GET', '/')
expected_substring = (
'record layer failure'
if IS_ABOVE_OPENSSL31
else 'wrong version number'
if IS_ABOVE_OPENSSL10
else 'unknown protocol'
)
assert expected_substring in ssl_err.value.args[-1]
actual_error = ssl_err.value.args[-1]
if IS_ABOVE_OPENSSL31 and IS_WINDOWS:
# On Windows, the TCP reset (RST) is surfaced before OpenSSL processes
# the server's response, yielding 'wrong version number' rather than
# the usual 'record layer failure'. See CPython's own test_ssl.py:
# https://github.com/python/cpython/blob/\
# 1b9fe5c7226eccc8b269a7443148033080399f43\
# /Lib/test/test_ssl.py#L5705
assert 'wrong version number' in actual_error
elif IS_ABOVE_OPENSSL31:
assert 'record layer failure' in actual_error
elif IS_ABOVE_OPENSSL10:
assert 'wrong version number' in actual_error
else: # pragma: no cover
assert 'unknown protocol' in actual_error


def test_http_over_https_no_data(mocker):
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog-fragments.d/828.contrib.rst

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this patch doesn't fix a bug in Cheroot's runtime, it shouldn't be listed among bugfixes in the change log. Fixing a test is infra work. So it could be a contrib note. Perhaps, a packaging note when we declare that we support new things (like a new Python version, a new OS or a new dep in this case).

Though, feel free to opt out of attaching a change note if it doesn't feel important to surface to the change log audience. You can add the bot:chronographer:skip label and the bot will stop flagging a missing note in the PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. I changed to a contrib note.

Regarding CPython, I get your idea but it sounds complicated. I was thinking before the issue was the version of OpenSSL but apparently macOS 15 CI runners use Python 3.14.6 with the same bundled OpenSSL 3.6.3 as Windows, but unlike Windows, macOS was already returning the correct record layer failure error. So I have modified the code the check for Windows in addition to the OpenSSL version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also symlink this note to 655 and 645, mentioning the prior art/contrib by radez?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's probably a good idea to normalize these into a unified check where possible. Maybe, migrating to requests in tests over time would be a better solution than trying to rely on low-level stdlib stuff. But this is something to think about separately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the intent but wouldn't this make error extraction more complex? requests wraps the SSL error through urllib3, so accessing the underlying message requires a deeper chain than ssl_err.value.args[-1]?

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed ``test_https_over_http_error`` failing on Windows with OpenSSL 3.1+,
where the SSL error message is ``wrong version number`` rather than
``record layer failure`` -- by :user:`julianz-`.
Loading