diff options
author | Thomas Grainger <tagrain@gmail.com> | 2023-04-24 19:12:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-24 13:12:46 -0500 |
commit | 4c4451b51ddb6e482a81a2607bdcdfe58da8651c (patch) | |
tree | d0fbac26d5257704f0d5c83c24be2d795695ffaa | |
parent | 214b184923388328919b0a4b0c15bff603aa51be (diff) | |
download | urllib3-4c4451b51ddb6e482a81a2607bdcdfe58da8651c.tar.gz |
Fix InsecureRequestWarning warnings in test suite
Co-authored-by: Seth Michael Larson <sethmichaellarson@gmail.com>
-rw-r--r-- | pyproject.toml | 1 | ||||
-rw-r--r-- | test/with_dummyserver/test_https.py | 6 | ||||
-rw-r--r-- | test/with_dummyserver/test_no_ssl.py | 12 | ||||
-rw-r--r-- | test/with_dummyserver/test_proxy_poolmanager.py | 7 | ||||
-rw-r--r-- | test/with_dummyserver/test_socketlevel.py | 4 |
5 files changed, 20 insertions, 10 deletions
diff --git a/pyproject.toml b/pyproject.toml index 804ffd9f..2afda13f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,7 +87,6 @@ filterwarnings = [ '''default:'urllib3\[secure\]' extra is deprecated and will be removed in urllib3 v2\.1\.0.*:DeprecationWarning''', '''default:'urllib3\.contrib\.pyopenssl' module is deprecated and will be removed in urllib3 v2\.1\.0.*:DeprecationWarning''', '''default:'urllib3\.contrib\.securetransport' module is deprecated and will be removed in urllib3 v2\.1\.0.*:DeprecationWarning''', - '''default:.*:urllib3.exceptions.InsecureRequestWarning''', '''default:No IPv6 support. Falling back to IPv4:urllib3.exceptions.HTTPWarning''', '''default:No IPv6 support. skipping:urllib3.exceptions.HTTPWarning''', '''default:ssl\.TLSVersion\.TLSv1 is deprecated:DeprecationWarning''', diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index 2a710bfd..de71c5a6 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -608,7 +608,8 @@ class TestHTTPS(HTTPSDummyServerTestCase): cert_reqs="CERT_NONE", ssl_minimum_version=self.tls_version(), ) as https_pool: - https_pool.request("GET", "/") + with pytest.warns(InsecureRequestWarning): + https_pool.request("GET", "/") def test_tunnel(self) -> None: """test the _tunnel behavior""" @@ -626,7 +627,8 @@ class TestHTTPS(HTTPSDummyServerTestCase): with mock.patch.object( conn, "_tunnel", create=True, return_value=None ) as conn_tunnel: - https_pool._make_request(conn, "GET", "/") + with pytest.warns(InsecureRequestWarning): + https_pool._make_request(conn, "GET", "/") conn_tunnel.assert_called_once_with() finally: conn.close() diff --git a/test/with_dummyserver/test_no_ssl.py b/test/with_dummyserver/test_no_ssl.py index 6529636c..b89f703f 100644 --- a/test/with_dummyserver/test_no_ssl.py +++ b/test/with_dummyserver/test_no_ssl.py @@ -5,8 +5,11 @@ Note: Import urllib3 inside the test functions to get the importblocker to work """ from __future__ import annotations +import pytest + import urllib3 from dummyserver.testcase import HTTPDummyServerTestCase, HTTPSDummyServerTestCase +from urllib3.exceptions import InsecureRequestWarning from ..test_no_ssl import TestWithoutSSL @@ -23,7 +26,8 @@ class TestHTTPSWithoutSSL(HTTPSDummyServerTestCase, TestWithoutSSL): with urllib3.HTTPSConnectionPool( self.host, self.port, cert_reqs="NONE" ) as pool: - try: - pool.request("GET", "/") - except urllib3.exceptions.SSLError as e: - assert "SSL module is not available" in str(e) + with pytest.warns(InsecureRequestWarning): + try: + pool.request("GET", "/") + except urllib3.exceptions.SSLError as e: + assert "SSL module is not available" in str(e) diff --git a/test/with_dummyserver/test_proxy_poolmanager.py b/test/with_dummyserver/test_proxy_poolmanager.py index 699467f2..f4620643 100644 --- a/test/with_dummyserver/test_proxy_poolmanager.py +++ b/test/with_dummyserver/test_proxy_poolmanager.py @@ -24,6 +24,7 @@ from urllib3.connection import VerifiedHTTPSConnection from urllib3.connectionpool import connection_from_url from urllib3.exceptions import ( ConnectTimeoutError, + InsecureRequestWarning, MaxRetryError, ProxyError, ProxySchemeUnknown, @@ -418,11 +419,13 @@ class TestHTTPProxyManager(HTTPDummyProxyTestCase): assert len(http.pools) == 1 for x in range(2): - http.urlopen("GET", self.https_url) + with pytest.warns(InsecureRequestWarning): + http.urlopen("GET", self.https_url) assert len(http.pools) == 2 for x in range(2): - http.urlopen("GET", self.https_url_alt) + with pytest.warns(InsecureRequestWarning): + http.urlopen("GET", self.https_url_alt) assert len(http.pools) == 3 def test_proxy_pooling_ext(self) -> None: diff --git a/test/with_dummyserver/test_socketlevel.py b/test/with_dummyserver/test_socketlevel.py index 809c6852..0f7e24c2 100644 --- a/test/with_dummyserver/test_socketlevel.py +++ b/test/with_dummyserver/test_socketlevel.py @@ -43,6 +43,7 @@ from urllib3._collections import HTTPHeaderDict from urllib3.connection import HTTPConnection, _get_default_user_agent from urllib3.connectionpool import _url_from_pool from urllib3.exceptions import ( + InsecureRequestWarning, MaxRetryError, ProtocolError, ProxyError, @@ -1246,7 +1247,8 @@ class TestProxyManager(SocketDummyServerTestCase): url = f"https://[{ipv6_addr}]" conn = proxy.connection_from_url(url) try: - r = conn.urlopen("GET", url, retries=0) + with pytest.warns(InsecureRequestWarning): + r = conn.urlopen("GET", url, retries=0) assert r.status == 200 except MaxRetryError: pytest.fail("Invalid IPv6 format in HTTP CONNECT request") |