Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where InsecureRequestWarning is emitted for HTTPS Emscripte… #3333

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails because you haven't imported warnings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in 2758cab

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,
)