Skip to content

Commit

Permalink
Fix InsecureRequestWarning for HTTPS Emscripten requests (#3333)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson authored Feb 9, 2024
1 parent 25155d7 commit cfe52f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/3331.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where ``InsecureRequestWarning`` was emitted for HTTPS connections when using Emscripten.
5 changes: 5 additions & 0 deletions src/urllib3/contrib/emscripten/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
self.blocksize = blocksize
self.source_address = None
self.socket_options = None
self.is_verified = False

def set_tunnel(
self,
Expand Down Expand Up @@ -228,6 +229,10 @@ def __init__(

self.cert_reqs = None

# The browser will automatically verify all requests.
# We have no control over that setting.
self.is_verified = True

def set_cert(
self,
key_file: str | None = None,
Expand Down
25 changes: 25 additions & 0 deletions test/contrib/emscripten/test_emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,3 +947,28 @@ def count_calls(self, *args, **argv): # type: ignore[no-untyped-def]
assert count == 6

pyodide_test(selenium_coverage, testserver_http.http_host, find_unused_port())


@install_urllib3_wheel()
def test_insecure_requests_warning(
selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
) -> None:
@run_in_pyodide # type: ignore[misc]
def pyodide_test(selenium_coverage, host: str, port: int, https_port: int) -> None: # type: ignore[no-untyped-def]
import warnings

import urllib3
import urllib3.exceptions

http = urllib3.PoolManager()

with warnings.catch_warnings(record=True) as w:
http.request("GET", f"https://{host}:{https_port}")
assert len(w) == 0

pyodide_test(
selenium_coverage,
testserver_http.http_host,
testserver_http.http_port,
testserver_http.https_port,
)

0 comments on commit cfe52f9

Please sign in to comment.