Skip to content

Commit cc2efd3

Browse files
committed
Fix test_https_over_http_error on Windows with OpenSSL 3.1+
On Windows, the TCP reset (RST) takes a different code path than Linux, causing OpenSSL 3.1+ to report 'wrong version number' rather than 'record layer failure'. Accept either string when IS_ABOVE_OPENSSL31 is True — the same pattern used in CPython's own test_ssl.py.
1 parent 18f4ba8 commit cc2efd3

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

cheroot/test/test_ssl.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,22 @@ def test_https_over_http_error(http_server, ip_addr):
697697
http.client.HTTPSConnection(
698698
f'{interface}:{port}',
699699
).request('GET', '/')
700-
expected_substring = (
701-
'record layer failure'
702-
if IS_ABOVE_OPENSSL31
703-
else 'wrong version number'
704-
if IS_ABOVE_OPENSSL10
705-
else 'unknown protocol'
706-
)
707-
assert expected_substring in ssl_err.value.args[-1]
700+
actual_error = ssl_err.value.args[-1]
701+
if IS_ABOVE_OPENSSL31:
702+
# OpenSSL 3.1+ usually reports 'record layer failure', but some builds
703+
# report 'wrong version number' instead (e.g. Python 3.14.6 on Windows
704+
# where the TCP reset takes a different code path). See CPython:
705+
# https://github.com/python/cpython/blob/\
706+
# 1b9fe5c7226eccc8b269a7443148033080399f43\
707+
# /Lib/test/test_ssl.py#L5705
708+
assert (
709+
'record layer failure' in actual_error
710+
or 'wrong version number' in actual_error
711+
), actual_error
712+
elif IS_ABOVE_OPENSSL10:
713+
assert 'wrong version number' in actual_error
714+
else:
715+
assert 'unknown protocol' in actual_error
708716

709717

710718
def test_http_over_https_no_data(mocker):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed ``test_https_over_http_error`` failing on Windows with OpenSSL 3.1+,
2+
where the SSL error message is ``wrong version number`` rather than
3+
``record layer failure`` -- by :user:`julianz-`.

0 commit comments

Comments
 (0)