| 1 | From 2a8fc126f6f7557b229eb5e74e691e8e319f27bb Mon Sep 17 00:00:00 2001
|
| 2 | From: julianz- <[email protected]>
|
| 3 | Date: Sat, 20 Jun 2026 19:14:18 -0700
|
| 4 | Subject: [PATCH 1/2] Fix test_https_over_http_error on Windows with OpenSSL
|
| 5 | 3.1+
|
| 6 | MIME-Version: 1.0
|
| 7 | Content-Type: text/plain; charset=UTF-8
|
| 8 | Content-Transfer-Encoding: 8bit
|
| 9 |
|
| 10 | On Windows, the TCP reset (RST) takes a different code path than Linux,
|
| 11 | causing OpenSSL 3.1+ to report 'wrong version number' rather than
|
| 12 | 'record layer failure'. Accept either string when IS_ABOVE_OPENSSL31
|
| 13 | is True — the same pattern used in CPython's own test_ssl.py.
|
| 14 | ---
|
| 15 | cheroot/test/test_ssl.py | 32 ++++++++++++++++------
|
| 16 | docs/changelog-fragments.d/828.contrib.rst | 3 ++
|
| 17 | 2 files changed, 26 insertions(+), 9 deletions(-)
|
| 18 | create mode 100644 docs/changelog-fragments.d/828.contrib.rst
|
| 19 |
|
| 20 | diff --git a/cheroot/test/test_ssl.py b/cheroot/test/test_ssl.py
|
| 21 | index 1859e6bc28..0a04d2bed6 100644
|
| 22 | |
| 23 | |
| 24 | @@ -527,7 +527,9 @@ def test_tls_client_auth( # noqa: C901, WPS213 # FIXME
|
| 25 | "'Remote end closed connection without response'))",
|
| 26 | )
|
| 27 |
|
| 28 | - assert any(e in err_text for e in expected_substrings)
|
| 29 | + assert any(e in err_text for e in expected_substrings), (
|
| 30 | + f'Unexpected error text: {err_text!r}'
|
| 31 | + )
|
| 32 |
|
| 33 |
|
| 34 | @pytest.mark.parametrize( # noqa: C901 # FIXME
|
| 35 | @@ -697,14 +699,26 @@ def test_https_over_http_error(http_server, ip_addr):
|
| 36 | http.client.HTTPSConnection(
|
| 37 | f'{interface}:{port}',
|
| 38 | ).request('GET', '/')
|
| 39 | - expected_substring = (
|
| 40 | - 'record layer failure'
|
| 41 | - if IS_ABOVE_OPENSSL31
|
| 42 | - else 'wrong version number'
|
| 43 | - if IS_ABOVE_OPENSSL10
|
| 44 | - else 'unknown protocol'
|
| 45 | - )
|
| 46 | - assert expected_substring in ssl_err.value.args[-1]
|
| 47 | + underlying_error_string = str(ssl_err.value)
|
| 48 | + if IS_ABOVE_OPENSSL31 and IS_WINDOWS:
|
| 49 | + # On Windows, the TCP reset (RST) is surfaced before OpenSSL processes
|
| 50 | + # the server's response, yielding 'wrong version number' rather than
|
| 51 | + # the usual 'record layer failure'. See CPython's own test_ssl.py:
|
| 52 | + # https://github.com/python/cpython/blob/\
|
| 53 | + # 1b9fe5c7226eccc8b269a7443148033080399f43\
|
| 54 | + # /Lib/test/test_ssl.py#L5705
|
| 55 | + assert 'wrong version number' in underlying_error_string
|
| 56 | + elif IS_ABOVE_OPENSSL31:
|
| 57 | + # Newer Python returns 'record layer failure'; Python 3.8 on macOS
|
| 58 | + # returns 'wrong version number' despite OpenSSL >= 3.1.
|
| 59 | + assert (
|
| 60 | + 'record layer failure' in underlying_error_string
|
| 61 | + or 'wrong version number' in underlying_error_string
|
| 62 | + )
|
| 63 | + elif IS_ABOVE_OPENSSL10:
|
| 64 | + assert 'wrong version number' in underlying_error_string
|
| 65 | + else: # pragma: no cover
|
| 66 | + assert 'unknown protocol' in underlying_error_string
|
| 67 |
|
| 68 |
|
| 69 | def test_http_over_https_no_data(mocker):
|
| 70 | diff --git a/docs/changelog-fragments.d/828.contrib.rst b/docs/changelog-fragments.d/828.contrib.rst
|
| 71 | new file mode 100644
|
| 72 | index 0000000000..831d85ab91
|
| 73 | |
| 74 | |
| 75 | @@ -0,0 +1,3 @@
|
| 76 | +Fixed ``test_https_over_http_error`` failing on Windows with OpenSSL 3.1+,
|
| 77 | +where the SSL error message is ``wrong version number`` rather than
|
| 78 | +``record layer failure`` -- by :user:`julianz-`.
|
| 79 |
|
| 80 | From 5bc6aef96dd4def3f20b688798a81e39a3d63574 Mon Sep 17 00:00:00 2001
|
| 81 | From: julianz- <[email protected]>
|
| 82 | Date: Sun, 12 Jul 2026 18:26:22 -0700
|
| 83 | Subject: [PATCH 2/2] Simplify test_https_over_http_error assertions and error
|
| 84 | handling
|
| 85 | MIME-Version: 1.0
|
| 86 | Content-Type: text/plain; charset=UTF-8
|
| 87 | Content-Transfer-Encoding: 8bit
|
| 88 |
|
| 89 | Remove redundant custom assertion message — pytest already shows the
|
| 90 | relevant values on failure. Merge the Windows-specific OpenSSL 3.1
|
| 91 | branch into the general case since both accept the same error strings.
|
| 92 | ---
|
| 93 | cheroot/test/test_ssl.py | 18 ++++--------------
|
| 94 | 1 file changed, 4 insertions(+), 14 deletions(-)
|
| 95 |
|
| 96 | diff --git a/cheroot/test/test_ssl.py b/cheroot/test/test_ssl.py
|
| 97 | index 0a04d2bed6..6df3696c74 100644
|
| 98 | |
| 99 | |
| 100 | @@ -527,9 +527,7 @@ def test_tls_client_auth( # noqa: C901, WPS213 # FIXME
|
| 101 | "'Remote end closed connection without response'))",
|
| 102 | )
|
| 103 |
|
| 104 | - assert any(e in err_text for e in expected_substrings), (
|
| 105 | - f'Unexpected error text: {err_text!r}'
|
| 106 | - )
|
| 107 | + assert any(e in err_text for e in expected_substrings)
|
| 108 |
|
| 109 |
|
| 110 | @pytest.mark.parametrize( # noqa: C901 # FIXME
|
| 111 | @@ -700,17 +698,9 @@ def test_https_over_http_error(http_server, ip_addr):
|
| 112 | f'{interface}:{port}',
|
| 113 | ).request('GET', '/')
|
| 114 | underlying_error_string = str(ssl_err.value)
|
| 115 | - if IS_ABOVE_OPENSSL31 and IS_WINDOWS:
|
| 116 | - # On Windows, the TCP reset (RST) is surfaced before OpenSSL processes
|
| 117 | - # the server's response, yielding 'wrong version number' rather than
|
| 118 | - # the usual 'record layer failure'. See CPython's own test_ssl.py:
|
| 119 | - # https://github.com/python/cpython/blob/\
|
| 120 | - # 1b9fe5c7226eccc8b269a7443148033080399f43\
|
| 121 | - # /Lib/test/test_ssl.py#L5705
|
| 122 | - assert 'wrong version number' in underlying_error_string
|
| 123 | - elif IS_ABOVE_OPENSSL31:
|
| 124 | - # Newer Python returns 'record layer failure'; Python 3.8 on macOS
|
| 125 | - # returns 'wrong version number' despite OpenSSL >= 3.1.
|
| 126 | + if IS_ABOVE_OPENSSL31:
|
| 127 | + # 'record layer failure' is typical, but Windows and macOS/Python 3.8
|
| 128 | + # yield 'wrong version number' instead.
|
| 129 | assert (
|
| 130 | 'record layer failure' in underlying_error_string
|
| 131 | or 'wrong version number' in underlying_error_string
|