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.
This commit is contained in:
Damien George 2017-10-26 12:29:24 +11:00
parent 328c1e78be
commit f36975b679
2 changed files with 5 additions and 1 deletions

View File

@ -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},
]

View File

@ -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