master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24#
25import gzip
26import logging
27import os
28import re
29import shutil
30import string
31import subprocess
32import tempfile
33from configparser import ConfigParser, ExtendedInterpolation
34from datetime import timedelta
35from typing import Dict, List, Optional
37import pytest
38from filelock import FileLock
40from .certs import CertificateSpec, Credentials, TestCA
42log = logging.getLogger(__name__)
45class EnvError(Exception):
46 """Exception from the test environment."""
49def init_config_from(conf_path):
50 if os.path.isfile(conf_path):
51 config = ConfigParser(interpolation=ExtendedInterpolation())
52 config.read(conf_path)
53 return config
54 return None
57TESTS_HTTPD_PATH = os.path.dirname(os.path.dirname(__file__))
58PROJ_PATH = os.path.dirname(os.path.dirname(TESTS_HTTPD_PATH))
59TOP_PATH = os.path.join(os.getcwd(), os.path.pardir)
60CONFIG_PATH = os.path.join(TOP_PATH, "tests", "http", "config.ini")
61if not os.path.exists(CONFIG_PATH):
62 ALT_CONFIG_PATH = os.path.join(PROJ_PATH, "tests", "http", "config.ini")
63 if not os.path.exists(ALT_CONFIG_PATH):
64 raise EnvError(
65 f"unable to find config.ini in {CONFIG_PATH} nor {ALT_CONFIG_PATH}"
66 )
67 TOP_PATH = PROJ_PATH
68 CONFIG_PATH = ALT_CONFIG_PATH
69DEF_CONFIG = init_config_from(CONFIG_PATH)
70CURL = os.path.join(TOP_PATH, "src", "curl")
71CURLINFO = os.path.join(TOP_PATH, "src", "curlinfo")
74class NghttpxUtil:
75 CMD = None
76 VERSION_FULL = None
77 CAN_ECH = None
79 @classmethod
80 def version(cls, cmd):
81 if cmd is None:
82 return None
83 if cls.VERSION_FULL is None or cmd != cls.CMD:
84 p = subprocess.run(args=[cmd, "--version"], capture_output=True, text=True, check=True)
85 cls.CMD = cmd
86 for line in p.stdout.splitlines(keepends=False):
87 if line.startswith("nghttpx "):
88 cls.VERSION_FULL = line
89 if cls.VERSION_FULL is None:
90 raise RuntimeError(f"{cmd}: unable to determine version")
91 return cls.VERSION_FULL
93 @staticmethod
94 def version_with_h3(version):
95 return re.match(r".* ngtcp2/\d+\.\d+\.\d+.*", version) is not None
97 @classmethod
98 def can_ech(cls, cmd):
99 if cmd is None:
100 return None
101 if cls.CAN_ECH is None or cmd != cls.CMD:
102 p = subprocess.run(args=[cmd, "-h"], capture_output=True, text=True, check=True)
103 cls.CMD = cmd
104 cls.CAN_ECH = False
105 for line in p.stdout.splitlines(keepends=False):
106 if '--ech-config-file' in line:
107 cls.CAN_ECH = True
108 break
109 return cls.CAN_ECH
112class EnvConfig:
113 def __init__(
114 self,
115 pytestconfig: Optional[pytest.Config] = None,
116 testrun_uid=None,
117 worker_id=None,
118 ):
119 self.pytestconfig = pytestconfig
120 self.testrun_uid = testrun_uid
121 self.worker_id = worker_id if worker_id is not None else "master"
122 self.tests_dir = TESTS_HTTPD_PATH
123 self.gen_root = self.gen_dir = os.path.join(self.tests_dir, "gen")
124 if self.worker_id != "master":
125 self.gen_dir = os.path.join(self.gen_dir, self.worker_id)
126 self.project_dir = os.path.dirname(os.path.dirname(self.tests_dir))
127 self.build_dir = TOP_PATH
128 self.config = DEF_CONFIG
129 # check cur and its features
130 self.curl = CURL
131 self.curlinfo = CURLINFO
132 if "CURL" in os.environ:
133 self.curl = os.environ["CURL"]
134 self.curl_props = {
135 "version_string": "",
136 "version": "",
137 "os": "",
138 "fullname": "",
139 "features_string": "",
140 "features": set(),
141 "protocols_string": "",
142 "protocols": set(),
143 "libs": set(),
144 "lib_versions": set(),
145 }
146 self.curl_is_debug = False
147 self.curl_protos = []
148 p = subprocess.run(args=[self.curl, "-V"], capture_output=True, text=True, check=True)
149 if p.stderr.startswith("WARNING:"):
150 self.curl_is_debug = True
151 for line in p.stdout.splitlines(keepends=False):
152 if line.startswith("curl "):
153 self.curl_props["version_string"] = line
154 m = re.match(r"^curl (?P<version>\S+) (?P<os>\S+) (?P<libs>.*)$", line)
155 if m:
156 self.curl_props["fullname"] = m.group(0)
157 self.curl_props["version"] = m.group("version")
158 self.curl_props["os"] = m.group("os")
159 self.curl_props["lib_versions"] = {
160 lib.lower() for lib in m.group("libs").split(" ")
161 }
162 self.curl_props["libs"] = {
163 re.sub(r"/[a-z0-9.-]*", "", lib)
164 for lib in self.curl_props["lib_versions"]
165 }
166 if line.startswith("Features: "):
167 self.curl_props["features_string"] = line[10:]
168 self.curl_props["features"] = {
169 feat.lower() for feat in line[10:].split(" ")
170 }
171 if line.startswith("Protocols: "):
172 self.curl_props["protocols_string"] = line[11:]
173 self.curl_props["protocols"] = {
174 prot.lower() for prot in line[11:].split(" ")
175 }
177 p = subprocess.run(args=[self.curlinfo], capture_output=True, text=True, check=True)
178 self.curl_is_verbose = 'verbose-strings: ON' in p.stdout
179 self.curl_can_cert_status = 'cert-status: ON' in p.stdout
180 self.curl_override_dns = 'override-dns: ON' in p.stdout
181 self.curl_resolv_threaded = 'resolv-threaded: ON' in p.stdout
182 self.curl_can_doh = 'DoH: ON' in p.stdout
184 self.ports = {}
186 self.httpd = self.config["httpd"]["httpd"]
187 self.apxs = self.config["httpd"]["apxs"]
188 if len(self.apxs) == 0:
189 self.apxs = None
190 self._httpd_version = None
192 self.examples_pem = {
193 "key": "xxx",
194 "cert": "xxx",
195 }
196 self.htdocs_dir = os.path.join(self.gen_dir, "htdocs")
197 self.tld = "http.curl.se"
198 self.domain1 = f"one.{self.tld}"
199 self.domain1brotli = f"brotli.one.{self.tld}"
200 self.domain2 = f"two.{self.tld}"
201 self.ftp_domain = f"ftp.{self.tld}"
202 self.proxy_domain = f"proxy.{self.tld}"
203 self.expired_domain = f"expired.{self.tld}"
204 self.cert_specs = [
205 CertificateSpec(
206 domains=[self.domain1, self.domain1brotli, "localhost", "127.0.0.1"],
207 key_type="rsa2048",
208 ),
209 CertificateSpec(
210 name="domain1-no-ip",
211 domains=[self.domain1, self.domain1brotli],
212 key_type="rsa2048",
213 ),
214 CertificateSpec(
215 name="domain1-very-bad",
216 domains=[self.domain1, "dns:127.0.0.1"],
217 key_type="rsa2048",
218 ),
219 CertificateSpec(domains=[self.domain2], key_type="rsa2048"),
220 CertificateSpec(domains=[self.ftp_domain], key_type="rsa2048"),
221 CertificateSpec(
222 domains=[self.proxy_domain, "127.0.0.1"], key_type="rsa2048"
223 ),
224 CertificateSpec(
225 domains=[self.expired_domain],
226 key_type="rsa2048",
227 valid_from=timedelta(days=-100),
228 valid_to=timedelta(days=-10),
229 ),
230 CertificateSpec(
231 name="clientsX",
232 sub_specs=[
233 CertificateSpec(name="user1", client=True),
234 ],
235 ),
236 CertificateSpec(
237 name='embedded-zero',
238 domains=[f'{self.domain1}\0actually.{self.domain2}'],
239 key_type='rsa2048',
240 ),
241 CertificateSpec(
242 name='embedded-zero-wildcard',
243 domains=[f'*.{self.tld}\0actually.{self.domain2}'],
244 key_type='rsa2048',
245 ),
246 ]
248 if "OPENSSL" in os.environ:
249 self.openssl = os.environ["OPENSSL"]
250 else:
251 self.openssl = "openssl"
252 self.openssl_ech = False
253 p = subprocess.run(
254 args=[self.openssl, "version"], capture_output=True, text=True, check=False
255 )
256 if p.returncode != 0:
257 # no openssl in path
258 self.openssl = None
259 self.openssl_version = None
260 else:
261 self.openssl_version = p.stdout.strip()
262 m = re.match(r'OpenSSL (\d+).*', self.openssl_version)
263 if m and int(m.group(1)) >= 4:
264 self.openssl_ech = True
266 self.nghttpx = self.config["nghttpx"]["nghttpx"]
267 if len(self.nghttpx.strip()) == 0:
268 self.nghttpx = None
269 self.nghttpx_ech = False
270 self._nghttpx_version = None
271 self.nghttpx_with_h3 = False
272 if self.nghttpx is not None:
273 self._nghttpx_version = NghttpxUtil.version(self.nghttpx)
274 self.nghttpx_with_h3 = NghttpxUtil.version_with_h3(self._nghttpx_version)
275 self.nghttpx_ech = NghttpxUtil.can_ech(self.nghttpx)
277 self.caddy = self.config["caddy"]["caddy"]
278 self._caddy_version = None
279 if len(self.caddy.strip()) == 0:
280 self.caddy = None
282 self.h2o = self.config["h2o"]["h2o"]
283 if len(self.h2o.strip()) == 0:
284 self.h2o = None
285 self._h2o_version = None
286 if self.h2o is not None:
287 try:
288 p = subprocess.run(
289 args=[self.h2o, "--version"], capture_output=True, text=True, check=False
290 )
291 if p.returncode != 0:
292 # not a working h2o
293 self.h2o = None
294 else:
295 # h2o --version output format: "h2o version 2.3.0"
296 m = re.search(r"h2o version (\S+)", p.stdout)
297 if m:
298 self._h2o_version = m.group(1)
299 else:
300 self.h2o = None
301 except Exception:
302 log.exception("checking h2o version")
303 self.h2o = None
305 if self.caddy is not None:
306 p = subprocess.run(
307 args=[self.caddy, "version"], capture_output=True, text=True, check=False
308 )
309 if p.returncode != 0:
310 # not a working caddy
311 self.caddy = None
312 m = re.match(r"v?(\d+\.\d+\.\d+).*", p.stdout)
313 if m:
314 self._caddy_version = m.group(1)
315 else:
316 raise RuntimeError(
317 f"Unable to determine caddy version from: {p.stdout}"
318 )
320 self.vsftpd = self.config["vsftpd"]["vsftpd"]
321 if self.vsftpd == "":
322 self.vsftpd = None
323 self._vsftpd_version = None
324 if self.vsftpd is not None:
325 with tempfile.TemporaryFile("w+") as tmp:
326 p = subprocess.run(
327 args=[self.vsftpd, "-v"], capture_output=True, text=True, stdin=tmp, check=False
328 )
329 if p.returncode != 0:
330 # not a working vsftpd
331 self.vsftpd = None
332 if p.stderr:
333 ver_text = p.stderr
334 else:
335 # Oddly, some versions of vsftpd write to stdin (!)
336 # instead of stderr, which is odd but works. If there
337 # is nothing on stderr, read the file on stdin and use
338 # any data there instead.
339 tmp.seek(0)
340 ver_text = tmp.read()
341 m = re.match(r"vsftpd: version (\d+\.\d+\.\d+)", ver_text)
342 if m:
343 self._vsftpd_version = m.group(1)
344 elif len(p.stderr) == 0:
345 # vsftp does not use stdout or stderr for printing its version... -.-
346 self._vsftpd_version = "unknown"
347 else:
348 raise EnvError(f"Unable to determine VsFTPD version from: {p.stderr}")
350 self.danted = self.config["danted"]["danted"]
351 if self.danted == "":
352 self.danted = None
353 self._danted_version = None
354 if self.danted is not None:
355 p = subprocess.run(args=[self.danted, "-v"], capture_output=True, text=True, check=False)
356 assert p.returncode == 0
357 if p.returncode != 0:
358 # not a working vsftpd
359 self.danted = None
360 m = re.match(r"^Dante v(\d+\.\d+\.\d+).*", p.stdout)
361 if not m:
362 m = re.match(r"^Dante v(\d+\.\d+\.\d+).*", p.stderr)
363 if m:
364 self._danted_version = m.group(1)
365 else:
366 self.danted = None
367 raise EnvError(f"Unable to determine danted version from: {p.stderr}")
369 self.sshd = self.config["sshd"]["sshd"]
370 if self.sshd == "":
371 self.sshd = None
372 self._sshd_version = None
373 if self.sshd is not None:
374 p = subprocess.run(args=[self.sshd, "-V"], capture_output=True, text=True, check=False)
375 assert p.returncode == 0
376 if p.returncode != 0:
377 self.sshd = None
378 else:
379 m = re.match(r"^OpenSSH_(\d+\.\d+).*,.*", p.stderr)
380 assert m, f"version: {p.stderr}"
381 if m:
382 self._sshd_version = m.group(1)
383 else:
384 self.sshd = None
385 raise EnvError(
386 f"Unable to determine sshd version from: {p.stderr}"
387 )
389 if self.sshd:
390 self.sftpd = self.config["sshd"]["sftpd"]
391 if self.sftpd == "":
392 self.sftpd = None
393 else:
394 self.sftpd = None
396 self._tcpdump = shutil.which("tcpdump")
398 @property
399 def httpd_version(self):
400 if self._httpd_version is None and self.apxs is not None:
401 try:
402 p = subprocess.run(
403 args=[self.apxs, "-q", "HTTPD_VERSION"],
404 capture_output=True,
405 text=True,
406 check=False,
407 )
408 if p.returncode != 0:
409 log.error(f"{self.apxs} failed to query HTTPD_VERSION: {p}")
410 else:
411 self._httpd_version = p.stdout.strip()
412 except Exception:
413 log.exception(f"{self.apxs} failed to run")
414 return self._httpd_version
416 def versiontuple(self, v):
417 v = re.sub(r"(\d+\.\d+(\.\d+)?)(-\S+)?", r"\1", v)
418 return tuple(map(int, v.split(".")))
420 def httpd_is_at_least(self, minv):
421 if self.httpd_version is None:
422 return False
423 hv = self.versiontuple(self.httpd_version)
424 return hv >= self.versiontuple(minv)
426 def caddy_is_at_least(self, minv):
427 if self.caddy_version is None:
428 return False
429 hv = self.versiontuple(self.caddy_version)
430 return hv >= self.versiontuple(minv)
432 def is_complete(self) -> bool:
433 return (
434 os.path.isfile(self.httpd)
435 and self.apxs is not None
436 and os.path.isfile(self.apxs)
437 )
439 def get_incomplete_reason(self) -> Optional[str]:
440 if self.httpd is None or len(self.httpd.strip()) == 0:
441 return "httpd not configured, see `--with-test-httpd=<path>`"
442 if not os.path.isfile(self.httpd):
443 return f"httpd ({self.httpd}) not found"
444 if self.apxs is None:
445 return "command apxs not found (commonly provided in apache2-dev)"
446 if not os.path.isfile(self.apxs):
447 return f"apxs ({self.apxs}) not found"
448 return None
450 @property
451 def nghttpx_version(self):
452 return self._nghttpx_version
454 @property
455 def caddy_version(self):
456 return self._caddy_version
458 @property
459 def vsftpd_version(self):
460 return self._vsftpd_version
462 @property
463 def h2o_version(self):
464 return self._h2o_version
466 @property
467 def sshd_version(self):
468 return self._sshd_version
470 @property
471 def tcpdump(self) -> Optional[str]:
472 return self._tcpdump
474 def clear_locks(self):
475 ca_lock = os.path.join(self.gen_root, "ca/ca.lock")
476 if os.path.exists(ca_lock):
477 os.remove(ca_lock)
480class Env:
481 SERVER_TIMEOUT = 30 # seconds to wait for server to come up/reload
483 CONFIG = EnvConfig()
485 @classmethod
486 def setup_incomplete(cls) -> bool:
487 return not cls.CONFIG.is_complete()
489 @classmethod
490 def incomplete_reason(cls) -> Optional[str]:
491 return cls.CONFIG.get_incomplete_reason()
493 @classmethod
494 def have_openssl(cls) -> bool:
495 return cls.CONFIG.openssl is not None
497 @classmethod
498 def have_nghttpx(cls) -> bool:
499 return cls.CONFIG.nghttpx is not None
501 @classmethod
502 def have_h3_server(cls) -> bool:
503 return cls.CONFIG.nghttpx_with_h3
505 @staticmethod
506 def have_openssl_ech() -> bool:
507 return Env.CONFIG.openssl_ech
509 @staticmethod
510 def have_nghttpx_ech() -> bool:
511 return Env.CONFIG.nghttpx_ech
513 @classmethod
514 def have_h2o(cls) -> bool:
515 return cls.CONFIG.h2o is not None
517 @classmethod
518 def have_ssl_curl(cls) -> bool:
519 return cls.curl_has_feature("ssl") or cls.curl_has_feature("multissl")
521 @classmethod
522 def have_h2_curl(cls) -> bool:
523 return "http2" in cls.CONFIG.curl_props["features"]
525 @classmethod
526 def have_h3_curl(cls) -> bool:
527 return "http3" in cls.CONFIG.curl_props["features"]
529 @classmethod
530 def have_compressed_curl(cls) -> bool:
531 return (
532 "brotli" in cls.CONFIG.curl_props["libs"]
533 or "zlib" in cls.CONFIG.curl_props["libs"]
534 or "zstd" in cls.CONFIG.curl_props["libs"]
535 )
537 @classmethod
538 def curl_uses_lib(cls, libname: str) -> bool:
539 return libname.lower() in cls.CONFIG.curl_props["libs"]
541 @classmethod
542 def curl_uses_any_libs(cls, libs: List[str]) -> bool:
543 return any(libname.lower() in cls.CONFIG.curl_props["libs"] for libname in libs)
545 @classmethod
546 def curl_uses_ossl_quic(cls) -> bool:
547 if cls.have_h3_curl():
548 return not cls.curl_uses_lib("ngtcp2") and cls.curl_uses_lib("nghttp3")
549 return False
551 @classmethod
552 def curl_version_string(cls) -> str:
553 return cls.CONFIG.curl_props["version_string"]
555 @classmethod
556 def curl_version_at_least(cls, min_version) -> bool:
557 version = cls.curl_version()
558 return cls.CONFIG.versiontuple(min_version) <= cls.CONFIG.versiontuple(
559 version
560 )
562 @classmethod
563 def curl_features_string(cls) -> str:
564 return cls.CONFIG.curl_props["features_string"]
566 @classmethod
567 def curl_has_feature(cls, feature: str) -> bool:
568 return feature.lower() in cls.CONFIG.curl_props["features"]
570 @classmethod
571 def curl_protocols_string(cls) -> str:
572 return cls.CONFIG.curl_props["protocols_string"]
574 @classmethod
575 def curl_has_protocol(cls, protocol: str) -> bool:
576 return protocol.lower() in cls.CONFIG.curl_props["protocols"]
578 @classmethod
579 def curl_lib_version(cls, libname: str) -> str:
580 prefix = f"{libname.lower()}/"
581 for lversion in cls.CONFIG.curl_props["lib_versions"]:
582 if lversion.startswith(prefix):
583 return lversion[len(prefix):]
584 return "unknown"
586 @classmethod
587 def curl_lib_version_at_least(cls, libname: str, min_version) -> bool:
588 lversion = cls.curl_lib_version(libname)
589 if lversion != "unknown":
590 return cls.CONFIG.versiontuple(min_version) <= cls.CONFIG.versiontuple(
591 lversion
592 )
593 return False
595 @classmethod
596 def curl_lib_version_before(cls, libname: str, lib_version) -> bool:
597 lversion = cls.curl_lib_version(libname)
598 if lversion != "unknown":
599 if m := re.match(r"(\d+\.\d+\.\d+).*", lversion):
600 lversion = m.group(1)
601 return cls.CONFIG.versiontuple(lib_version) > cls.CONFIG.versiontuple(
602 lversion
603 )
604 return False
606 @classmethod
607 def curl_os(cls) -> str:
608 return cls.CONFIG.curl_props["os"]
610 @classmethod
611 def curl_fullname(cls) -> str:
612 return cls.CONFIG.curl_props["fullname"]
614 @classmethod
615 def curl_version(cls) -> str:
616 return cls.CONFIG.curl_props["version"]
618 @classmethod
619 def curl_is_debug(cls) -> bool:
620 return cls.CONFIG.curl_is_debug
622 @classmethod
623 def curl_is_verbose(cls) -> bool:
624 return cls.CONFIG.curl_is_verbose
626 @classmethod
627 def curl_can_cert_status(cls) -> bool:
628 return cls.CONFIG.curl_can_cert_status
630 @classmethod
631 def curl_override_dns(cls) -> bool:
632 return cls.CONFIG.curl_override_dns
634 @classmethod
635 def curl_resolv_threaded(cls) -> bool:
636 return cls.CONFIG.curl_resolv_threaded
638 @classmethod
639 def curl_can_doh(cls) -> bool:
640 return cls.CONFIG.curl_can_doh
642 @classmethod
643 def curl_can_early_data(cls) -> bool:
644 if cls.curl_uses_lib('gnutls'):
645 return cls.curl_lib_version_at_least('gnutls', '3.7.2')
646 return cls.curl_uses_any_libs(['wolfssl', 'quictls', 'openssl'])
648 @classmethod
649 def curl_can_h3_early_data(cls) -> bool:
650 return cls.curl_can_early_data() and cls.curl_uses_lib("ngtcp2")
652 @classmethod
653 def http_protos(cls) -> List[str]:
654 # http protocols we can test
655 if cls.have_h2_curl():
656 if cls.have_h3():
657 return ["http/1.1", "h2", "h3"]
658 return ["http/1.1", "h2"]
659 return ["http/1.1"]
661 @classmethod
662 def http_h1_h2_protos(cls) -> List[str]:
663 # http 1+2 protocols we can test
664 if cls.have_h2_curl():
665 return ["http/1.1", "h2"]
666 return ["http/1.1"]
668 @classmethod
669 def http_mplx_protos(cls) -> List[str]:
670 # http multiplexing protocols we can test
671 if cls.have_h2_curl():
672 if cls.have_h3():
673 return ["h2", "h3"]
674 return ["h2"]
675 return []
677 @classmethod
678 def have_h3(cls) -> bool:
679 return cls.have_h3_curl() and cls.have_h3_server()
681 @classmethod
682 def httpd_version(cls) -> str:
683 return cls.CONFIG.httpd_version
685 @classmethod
686 def nghttpx_version(cls) -> str:
687 return cls.CONFIG.nghttpx_version
689 @classmethod
690 def caddy_version(cls) -> str:
691 return cls.CONFIG.caddy_version
693 @classmethod
694 def h2o_version(cls) -> str:
695 return cls.CONFIG.h2o_version
697 @classmethod
698 def sshd_version(cls) -> str:
699 return cls.CONFIG.sshd_version
701 @classmethod
702 def caddy_is_at_least(cls, minv) -> bool:
703 return cls.CONFIG.caddy_is_at_least(minv)
705 @classmethod
706 def httpd_is_at_least(cls, minv) -> bool:
707 return cls.CONFIG.httpd_is_at_least(minv)
709 @classmethod
710 def has_caddy(cls) -> bool:
711 return cls.CONFIG.caddy is not None
713 @classmethod
714 def has_vsftpd(cls) -> bool:
715 return cls.CONFIG.vsftpd is not None
717 @classmethod
718 def vsftpd_version(cls) -> str:
719 return cls.CONFIG.vsftpd_version
721 @classmethod
722 def has_danted(cls) -> bool:
723 return cls.CONFIG.danted is not None
725 @classmethod
726 def has_sshd(cls) -> bool:
727 return cls.CONFIG.sshd is not None
729 @classmethod
730 def has_sftpd(cls) -> bool:
731 return cls.has_sshd() and cls.CONFIG.sftpd is not None
733 @classmethod
734 def tcpdump(cls) -> Optional[str]:
735 return cls.CONFIG.tcpdump
737 def __init__(self, pytestconfig=None, env_config=None):
738 if env_config:
739 Env.CONFIG = env_config
740 self._verbose = pytestconfig.option.verbose if pytestconfig is not None else 0
741 self._ca = None
742 self._test_timeout = 300.0 if self._verbose > 1 else 60.0 # seconds
744 def issue_certs(self):
745 if self._ca is None:
746 # ca_dir = os.path.join(self.CONFIG.gen_root, 'ca')
747 ca_dir = os.path.join(self.gen_dir, "ca")
748 os.makedirs(ca_dir, exist_ok=True)
749 lock_file = os.path.join(ca_dir, "ca.lock")
750 with FileLock(lock_file):
751 self._ca = TestCA.create_root(
752 name=self.CONFIG.tld, store_dir=ca_dir, key_type="rsa2048"
753 )
754 self._ca.issue_certs(self.CONFIG.cert_specs)
755 if self.have_openssl():
756 self._ca.create_hashdir(self.openssl)
757 if self.have_openssl_ech():
758 for domain in [self.domain1, self.domain2]:
759 p = subprocess.run(args=[
760 self.openssl, 'ech',
761 '-out', os.path.join(ca_dir, f'{domain}.echconfig'),
762 '-public_name', f'public.{domain}'
763 ], capture_output=True, text=True, check=True)
764 if p.returncode != 0:
765 raise EnvError(f"Error generating ECHConfig for {domain}")
767 def setup(self):
768 os.makedirs(self.gen_dir, exist_ok=True)
769 os.makedirs(self.htdocs_dir, exist_ok=True)
770 self.issue_certs()
772 def get_credentials(self, domain) -> Optional[Credentials]:
773 creds = self.ca.get_credentials_for_name(domain)
774 if len(creds) > 0:
775 return creds[0]
776 return None
778 def get_echconfig_file(self, domain) -> Optional[str]:
779 ech_file = os.path.join(self.gen_dir, f"ca/{domain}.echconfig")
780 if os.path.exists(ech_file):
781 return ech_file
782 return None
784 def get_echconfig_arg(self, domain) -> Optional[str]:
785 ech_file = self.get_echconfig_file(domain)
786 if ech_file:
787 ech_config = ''
788 in_pem = False
789 with open(ech_file) as fd:
790 for line in fd.read().splitlines():
791 if not in_pem and line == '-----BEGIN ECHCONFIG-----':
792 in_pem = True
793 elif in_pem and line == '-----END ECHCONFIG-----':
794 break
795 elif in_pem:
796 ech_config += line
797 return ech_config
798 return None
800 @property
801 def verbose(self) -> int:
802 return self._verbose
804 @property
805 def test_timeout(self) -> Optional[float]:
806 return self._test_timeout
808 @test_timeout.setter
809 def test_timeout(self, val: Optional[float]):
810 self._test_timeout = val
812 @property
813 def gen_dir(self) -> str:
814 return self.CONFIG.gen_dir
816 @property
817 def gen_root(self) -> str:
818 return self.CONFIG.gen_root
820 @property
821 def project_dir(self) -> str:
822 return self.CONFIG.project_dir
824 @property
825 def build_dir(self) -> str:
826 return self.CONFIG.build_dir
828 @property
829 def ca(self):
830 return self._ca
832 @property
833 def htdocs_dir(self) -> str:
834 return self.CONFIG.htdocs_dir
836 @property
837 def tld(self) -> str:
838 return self.CONFIG.tld
840 @property
841 def domain1(self) -> str:
842 return self.CONFIG.domain1
844 @property
845 def domain1brotli(self) -> str:
846 return self.CONFIG.domain1brotli
848 @property
849 def domain2(self) -> str:
850 return self.CONFIG.domain2
852 @property
853 def ftp_domain(self) -> str:
854 return self.CONFIG.ftp_domain
856 @property
857 def proxy_domain(self) -> str:
858 return self.CONFIG.proxy_domain
860 @property
861 def expired_domain(self) -> str:
862 return self.CONFIG.expired_domain
864 @property
865 def ports(self) -> Dict[str, int]:
866 return self.CONFIG.ports
868 def update_ports(self, ports: Dict[str, int]):
869 self.CONFIG.ports.update(ports)
871 @property
872 def http_port(self) -> int:
873 return self.CONFIG.ports.get("http", 0)
875 @property
876 def https_port(self) -> int:
877 return self.CONFIG.ports["https"]
879 @property
880 def https_only_tcp_port(self) -> int:
881 return self.CONFIG.ports["https-tcp-only"]
883 @property
884 def nghttpx_https_port(self) -> int:
885 return self.CONFIG.ports["nghttpx_https"]
887 @property
888 def h3_port(self) -> int:
889 return self.https_port
891 @property
892 def proxy_port(self) -> int:
893 return self.CONFIG.ports["proxy"]
895 @property
896 def proxys_port(self) -> int:
897 return self.CONFIG.ports["proxys"]
899 @property
900 def ftp_port(self) -> int:
901 return self.CONFIG.ports["ftp"]
903 @property
904 def ftps_port(self) -> int:
905 return self.CONFIG.ports["ftps"]
907 @property
908 def h2proxys_port(self) -> int:
909 return self.CONFIG.ports["h2proxys"]
911 @property
912 def h3proxys_port(self) -> int:
913 return self.CONFIG.ports["h2o_h3proxys"]
915 def pts_port(self, proto: str = "http/1.1", use_h2o: bool = False) -> int:
916 # proxy tunnel port
917 prefix = 'h2o_' if use_h2o else ''
918 if proto == "h3":
919 return self.CONFIG.ports.get("h2o_h3proxys", 0)
920 if proto == "h2":
921 return self.CONFIG.ports.get(f"{prefix}h2proxys", 0)
922 return self.CONFIG.ports[f"{prefix}proxys"]
924 @property
925 def caddy(self) -> str:
926 return self.CONFIG.caddy
928 @property
929 def caddy_https_port(self) -> int:
930 return self.CONFIG.ports["caddys"]
932 @property
933 def caddy_http_port(self) -> int:
934 return self.CONFIG.ports["caddy"]
936 @property
937 def danted(self) -> str:
938 return self.CONFIG.danted
940 @property
941 def vsftpd(self) -> str:
942 return self.CONFIG.vsftpd
944 @property
945 def curl(self) -> str:
946 return self.CONFIG.curl
948 @property
949 def openssl(self) -> Optional[str]:
950 return self.CONFIG.openssl
952 @property
953 def httpd(self) -> str:
954 return self.CONFIG.httpd
956 @property
957 def apxs(self) -> str:
958 return self.CONFIG.apxs
960 @property
961 def nghttpx(self) -> Optional[str]:
962 return self.CONFIG.nghttpx
964 @property
965 def slow_network(self) -> bool:
966 return (
967 "CURL_DBG_SOCK_WBLOCK" in os.environ
968 or "CURL_DBG_SOCK_WPARTIAL" in os.environ
969 )
971 @property
972 def ci_run(self) -> bool:
973 return "CURL_CI" in os.environ
975 def port_for(self, alpn_proto: Optional[str] = None):
976 if alpn_proto is None or alpn_proto in [
977 "h2",
978 "http/1.1",
979 "http/1.0",
980 "http/0.9",
981 ]:
982 return self.https_port
983 if alpn_proto == "h3":
984 return self.h3_port
985 return self.http_port
987 def authority_for(self, domain: str, alpn_proto: Optional[str] = None):
988 return f"{domain}:{self.port_for(alpn_proto=alpn_proto)}"
990 def make_data_file(
991 self, indir: str, fname: str, fsize: int, line_length: int = 1024
992 ) -> str:
993 if line_length < 11:
994 raise RuntimeError("line_length less than 11 not supported")
995 os.makedirs(indir, exist_ok=True)
996 fpath = os.path.join(indir, fname)
997 s10 = string.digits
998 s = round((line_length / 10) + 1) * s10
999 s = s[0:line_length - 11]
1000 with open(fpath, "w") as fd:
1001 fd.writelines(f"{i:09d}-{s}\n" for i in range(int(fsize / line_length)))
1002 remain = int(fsize % line_length)
1003 if remain != 0:
1004 i = int(fsize / line_length) + 1
1005 fd.write(f"{i:09d}-{s}"[0:remain - 1] + "\n")
1006 return fpath
1008 def make_data_gzipbomb(self, indir: str, fname: str, fsize: int) -> str:
1009 fpath = os.path.join(indir, fname)
1010 gzpath = f"{fpath}.gz"
1011 varpath = f"{fpath}.var"
1013 with open(fpath, "w") as fd:
1014 fd.write("not what we are looking for!\n")
1015 count = int(fsize / 1024)
1016 zero1k = bytearray(1024)
1017 with gzip.open(gzpath, "wb") as fd:
1018 for _ in range(count):
1019 fd.write(zero1k)
1020 with open(varpath, "w") as fd:
1021 fd.write(f"URI: {fname}\n")
1022 fd.write("\n")
1023 fd.write(f"URI: {fname}.gz\n")
1024 fd.write("Content-Type: text/plain\n")
1025 fd.write("Content-Encoding: x-gzip\n")
1026 fd.write("\n")
1027 return fpath
Diagnostics4 git calls · 33 ms
CallStatusSizeTime033 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2007.7 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=26 git.response.bytes=7880 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=2f21dbdde8504b07e6d9e371df29332330326592 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=7880 git.pkt.payload.max=7859 git.sideband.band1.bytes=7858 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2c36fbc1aaedd
- Request
- 5a593d45…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format