Fix the import_crypto_module helper and factor some str/unicode helpers into the test util module
diff --git a/OpenSSL/ssl/context.c b/OpenSSL/ssl/context.c
index d4cae75..d6c844b 100644
--- a/OpenSSL/ssl/context.c
+++ b/OpenSSL/ssl/context.c
@@ -376,7 +376,7 @@
name_attr = asciiname;
}
#endif
- right_name = (PyText_CheckExact(name_attr) &&
+ right_name = (PyBytes_CheckExact(name_attr) &&
strcmp(name, PyBytes_AsString(name_attr)) == 0);
Py_DECREF(name_attr);
res = (PyTypeObject *)type;
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 5cbc105..a86bfac 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -23,18 +23,7 @@
from OpenSSL.crypto import CRL, Revoked, load_crl
from OpenSSL.crypto import NetscapeSPKI, NetscapeSPKIType
from OpenSSL.crypto import sign, verify
-from OpenSSL.test.util import TestCase
-
-
-try:
- bytes
-except NameError:
- def b(s):
- return s
- bytes = str
-else:
- def b(s):
- return s.encode("ascii")
+from OpenSSL.test.util import TestCase, bytes, b
root_cert_pem = b("""-----BEGIN CERTIFICATE-----
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 6132c54..75af963 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -19,7 +19,7 @@
from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD
from OpenSSL.SSL import OP_NO_SSLv2, OP_NO_SSLv3, OP_SINGLE_DH_USE
from OpenSSL.SSL import VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT, VERIFY_CLIENT_ONCE
-from OpenSSL.test.util import TestCase
+from OpenSSL.test.util import TestCase, bytes, b
from OpenSSL.test.test_crypto import cleartextCertificatePEM, cleartextPrivateKeyPEM
from OpenSSL.test.test_crypto import client_cert_pem, client_key_pem, server_cert_pem, server_key_pem, root_cert_pem
try:
@@ -57,10 +57,10 @@
# Let's pass some unencrypted data to make sure our socket connection is
# fine. Just one byte, so we don't have to worry about buffers getting
# filled up or fragmentation.
- server.send("x")
- assert client.recv(1024) == "x"
- client.send("y")
- assert server.recv(1024) == "y"
+ server.send(b("x"))
+ assert client.recv(1024) == b("x")
+ client.send(b("y"))
+ assert server.recv(1024) == b("y")
# Most of our callers want non-blocking sockets, make it easy for them.
server.setblocking(False)
diff --git a/OpenSSL/test/util.py b/OpenSSL/test/util.py
index bbe8492..61246a6 100644
--- a/OpenSSL/test/util.py
+++ b/OpenSSL/test/util.py
@@ -16,6 +16,17 @@
from OpenSSL.crypto import Error, _exception_from_error_queue
+try:
+ bytes = bytes
+except NameError:
+ def b(s):
+ return s
+ bytes = str
+else:
+ def b(s):
+ return s.encode("ascii")
+
+
class TestCase(TestCase):
"""
L{TestCase} adds useful testing functionality beyond what is available