From f36975b6792f6b702dc9184adcdb6e0d89ce23b4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 26 Oct 2017 12:29:24 +1100 Subject: [PATCH] tests/net_inet: Update tls test to work with CPython and incl new site. CPython only supports the server_hostname keyword arg via the SSLContext object, so use that instead of the top-level ssl.wrap_socket. This allows the test to run on CPython the same as uPy. Also add the "Host:" header to correctly make a GET request (for URLs that are hosted on other servers). This is not strictly needed to test the SSL connection but helps to debug things when printing the response. --- tests/net_inet/test_tls_sites.py | 5 ++++- tests/net_inet/test_tls_sites.py.exp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/net_inet/test_tls_sites.py b/tests/net_inet/test_tls_sites.py index 67345fd0b9..bf8071d087 100644 --- a/tests/net_inet/test_tls_sites.py +++ b/tests/net_inet/test_tls_sites.py @@ -6,6 +6,8 @@ try: import ussl as ssl except: import ssl + # CPython only supports server_hostname with SSLContext + ssl = ssl.SSLContext() def test_one(site, opts): @@ -22,7 +24,7 @@ def test_one(site, opts): else: s = ssl.wrap_socket(s) - s.write(b"GET / HTTP/1.0\r\n\r\n") + s.write(b"GET / HTTP/1.0\r\nHost: %s\r\n\r\n" % bytes(site, 'latin')) resp = s.read(4096) # print(resp) @@ -34,6 +36,7 @@ SITES = [ "google.com", "www.google.com", "api.telegram.org", + {"host": "api.pushbullet.com", "sni": True}, # "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", {"host": "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", "sni": True}, ] diff --git a/tests/net_inet/test_tls_sites.py.exp b/tests/net_inet/test_tls_sites.py.exp index 12732d1fa5..2f3c113d2f 100644 --- a/tests/net_inet/test_tls_sites.py.exp +++ b/tests/net_inet/test_tls_sites.py.exp @@ -1,4 +1,5 @@ google.com ok www.google.com ok api.telegram.org ok +api.pushbullet.com ok w9rybpfril.execute-api.ap-southeast-2.amazonaws.com ok