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
Emit insecure proxy event when using unverified proxies #3070
Open
tushar5526
wants to merge
11
commits into
urllib3:main
Choose a base branch
from
tushar5526:2791
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
96b5363
Emit insecure proxy event when using unverified proxies
tushar5526 747e233
Add tests and update docs for changes.
tushar5526 5054829
fix: Update InsecureRequestWarning message to use _tunnel_host when H…
tushar5526 015db1b
Merge branch 'urllib3:main' into 2791
tushar5526 32c6a73
Use absolute URL in proxy test case
tushar5526 2a024b4
Assert host in warning strings
tushar5526 0a07cfc
Add testcases for HTTPs to HTTP proxies
tushar5526 150172d
Fix lint errors
tushar5526 8ece270
Merge branch 'main' into 2791
tushar5526 a0186f5
Merge branch 'main' into 2791
illia-v 93279fc
Merge branch 'main' into 2791
illia-v File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Emit ``InsecureProxyWarning`` when the proxy connection is not verified but the proxy.scheme is https |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,10 @@ | |
|
||
import urllib3 | ||
from dummyserver.testcase import ( | ||
HTTPSHypercornDummyServerTestCase, | ||
HypercornDummyProxyTestCase, | ||
HypercornDummyServerTestCase, | ||
) | ||
from urllib3.exceptions import InsecureRequestWarning | ||
from urllib3.exceptions import InsecureProxyWarning, InsecureRequestWarning | ||
|
||
from ..test_no_ssl import TestWithoutSSL | ||
|
||
|
@@ -24,13 +24,32 @@ def test_simple(self) -> None: | |
assert r.status == 200, r.data | ||
|
||
|
||
class TestHTTPSWithoutSSL(HTTPSHypercornDummyServerTestCase, TestWithoutSSL): | ||
class TestHTTPSWithoutSSL(HypercornDummyProxyTestCase, TestWithoutSSL): | ||
def test_simple(self) -> None: | ||
with urllib3.HTTPSConnectionPool( | ||
self.host, self.port, cert_reqs="NONE" | ||
self.https_host, self.https_port, cert_reqs="NONE" | ||
) as pool: | ||
with pytest.warns(InsecureRequestWarning): | ||
try: | ||
pool.request("GET", "/") | ||
except urllib3.exceptions.SSLError as e: | ||
assert "SSL module is not available" in str(e) | ||
|
||
def test_simple_proxy(self) -> None: | ||
https_proxy_url = f"https://{self.proxy_host}:{int(self.https_proxy_port)}" | ||
with urllib3.ProxyManager(https_proxy_url, cert_reqs="NONE") as pool: | ||
with pytest.warns((InsecureProxyWarning, InsecureRequestWarning)) as record: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes pytest check that at least one of the two warnings is raised, not that both of them are raised sequentially |
||
try: | ||
pool.request("GET", "https://urllib3.readthedocs.io") | ||
except urllib3.exceptions.SSLError as e: | ||
assert "SSL module is not available" in str(e) | ||
assert "localhost" in str(record[0].message) | ||
assert "urllib3.readthedocs.io" in str(record[1].message) | ||
|
||
with pytest.warns((InsecureProxyWarning, InsecureRequestWarning)) as record: | ||
try: | ||
pool.request("GET", f"http://{self.http_host}:{self.http_port}") | ||
except urllib3.exceptions.SSLError as e: | ||
assert "SSL module is not available" in str(e) | ||
assert "localhost" in str(record[0].message) | ||
assert self.http_host in str(record[1].message) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to test both HTTPS->HTTP and HTTPS->HTTPS proxy scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the expected HTTPS -> HTTP proxy scenario? Currently, it throws an
InsecureRequestWarning
asconn.is_verified
is set toFalse
while using HTTPs->HTTP connection. Should it only throwInsecureProxyWarning
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this Seth's suggestion is related to #3070 (comment).
You change the message for
InsecureRequestWarning
, it would be good to test what host is included in the message when a proxy is used as well as changingtest_simple
to check what host is used there.