From f8804ad015eaba07e905941052c4412f9b42cbd9 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <slev@altlinux.org>
Date: May 26 2023 15:01:37 +0000
Subject: [PATCH 1/3] tests: Replace removed urllib3's get_host with parse_url


`get_host` was deprecated since `urllib 1.5`:
https://github.com/urllib3/urllib3/commit/0c973cada5888e65fb2a26693e08de67038f00e5

and has been removed in `urllib3` 2.0:
https://github.com/urllib3/urllib3/pull/2139

Fixes:
ERROR: Failure: ImportError (cannot import name 'get_host' from 'urllib3.util' (/usr/l
ib/python3/site-packages/urllib3/util/__init__.py))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3/site-packages/nose/loader.py", line 418, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/usr/lib/python3/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python3/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib64/python3.10/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib64/python3.10/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 719, in _load
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test.py", line 1, in <module>
    from test_config import Declarative, write_template_file, restart_apache
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 27, in <module>
    import test_request
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_request.py", line 8, in <module>
    from requests.packages.urllib3.util import get_host
ImportError: cannot import name 'get_host' from 'urllib3.util' (/usr/lib/python3/site-packages/urllib3/util/__init__.py)

Related: https://pagure.io/mod_nss/issue/56
Signed-off-by: Stanislav Levin <slev@altlinux.org>

---

diff --git a/test/test_request.py b/test/test_request.py
index fdedd48..5d45327 100644
--- a/test/test_request.py
+++ b/test/test_request.py
@@ -5,7 +5,7 @@ import requests
 import logging
 import socket
 import ssl
-from requests.packages.urllib3.util import get_host
+from requests.packages.urllib3.util import parse_url
 from requests.packages.urllib3.util.timeout import Timeout
 from requests.packages.urllib3.connectionpool import (
     HTTPConnectionPool, HTTPSConnectionPool, VerifiedHTTPSConnection)
@@ -60,7 +60,8 @@ def connection_from_url(url, **kw):
         >>> conn = connection_from_url('http://google.com/')
         >>> r = conn.request('GET', '/')
     """
-    scheme, host, port = get_host(url)
+    p = parse_url(url)
+    scheme, host, port = p.scheme or "http", p.hostname, p.port
     if scheme == 'https':
         return MyHTTPSConnectionPool(host, port=port, **kw)
     else:

From 1f1be33c67c819808cb30a9fb6a555c2bcf4c8f4 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <slev@altlinux.org>
Date: May 26 2023 15:01:44 +0000
Subject: [PATCH 2/3] tests: Fix import of urllib's VerifiedHTTPSConnection


`VerifiedHTTPSConnection` has been removed from `urllib3.connectionpool`
in `urllib3` 2.0:
https://github.com/urllib3/urllib3/pull/2768

Fixes:
ERROR: Failure: ImportError (cannot import name 'VerifiedHTTPSConnection' from 'urllib3.connectionpool' (/usr/lib/python3/site-packages/urllib3/connectionpool.py))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3/site-packages/nose/loader.py", line 418, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/usr/lib/python3/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python3/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib64/python3.10/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib64/python3.10/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 719, in _load
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test.py", line 1, in <module>
    from test_config import Declarative, write_template_file, restart_apache
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 27, in <module>
    import test_request
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_request.py", line 11, in <module>
    from requests.packages.urllib3.connectionpool import (
ImportError: cannot import name 'VerifiedHTTPSConnection' from 'urllib3.connectionpool' (/usr/lib/python3/site-packages/urllib3/connectionpool.py)

Related: https://pagure.io/mod_nss/issue/56
Signed-off-by: Stanislav Levin <slev@altlinux.org>

---

diff --git a/test/test_request.py b/test/test_request.py
index 5d45327..c9676c1 100644
--- a/test/test_request.py
+++ b/test/test_request.py
@@ -8,7 +8,10 @@ import ssl
 from requests.packages.urllib3.util import parse_url
 from requests.packages.urllib3.util.timeout import Timeout
 from requests.packages.urllib3.connectionpool import (
-    HTTPConnectionPool, HTTPSConnectionPool, VerifiedHTTPSConnection)
+    HTTPConnectionPool,
+    HTTPSConnectionPool,
+)
+from requests.packages.urllib3.connection import VerifiedHTTPSConnection
 
 try:
     from requests.packages.urllib3.contrib.pyopenssl import (

From 409863932e6792ec39253a736560d037155bff17 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <slev@altlinux.org>
Date: May 26 2023 15:01:44 +0000
Subject: [PATCH 3/3] tests: Drop no longer existent strict param of HTTPConnectionPool


`strict` param of HTTPConnectionPool has been removed in `urllib3` 2.0:
https://github.com/urllib3/urllib3/pull/2064

Fixes:
ERROR: test_suite1[0]: /: Basic SSL connection
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 138, in <lambda>
    func = lambda: self.check(nice, **test)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 162, in check
    self.check_result(nice, uri, options, expected, cipher, protocol,
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 191, in check_result
    request = self.make_request(uri, options)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_config.py", line 148, in make_request
    request = session.get('https://%s:%d%s' % (host, port, uri),
  File "/usr/lib/python3/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/usr/lib/python3/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/site-packages/requests/adapters.py", line 454, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_request.py", line 200, in get_connection
    return connection_from_url(url)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_request.py", line 83, in connection_from_url
    return MyHTTPSConnectionPool(host, port=port, **kw)
  File "/usr/src/RPM/BUILD/apache2-mod_nss-1.0.18/test/test_request.py", line 98, in __init__
    super(HTTPSConnectionPool, self).__init__(host, port,
  File "/usr/lib/python3/site-packages/urllib3/connectionpool.py", line 196, in __init__
    timeout = Timeout.from_float(timeout)
  File "/usr/lib/python3/site-packages/urllib3/util/timeout.py", line 190, in from_float
    return Timeout(read=timeout, connect=timeout)
  File "/usr/lib/python3/site-packages/urllib3/util/timeout.py", line 119, in __init__
    self._connect = self._validate_timeout(connect, "connect")
  File "/usr/lib/python3/site-packages/urllib3/util/timeout.py", line 149, in _validate_timeout
    raise ValueError(
ValueError: Timeout cannot be a boolean value. It must be an int, float or None.

Related: https://pagure.io/mod_nss/issue/56
Signed-off-by: Stanislav Levin <slev@altlinux.org>

---

diff --git a/test/test_request.py b/test/test_request.py
index c9676c1..80f5697 100644
--- a/test/test_request.py
+++ b/test/test_request.py
@@ -73,7 +73,7 @@ def connection_from_url(url, **kw):
 
 class MyHTTPSConnectionPool(HTTPSConnectionPool):
     def __init__(self, host, port=None,
-                 strict=False, timeout=Timeout.DEFAULT_TIMEOUT, maxsize=1,
+                 timeout=Timeout.DEFAULT_TIMEOUT, maxsize=1,
                  block=False, headers=None,
                  key_file=None, cert_file=None,
                  cert_reqs='CERT_REQUIRED',
@@ -81,9 +81,14 @@ class MyHTTPSConnectionPool(HTTPSConnectionPool):
                  ssl_version=ssl.PROTOCOL_SSLv23,
                  ciphers=None):
 
-        super(HTTPSConnectionPool, self).__init__(host, port,
-                                                  strict, timeout, maxsize,
-                                                  block, headers)
+        super(HTTPSConnectionPool, self).__init__(
+            host=host,
+            port=port,
+            timeout=timeout,
+            maxsize=maxsize,
+            block=block,
+            headers=headers,
+        )
         self.key_file = key_file
         self.cert_file = cert_file
         self.cert_reqs = cert_reqs

