Fix unit tests with urllib3 2.x

urllib3 was recently bumped to 2.x[1] in global upper constraints.
Adopt the unit tests to fix a few new errors.

The key points are
 - It now strictly requires byte response
 - It ignores CN to verify SSL certificates and we should add SAN

Also leave the script to generate test certificates and keys so that
we can adjust these in the future more easily.

[1] https://review.opendev.org/c/openstack/requirements/+/972462

Change-Id: I4ed7182ad38593554b0ac7cbdb63af85d984371d
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
(cherry picked from commit e02b6b449ca0a93197608d3adfabf4e3e646a762)
This commit is contained in:
Takashi Kajinami
2026-03-09 00:48:53 +09:00
parent b9e5198f0d
commit d53dd3e075
9 changed files with 226 additions and 278 deletions
+9 -9
View File
@@ -77,7 +77,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v1_requests_cert_verification(self, __):
"""v1 regression test for bug 115260."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
try:
client = v1.Client(url,
@@ -94,7 +94,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
"""v1 regression test for bug 115260."""
# Legacy test. Verify 'no compression' has no effect
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
try:
client = v1.Client(url,
@@ -110,7 +110,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_cert_verification(self, __):
"""v2 regression test for bug 115260."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
try:
gc = v2.Client(url,
@@ -127,7 +127,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
"""v2 regression test for bug 115260."""
# Legacy test. Verify 'no compression' has no effect
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
try:
gc = v2.Client(url,
@@ -143,7 +143,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_valid_cert_verification(self, __):
"""Test absence of SSL key file."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
try:
@@ -160,7 +160,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_valid_cert_verification_no_compression(self, __):
"""Test VerifiedHTTPSConnection: absence of SSL key file."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
try:
@@ -177,7 +177,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_valid_cert_no_key(self, __):
"""Test VerifiedHTTPSConnection: absence of SSL key file."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
@@ -196,7 +196,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_bad_cert(self, __):
"""Test VerifiedHTTPSConnection: absence of SSL key file."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
cert_file = os.path.join(TEST_VAR_DIR, 'badcert.crt')
cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
@@ -219,7 +219,7 @@ class TestHTTPSVerifyCert(testtools.TestCase):
def test_v2_requests_bad_ca(self, __):
"""Test VerifiedHTTPSConnection: absence of SSL key file."""
port = self.port
url = 'https://0.0.0.0:%d' % port
url = 'https://127.0.0.1:%d' % port
cacert = os.path.join(TEST_VAR_DIR, 'badca.crt')
try: