Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r58773:4a5b45b6662a
Date: 2012-11-07 01:19 +0100
http://bitbucket.org/pypy/pypy/changeset/4a5b45b6662a/

Log:    _ssl: Basic test for the server_hostname parameter, enough to catch
        some failures.

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -238,11 +238,12 @@
         assert w_sock is not None
         # server_hostname is either None (or absent), or to be encoded
         # using the idna encoding.
-        if space.is_w(w_server_hostname, space.w_None):
+        if space.is_none(w_server_hostname):
             hostname = None
         else:
             hostname = space.bytes_w(
-                space.call_method(w_server_hostname, "idna"))
+                space.call_method(w_server_hostname,
+                                  "encode", space.wrap("idna")))
 
         if hostname and not HAS_SNI:
             raise OperationError(space.w_ValueError,
diff --git a/pypy/module/_ssl/test/test_ssl.py 
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -66,7 +66,7 @@
 
 
 class AppTestConnectedSSL:
-    spaceconfig = dict(usemodules=('_ssl', '_socket', 'struct'))
+    spaceconfig = dict(usemodules=('_ssl', '_socket', 'struct', 'array'))
 
     def setup_method(self, method):
         # https://www.verisign.net/
@@ -142,12 +142,19 @@
             raise
         raises(AttributeError, ss.write, b"hello\n")
         del ss; gc.collect()
+
+    def test_server_hostname(self):
+        import socket, _ssl, gc
+        ctx = _ssl._SSLContext(_ssl.PROTOCOL_SSLv23)
+        ss = ctx._wrap_socket(self.s, False,
+                              server_hostname="svn.python.org")
+        self.s.close()
+        del ss; gc.collect()
         
 
 class AppTestConnectedSSL_Timeout(AppTestConnectedSSL):
     # Same tests, with a socket timeout
     # to exercise the poll() calls
-    spaceconfig = dict(usemodules=('_ssl', '_socket', 'struct'))
 
     def setup_class(cls):
         cls.space.appexec([], """():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to