Skip to content

Commit cac7478

Browse files
authored
Fix tests on Windows, add Windows CI (#1186)
* fix tests on Windows, add Windows CI * remove test safeguards from coverage
1 parent 3517764 commit cac7478

File tree

4 files changed

+48
-35
lines changed

4 files changed

+48
-35
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- {VERSION: "3.11", TOXENV: "py311"}
1919
- {VERSION: "pypy-3.7", TOXENV: "pypy3"}
2020
- {VERSION: "pypy-3.8", TOXENV: "pypy3"}
21+
- {VERSION: "3.11", TOXENV: "py311-useWheel", OS: "windows-2022" }
2122
# -cryptographyMain
2223
- {VERSION: "3.6", TOXENV: "py36-cryptographyMain", OS: "ubuntu-20.04"}
2324
- {VERSION: "3.7", TOXENV: "py37-cryptographyMain"}
@@ -47,7 +48,7 @@ jobs:
4748
- {VERSION: "3.9", TOXENV: "flake8"}
4849
- {VERSION: "3.6", TOXENV: "py36-mypy", OS: "ubuntu-20.04"}
4950
- {VERSION: "3.9", TOXENV: "docs"}
50-
name: "${{ matrix.PYTHON.TOXENV }}"
51+
name: "${{ matrix.PYTHON.TOXENV }}${{ matrix.PYTHON.OS && format(' on {0}', matrix.PYTHON.OS) || '' }}"
5152
steps:
5253
- uses: actions/checkout@v3
5354
- name: Setup python

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Installation script for the OpenSSL package.
99
"""
1010

11-
import codecs
1211
import os
1312
import re
1413

@@ -21,10 +20,12 @@
2120

2221
def read_file(*parts):
2322
"""
24-
Build an absolute path from *parts* and and return the contents of the
23+
Build an absolute path from *parts* and return the contents of the
2524
resulting file. Assume UTF-8 encoding.
2625
"""
27-
with codecs.open(os.path.join(HERE, *parts), "rb", "ascii") as f:
26+
with open(
27+
os.path.join(HERE, *parts), "r", encoding="utf-8", newline=None
28+
) as f:
2829
return f.read()
2930

3031

tests/test_crypto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ def check_recovery(
25242524
b"-passin",
25252525
b"pass:" + passwd,
25262526
*extra,
2527-
)
2527+
).replace(b"\r\n", b"\n")
25282528
assert recovered_key[-len(key) :] == key
25292529
if cert:
25302530
recovered_cert = _runopenssl(
@@ -2536,7 +2536,7 @@ def check_recovery(
25362536
b"pass:" + passwd,
25372537
b"-nokeys",
25382538
*extra,
2539-
)
2539+
).replace(b"\r\n", b"\n")
25402540
assert recovered_cert[-len(cert) :] == cert
25412541
if ca:
25422542
recovered_cert = _runopenssl(
@@ -2548,7 +2548,7 @@ def check_recovery(
25482548
b"pass:" + passwd,
25492549
b"-nokeys",
25502550
*extra,
2551-
)
2551+
).replace(b"\r\n", b"\n")
25522552
assert recovered_cert[-len(ca) :] == ca
25532553

25542554
def verify_pkcs12_container(self, p12):

tests/test_ssl.py

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,23 +1140,30 @@ def _load_verify_directory_locations_capath(self, capath):
11401140

11411141
self._load_verify_locations_test(None, capath)
11421142

1143-
def test_load_verify_directory_bytes_capath(self, tmpfile):
1143+
@pytest.mark.parametrize(
1144+
"pathtype",
1145+
[
1146+
"ascii_path",
1147+
pytest.param(
1148+
"unicode_path",
1149+
marks=pytest.mark.skipif(
1150+
platform == "win32",
1151+
reason="Unicode paths not supported on Windows",
1152+
),
1153+
),
1154+
],
1155+
)
1156+
@pytest.mark.parametrize("argtype", ["bytes_arg", "unicode_arg"])
1157+
def test_load_verify_directory_capath(self, pathtype, argtype, tmpfile):
11441158
"""
11451159
`Context.load_verify_locations` accepts a directory name as a `bytes`
11461160
instance and uses the certificates within for verification purposes.
11471161
"""
1148-
self._load_verify_directory_locations_capath(
1149-
tmpfile + NON_ASCII.encode(getfilesystemencoding())
1150-
)
1151-
1152-
def test_load_verify_directory_unicode_capath(self, tmpfile):
1153-
"""
1154-
`Context.load_verify_locations` accepts a directory name as a `unicode`
1155-
instance and uses the certificates within for verification purposes.
1156-
"""
1157-
self._load_verify_directory_locations_capath(
1158-
tmpfile.decode(getfilesystemencoding()) + NON_ASCII
1159-
)
1162+
if pathtype == "unicode_path":
1163+
tmpfile += NON_ASCII.encode(getfilesystemencoding())
1164+
if argtype == "unicode_arg":
1165+
tmpfile = tmpfile.decode(getfilesystemencoding())
1166+
self._load_verify_directory_locations_capath(tmpfile)
11601167

11611168
def test_load_verify_locations_wrong_args(self):
11621169
"""
@@ -2838,23 +2845,24 @@ def test_wantWriteError(self):
28382845
"""
28392846
client_socket, server_socket = socket_pair()
28402847
# Fill up the client's send buffer so Connection won't be able to write
2841-
# anything. Only write a single byte at a time so we can be sure we
2848+
# anything. Start by sending larger chunks (Windows Socket I/O is slow)
2849+
# and continue by writing a single byte at a time so we can be sure we
28422850
# completely fill the buffer. Even though the socket API is allowed to
28432851
# signal a short write via its return value it seems this doesn't
28442852
# always happen on all platforms (FreeBSD and OS X particular) for the
28452853
# very last bit of available buffer space.
2846-
msg = b"x"
2847-
for i in range(1024 * 1024 * 64):
2848-
try:
2849-
client_socket.send(msg)
2850-
except error as e:
2851-
if e.errno == EWOULDBLOCK:
2852-
break
2853-
raise
2854-
else:
2855-
pytest.fail(
2856-
"Failed to fill socket buffer, cannot test BIO want write"
2857-
)
2854+
for msg in [b"x" * 65536, b"x"]:
2855+
for i in range(1024 * 1024 * 64):
2856+
try:
2857+
client_socket.send(msg)
2858+
except error as e:
2859+
if e.errno == EWOULDBLOCK:
2860+
break
2861+
raise # pragma: no cover
2862+
else: # pragma: no cover
2863+
pytest.fail(
2864+
"Failed to fill socket buffer, cannot test BIO want write"
2865+
)
28582866

28592867
ctx = Context(SSLv23_METHOD)
28602868
conn = Connection(ctx, client_socket)
@@ -3753,13 +3761,16 @@ def test_unexpected_EOF(self):
37533761
"""
37543762
If the connection is lost before an orderly SSL shutdown occurs,
37553763
`OpenSSL.SSL.SysCallError` is raised with a message of
3756-
"Unexpected EOF".
3764+
"Unexpected EOF" (or WSAECONNRESET on Windows).
37573765
"""
37583766
server_conn, client_conn = loopback()
37593767
client_conn.sock_shutdown(SHUT_RDWR)
37603768
with pytest.raises(SysCallError) as err:
37613769
server_conn.recv(1024)
3762-
assert err.value.args == (-1, "Unexpected EOF")
3770+
if platform == "win32":
3771+
assert err.value.args == (10054, "WSAECONNRESET")
3772+
else:
3773+
assert err.value.args == (-1, "Unexpected EOF")
37633774

37643775
def _check_client_ca_list(self, func):
37653776
"""

0 commit comments

Comments
 (0)