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
+7 -7
View File
@@ -318,7 +318,7 @@ class TestClient(testtools.TestCase):
def test_http_chunked_request(self):
text = "Ok"
data = io.StringIO(text)
data = io.BytesIO(text.encode())
path = '/v1/images/'
self.mock.post(self.endpoint + path, text=text)
@@ -341,9 +341,9 @@ class TestClient(testtools.TestCase):
self.assertEqual(data, json.loads(self.mock.last_request.body))
def test_http_chunked_response(self):
data = "TEST"
data = b"TEST"
path = '/v1/images/'
self.mock.get(self.endpoint + path, body=io.StringIO(data),
self.mock.get(self.endpoint + path, body=io.BytesIO(data),
headers={"Content-Type": "application/octet-stream"})
resp, body = self.client.get(path)
@@ -353,10 +353,10 @@ class TestClient(testtools.TestCase):
@original_only
def test_log_http_response_with_non_ascii_char(self):
try:
response = 'Ok'
response = b'Ok'
headers = {"Content-Type": "text/plain",
"test": "value1\xa5\xa6"}
fake = utils.FakeResponse(headers, io.StringIO(response))
fake = utils.FakeResponse(headers, io.BytesIO(response))
self.client.log_http_response(fake)
except UnicodeDecodeError as e:
self.fail("Unexpected UnicodeDecodeError exception '%s'" % e)
@@ -457,9 +457,9 @@ class TestClient(testtools.TestCase):
def test_log_request_id_once(self):
logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
data = "TEST"
data = b"TEST"
path = '/v1/images/'
self.mock.get(self.endpoint + path, body=io.StringIO(data),
self.mock.get(self.endpoint + path, body=io.BytesIO(data),
headers={"Content-Type": "application/octet-stream",
'x-openstack-request-id': "1234"})