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 Jan 31, 2024
1 parent 60c4647 commit dcb177b
Show file tree
Hide file tree
Showing 3 changed files with 34 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.
4 changes: 4 additions & 0 deletions src/urllib3/contrib/emscripten/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,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
29 changes: 29 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,31 @@ 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 pytest

import urllib3
import urllib3.exceptions

http = urllib3.PoolManager()

with pytest.warns(urllib3.exceptions.InsecureRequestWarning):
http.request("GET", f"http://{host}:{port}")

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 dcb177b

Please sign in to comment.