Skip to content

Commit

Permalink
Fix issue where InsecureRequestWarning is emitted for HTTPS Emscripte…
Browse files Browse the repository at this point in the history
…n requests
  • Loading branch information
sethmlarson committed Feb 8, 2024
1 parent 9929d3c commit c5dc9ba
Show file tree
Hide file tree
Showing 3 changed files with 30 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
24 changes: 24 additions & 0 deletions test/contrib/emscripten/test_emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
import typing
import warnings

import pytest

Expand Down Expand Up @@ -947,3 +948,26 @@ 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 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 c5dc9ba

Please sign in to comment.