]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
pytest: fix run against multissl curl
authorStefan Eissing <stefan@eissing.org>
Tue, 29 Oct 2024 09:07:34 +0000 (10:07 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Oct 2024 10:13:56 +0000 (11:13 +0100)
Changes to make a curl built with OpenSSL + GnuTLS to run successfully
in our pytests. Run

CURL_SSL_BACKEND=openssl pytest

to test a TLS backend other than the default.

Closes #15443

tests/http/conftest.py
tests/http/test_02_download.py
tests/http/testenv/env.py
tests/http/testenv/nghttpx.py

index d3f655263d3b345fce0b323ba5002c9375de4e9c..563a8c92d984973779a343b8c1ae43cb6645a630 100644 (file)
@@ -102,7 +102,7 @@ def httpd(env) -> Generator[Httpd, None, None]:
 @pytest.fixture(scope='package')
 def nghttpx(env, httpd) -> Generator[Nghttpx, None, None]:
     nghttpx = NghttpxQuic(env=env)
-    if env.have_h3():
+    if nghttpx.exists() and (env.have_h3() or nghttpx.https_port > 0):
         nghttpx.clear_logs()
         assert nghttpx.start()
     yield nghttpx
@@ -111,7 +111,7 @@ def nghttpx(env, httpd) -> Generator[Nghttpx, None, None]:
 @pytest.fixture(scope='package')
 def nghttpx_fwd(env, httpd) -> Generator[Nghttpx, None, None]:
     nghttpx = NghttpxFwd(env=env)
-    if env.have_h3():
+    if nghttpx.exists() and (env.have_h3() or nghttpx.https_port > 0):
         nghttpx.clear_logs()
         assert nghttpx.start()
     yield nghttpx
index 5bcbb8c43903d8cafee50f502af925ded12672e2..fe92df5041a629e987b9368aeabb16b16eaa3b42 100644 (file)
@@ -572,7 +572,7 @@ class TestDownload:
         assert r.total_connects == 1, r.dump_logs()
 
     # download parallel with h2 "Upgrade:"
-    def test_02_31_parallel_upgrade(self, env: Env, httpd):
+    def test_02_31_parallel_upgrade(self, env: Env, httpd, nghttpx):
         count = 3
         curl = CurlClient(env=env)
         urln = f'http://{env.domain1}:{env.http_port}/data.json?[0-{count-1}]'
@@ -599,7 +599,6 @@ class TestDownload:
         port = env.port_for(proto)
         if proto != 'h3':
             port = env.nghttpx_https_port
-        # url = f'https://{env.domain1}:{env.port_for(proto)}/{docname}'
         url = f'https://{env.domain1}:{port}/{docname}'
         client = LocalClient(name='hx-download', env=env)
         if not client.exists():
index 5d6ec176fac7a4b21a2c968df5240adfae310156..988b90a2f1256f59473c5ac25157bac3d6b8907e 100644 (file)
@@ -95,7 +95,7 @@ class EnvConfig:
                         lib.lower() for lib in m.group('libs').split(' ')
                     ]
                     self.curl_props['libs'] = [
-                        re.sub(r'/.*', '', lib) for lib in self.curl_props['lib_versions']
+                        re.sub(r'/[a-z0-9.-]*', '', lib) for lib in self.curl_props['lib_versions']
                     ]
             if line.startswith('Features: '):
                 self.curl_props['features'] = [
@@ -303,7 +303,7 @@ class Env:
 
     @staticmethod
     def have_ssl_curl() -> bool:
-        return 'ssl' in Env.CONFIG.curl_props['features']
+        return Env.curl_has_feature('ssl') or Env.curl_has_feature('multissl')
 
     @staticmethod
     def have_h2_curl() -> bool:
index bb07fef69003348215c6532b16fac48fca526529..801d9a63ad0bb160d3c3028ee7d0e0606cf88dd4 100644 (file)
@@ -41,10 +41,11 @@ log = logging.getLogger(__name__)
 
 class Nghttpx:
 
-    def __init__(self, env: Env, port: int, name: str):
+    def __init__(self, env: Env, port: int, https_port: int, name: str):
         self.env = env
         self._name = name
         self._port = port
+        self._https_port = https_port
         self._cmd = env.nghttpx
         self._run_dir = os.path.join(env.gen_dir, name)
         self._pid_file = os.path.join(self._run_dir, 'nghttpx.pid')
@@ -58,8 +59,12 @@ class Nghttpx:
         self._mkpath(self._run_dir)
         self._write_config()
 
+    @property
+    def https_port(self):
+        return self._https_port
+
     def exists(self):
-        return os.path.exists(self._cmd)
+        return self._cmd and os.path.exists(self._cmd)
 
     def clear_logs(self):
         self._rmf(self._error_log)
@@ -127,10 +132,18 @@ class Nghttpx:
         curl = CurlClient(env=self.env, run_dir=self._tmp_dir)
         try_until = datetime.now() + timeout
         while datetime.now() < try_until:
-            check_url = f'https://{self.env.domain1}:{self._port}/'
-            r = curl.http_get(url=check_url, extra_args=[
-                '--http3-only', '--connect-timeout', '1'
-            ])
+            if self._https_port > 0:
+                check_url = f'https://{self.env.domain1}:{self._https_port}/'
+                r = curl.http_get(url=check_url, extra_args=[
+                    '--trace', 'curl.trace', '--trace-time',
+                    '--connect-timeout', '1'
+                ])
+            else:
+                check_url = f'https://{self.env.domain1}:{self._port}/'
+                r = curl.http_get(url=check_url, extra_args=[
+                    '--trace', 'curl.trace', '--trace-time',
+                    '--http3-only', '--connect-timeout', '1'
+                ])
             if r.exit_code != 0:
                 return True
             log.debug(f'waiting for nghttpx to stop responding: {r}')
@@ -142,11 +155,18 @@ class Nghttpx:
         curl = CurlClient(env=self.env, run_dir=self._tmp_dir)
         try_until = datetime.now() + timeout
         while datetime.now() < try_until:
-            check_url = f'https://{self.env.domain1}:{self._port}/'
-            r = curl.http_get(url=check_url, extra_args=[
-                '--http3-only', '--trace', 'curl.trace', '--trace-time',
-                '--connect-timeout', '1'
-            ])
+            if self._https_port > 0:
+                check_url = f'https://{self.env.domain1}:{self._https_port}/'
+                r = curl.http_get(url=check_url, extra_args=[
+                    '--trace', 'curl.trace', '--trace-time',
+                    '--connect-timeout', '1'
+                ])
+            else:
+                check_url = f'https://{self.env.domain1}:{self._port}/'
+                r = curl.http_get(url=check_url, extra_args=[
+                    '--http3-only', '--trace', 'curl.trace', '--trace-time',
+                    '--connect-timeout', '1'
+                ])
             if r.exit_code == 0:
                 return True
             log.debug(f'waiting for nghttpx to become responsive: {r}')
@@ -173,7 +193,8 @@ class Nghttpx:
 class NghttpxQuic(Nghttpx):
 
     def __init__(self, env: Env):
-        super().__init__(env=env, name='nghttpx-quic', port=env.h3_port)
+        super().__init__(env=env, name='nghttpx-quic', port=env.h3_port,
+                         https_port=env.nghttpx_https_port)
 
     def start(self, wait_live=True):
         self._mkpath(self._tmp_dir)
@@ -210,7 +231,8 @@ class NghttpxQuic(Nghttpx):
 class NghttpxFwd(Nghttpx):
 
     def __init__(self, env: Env):
-        super().__init__(env=env, name='nghttpx-fwd', port=env.h2proxys_port)
+        super().__init__(env=env, name='nghttpx-fwd', port=env.h2proxys_port,
+                         https_port=0)
 
     def start(self, wait_live=True):
         self._mkpath(self._tmp_dir)