Skip to content

Commit f36975b

Browse files
committed
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.
1 parent 328c1e7 commit f36975b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/net_inet/test_tls_sites.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import ussl as ssl
77
except:
88
import ssl
9+
# CPython only supports server_hostname with SSLContext
10+
ssl = ssl.SSLContext()
911

1012

1113
def test_one(site, opts):
@@ -22,7 +24,7 @@ def test_one(site, opts):
2224
else:
2325
s = ssl.wrap_socket(s)
2426

25-
s.write(b"GET / HTTP/1.0\r\n\r\n")
27+
s.write(b"GET / HTTP/1.0\r\nHost: %s\r\n\r\n" % bytes(site, 'latin'))
2628
resp = s.read(4096)
2729
# print(resp)
2830

@@ -34,6 +36,7 @@ def test_one(site, opts):
3436
"google.com",
3537
"www.google.com",
3638
"api.telegram.org",
39+
{"host": "api.pushbullet.com", "sni": True},
3740
# "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com",
3841
{"host": "w9rybpfril.execute-api.ap-southeast-2.amazonaws.com", "sni": True},
3942
]

tests/net_inet/test_tls_sites.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
google.com ok
22
www.google.com ok
33
api.telegram.org ok
4+
api.pushbullet.com ok
45
w9rybpfril.execute-api.ap-southeast-2.amazonaws.com ok

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy