You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ic...@apache.org on 2021/08/20 16:07:45 UTC
svn commit: r1892476 [3/12] - in /httpd/httpd/trunk: ./ test/ test/modules/
test/modules/http2/ test/modules/http2/conf/ test/modules/http2/data/
test/modules/http2/htdocs/ test/modules/http2/htdocs/cgi/
test/modules/http2/htdocs/cgi/files/ test/module...
Added: httpd/httpd/trunk/test/modules/http2/data/nghttp-output-10k-1.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/data/nghttp-output-10k-1.txt?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/data/nghttp-output-10k-1.txt (added)
+++ httpd/httpd/trunk/test/modules/http2/data/nghttp-output-10k-1.txt Fri Aug 20 16:07:44 2021
@@ -0,0 +1,166 @@
+stderr: [WARNING] Certificate verification failed: unable to verify the first certificate
+
+stdout: [ 0.002] Connected
+The negotiated protocol: h2
+[ 0.004] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
+ (niv=2)
+ [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
+ [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
+ (dep_stream_id=0, weight=201, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
+ (dep_stream_id=0, weight=101, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
+ (dep_stream_id=0, weight=1, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
+ (dep_stream_id=7, weight=1, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
+ (dep_stream_id=3, weight=1, exclusive=0)
+[ 0.004] send HEADERS frame <length=78, flags=0x24, stream_id=13>
+ ; END_HEADERS | PRIORITY
+ (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
+ ; Open new stream
+ :method: POST
+ :path: //echo.py
+ :scheme: https
+ :authority: 127.0.0.1:42002
+ accept: */*
+ accept-encoding: gzip, deflate
+ user-agent: nghttp2/1.33.0
+ content-length: 10000
+ host: cgi.tests.httpd.apache.org:42002
+[ 0.004] send DATA frame <length=10000, flags=0x01, stream_id=13>
+ ; END_STREAM
+[ 0.005] recv SETTINGS frame <length=6, flags=0x00, stream_id=0>
+ (niv=1)
+ [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
+[ 0.005] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
+ ; ACK
+ (niv=0)
+[ 0.005] recv WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>
+ (window_size_increment=2147418112)
+[ 0.005] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
+ ; ACK
+ (niv=0)
+[ 0.038] recv (stream_id=13) :status: 200
+[ 0.038] recv (stream_id=13) date: Thu, 14 Feb 2019 11:50:20 GMT
+[ 0.038] recv (stream_id=13) server: Apache/2.4.39-dev (Unix) OpenSSL/1.1.1
+[ 0.038] recv (stream_id=13) content-type: application/data
+[ 0.038] recv HEADERS frame <length=70, flags=0x04, stream_id=13>
+ ; END_HEADERS
+ (padlen=0)
+ ; First response header
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+12345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345678901234567890123456789012345678901[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+23456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345678901234567890123456789012[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+34567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345678901234567890123[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+45678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345678901234[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+56789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+0123456789012345678901234567890123456789012345[ 0.038] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+67890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567[ 0.038] recv DATA frame <length=402, flags=0x00, stream_id=13>
+890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678[ 0.039] recv DATA frame <length=1291, flags=0x00, stream_id=13>
+901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+[ 0.039] recv DATA frame <length=561, flags=0x00, stream_id=13>
+[ 0.039] recv DATA frame <length=0, flags=0x01, stream_id=13>
+ ; END_STREAM
+[ 0.039] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
+ (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
+
Added: httpd/httpd/trunk/test/modules/http2/data/nghttp-output-1k-1.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/data/nghttp-output-1k-1.txt?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/data/nghttp-output-1k-1.txt (added)
+++ httpd/httpd/trunk/test/modules/http2/data/nghttp-output-1k-1.txt Fri Aug 20 16:07:44 2021
@@ -0,0 +1,68 @@
+stderr: [WARNING] Certificate verification failed: unable to verify the first certificate
+
+stdout: [ 0.002] Connected
+The negotiated protocol: h2
+[ 0.004] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
+ (niv=2)
+ [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
+ [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
+ (dep_stream_id=0, weight=201, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
+ (dep_stream_id=0, weight=101, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
+ (dep_stream_id=0, weight=1, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
+ (dep_stream_id=7, weight=1, exclusive=0)
+[ 0.004] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
+ (dep_stream_id=3, weight=1, exclusive=0)
+[ 0.004] send HEADERS frame <length=77, flags=0x24, stream_id=13>
+ ; END_HEADERS | PRIORITY
+ (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
+ ; Open new stream
+ :method: POST
+ :path: //echo.py
+ :scheme: https
+ :authority: 127.0.0.1:42002
+ accept: */*
+ accept-encoding: gzip, deflate
+ user-agent: nghttp2/1.33.0
+ content-length: 1000
+ host: cgi.tests.httpd.apache.org:42002
+[ 0.004] send DATA frame <length=1000, flags=0x01, stream_id=13>
+ ; END_STREAM
+[ 0.005] recv SETTINGS frame <length=6, flags=0x00, stream_id=0>
+ (niv=1)
+ [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
+[ 0.005] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
+ ; ACK
+ (niv=0)
+[ 0.005] recv WINDOW_UPDATE frame <length=4, flags=0x00, stream_id=0>
+ (window_size_increment=2147418112)
+[ 0.005] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
+ ; ACK
+ (niv=0)
+[ 0.048] recv (stream_id=13) :status: 200
+[ 0.048] recv (stream_id=13) date: Thu, 14 Feb 2019 11:48:18 GMT
+[ 0.048] recv (stream_id=13) server: Apache/2.4.39-dev (Unix) OpenSSL/1.1.1
+[ 0.048] recv (stream_id=13) content-type: application/data
+[ 0.048] recv HEADERS frame <length=70, flags=0x04, stream_id=13>
+ ; END_HEADERS
+ (padlen=0)
+ ; First response header
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
+[ 0.048] recv DATA frame <length=1000, flags=0x00, stream_id=13>
+[ 0.048] recv DATA frame <length=0, flags=0x01, stream_id=13>
+ ; END_STREAM
+[ 0.048] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
+ (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
+
Added: httpd/httpd/trunk/test/modules/http2/h2_certs.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/h2_certs.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/h2_certs.py (added)
+++ httpd/httpd/trunk/test/modules/http2/h2_certs.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,447 @@
+import os
+import re
+from datetime import timedelta, datetime
+from typing import List, Any, Optional
+
+from cryptography import x509
+from cryptography.hazmat.backends import default_backend
+from cryptography.hazmat.primitives import hashes
+from cryptography.hazmat.primitives.asymmetric import ec, rsa
+from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateKey
+from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
+from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption, load_pem_private_key
+from cryptography.x509 import ExtendedKeyUsageOID, NameOID
+
+
+EC_SUPPORTED = {}
+EC_SUPPORTED.update([(curve.name.upper(), curve) for curve in [
+ ec.BrainpoolP256R1,
+ ec.BrainpoolP384R1,
+ ec.BrainpoolP512R1,
+ ec.SECP192R1,
+ ec.SECP224R1,
+ ec.SECP256R1,
+ ec.SECP384R1,
+]])
+
+
+def _private_key(key_type):
+ if isinstance(key_type, str):
+ key_type = key_type.upper()
+ m = re.match(r'^(RSA)?(\d+)$', key_type)
+ if m:
+ key_type = int(m.group(2))
+
+ if isinstance(key_type, int):
+ return rsa.generate_private_key(
+ public_exponent=65537,
+ key_size=key_type,
+ backend=default_backend()
+ )
+ if not isinstance(key_type, ec.EllipticCurve) and key_type in EC_SUPPORTED:
+ key_type = EC_SUPPORTED[key_type]
+ return ec.generate_private_key(
+ curve=key_type,
+ backend=default_backend()
+ )
+
+
+class CertificateSpec:
+
+ def __init__(self, name: str = None, domains: List[str] = None,
+ email: str = None,
+ key_type: str = None, single_file: bool = False,
+ valid_from: timedelta = timedelta(days=-1),
+ valid_to: timedelta = timedelta(days=89),
+ client: bool = False,
+ sub_specs: List['CertificateSpec'] = None):
+ self._name = name
+ self.domains = domains
+ self.client = client
+ self.email = email
+ self.key_type = key_type
+ self.single_file = single_file
+ self.valid_from = valid_from
+ self.valid_to = valid_to
+ self.sub_specs = sub_specs
+
+ @property
+ def name(self) -> Optional[str]:
+ if self._name:
+ return self._name
+ elif self.domains:
+ return self.domains[0]
+ return None
+
+
+class Credentials:
+
+ def __init__(self, name: str, cert: Any, pkey: Any):
+ self._name = name
+ self._cert = cert
+ self._pkey = pkey
+ self._cert_file = None
+ self._pkey_file = None
+ self._store = None
+
+ @property
+ def name(self) -> str:
+ return self._name
+
+ @property
+ def subject(self) -> x509.Name:
+ return self._cert.subject
+
+ @property
+ def key_type(self):
+ if isinstance(self._pkey, RSAPrivateKey):
+ return f"rsa{self._pkey.key_size}"
+ elif isinstance(self._pkey, EllipticCurvePrivateKey):
+ return f"{self._pkey.curve.name}"
+ else:
+ raise Exception(f"unknown key type: {self._pkey}")
+
+ @property
+ def private_key(self) -> Any:
+ return self._pkey
+
+ @property
+ def certificate(self) -> Any:
+ return self._cert
+
+ @property
+ def cert_pem(self) -> bytes:
+ return self._cert.public_bytes(Encoding.PEM)
+
+ @property
+ def pkey_pem(self) -> bytes:
+ return self._pkey.private_bytes(
+ Encoding.PEM,
+ PrivateFormat.TraditionalOpenSSL if self.key_type.startswith('rsa') else PrivateFormat.PKCS8,
+ NoEncryption())
+
+ def set_store(self, store: 'CertStore'):
+ self._store = store
+
+ def set_files(self, cert_file: str, pkey_file: str = None):
+ self._cert_file = cert_file
+ self._pkey_file = pkey_file
+
+ @property
+ def cert_file(self) -> str:
+ return self._cert_file
+
+ @property
+ def pkey_file(self) -> Optional[str]:
+ return self._pkey_file
+
+ def get_first(self, name) -> Optional['Credentials']:
+ creds = self._store.get_credentials_for_name(name) if self._store else []
+ return creds[0] if len(creds) else None
+
+ def get_credentials_for_name(self, name) -> List['Credentials']:
+ return self._store.get_credentials_for_name(name) if self._store else []
+
+ def issue_certs(self, specs: List[CertificateSpec],
+ chain: List['Credentials'] = None) -> List['Credentials']:
+ return [self.issue_cert(spec=spec, chain=chain) for spec in specs]
+
+ def issue_cert(self, spec: CertificateSpec, chain: List['Credentials'] = None) -> 'Credentials':
+ key_type = spec.key_type if spec.key_type else self.key_type
+ creds = self._store.load_credentials(name=spec.name, key_type=key_type, single_file=spec.single_file) \
+ if self._store else None
+ if creds is None:
+ creds = H2TestCA.create_credentials(spec=spec, issuer=self, key_type=key_type,
+ valid_from=spec.valid_from, valid_to=spec.valid_to)
+ if self._store:
+ self._store.save(creds, single_file=spec.single_file)
+
+ if spec.sub_specs:
+ if self._store:
+ sub_store = CertStore(fpath=os.path.join(self._store.path, creds.name))
+ creds.set_store(sub_store)
+ subchain = chain.copy() if chain else []
+ subchain.append(self)
+ creds.issue_certs(spec.sub_specs, chain=subchain)
+ return creds
+
+
+class CertStore:
+
+ def __init__(self, fpath: str):
+ self._store_dir = fpath
+ if not os.path.exists(self._store_dir):
+ os.makedirs(self._store_dir)
+ self._creds_by_name = {}
+
+ @property
+ def path(self) -> str:
+ return self._store_dir
+
+ def save(self, creds: Credentials, name: str = None,
+ chain: List[Credentials] = None,
+ single_file: bool = False) -> None:
+ name = name if name is not None else creds.name
+ cert_file = self.get_cert_file(name=name, key_type=creds.key_type)
+ pkey_file = self.get_pkey_file(name=name, key_type=creds.key_type)
+ if single_file:
+ pkey_file = None
+ with open(cert_file, "wb") as fd:
+ fd.write(creds.cert_pem)
+ if chain:
+ for c in chain:
+ fd.write(c.cert_pem)
+ if pkey_file is None:
+ fd.write(creds.pkey_pem)
+ if pkey_file is not None:
+ with open(pkey_file, "wb") as fd:
+ fd.write(creds.pkey_pem)
+ creds.set_files(cert_file, pkey_file)
+ self._add_credentials(name, creds)
+
+ def _add_credentials(self, name: str, creds: Credentials):
+ if name not in self._creds_by_name:
+ self._creds_by_name[name] = []
+ self._creds_by_name[name].append(creds)
+
+ def get_credentials_for_name(self, name) -> List[Credentials]:
+ return self._creds_by_name[name] if name in self._creds_by_name else []
+
+ def get_cert_file(self, name: str, key_type=None) -> str:
+ key_infix = ".{0}".format(key_type) if key_type is not None else ""
+ return os.path.join(self._store_dir, f'{name}{key_infix}.cert.pem')
+
+ def get_pkey_file(self, name: str, key_type=None) -> str:
+ key_infix = ".{0}".format(key_type) if key_type is not None else ""
+ return os.path.join(self._store_dir, f'{name}{key_infix}.pkey.pem')
+
+ def load_pem_cert(self, fpath: str) -> x509.Certificate:
+ with open(fpath) as fd:
+ return x509.load_pem_x509_certificate("".join(fd.readlines()).encode())
+
+ def load_pem_pkey(self, fpath: str):
+ with open(fpath) as fd:
+ return load_pem_private_key("".join(fd.readlines()).encode(), password=None)
+
+ def load_credentials(self, name: str, key_type=None, single_file: bool = False):
+ cert_file = self.get_cert_file(name=name, key_type=key_type)
+ pkey_file = cert_file if single_file else self.get_pkey_file(name=name, key_type=key_type)
+ if os.path.isfile(cert_file) and os.path.isfile(pkey_file):
+ cert = self.load_pem_cert(cert_file)
+ pkey = self.load_pem_pkey(pkey_file)
+ creds = Credentials(name=name, cert=cert, pkey=pkey)
+ creds.set_store(self)
+ creds.set_files(cert_file, pkey_file)
+ self._add_credentials(name, creds)
+ return creds
+ return None
+
+
+class H2TestCA:
+
+ @classmethod
+ def create_root(cls, name: str, store_dir: str, key_type: str = "rsa2048") -> Credentials:
+ store = CertStore(fpath=store_dir)
+ creds = store.load_credentials(name="ca", key_type=key_type)
+ if creds is None:
+ creds = H2TestCA._make_ca_credentials(name=name, key_type=key_type)
+ store.save(creds, name="ca")
+ creds.set_store(store)
+ return creds
+
+ @staticmethod
+ def create_credentials(spec: CertificateSpec, issuer: Credentials, key_type: Any,
+ valid_from: timedelta = timedelta(days=-1),
+ valid_to: timedelta = timedelta(days=89),
+ ) -> Credentials:
+ """Create a certificate signed by this CA for the given domains.
+ :returns: the certificate and private key PEM file paths
+ """
+ if spec.domains and len(spec.domains):
+ creds = H2TestCA._make_server_credentials(name=spec.name, domains=spec.domains,
+ issuer=issuer, valid_from=valid_from,
+ valid_to=valid_to, key_type=key_type)
+ elif spec.client:
+ creds = H2TestCA._make_client_credentials(name=spec.name, issuer=issuer,
+ email=spec.email, valid_from=valid_from,
+ valid_to=valid_to, key_type=key_type)
+ elif spec.name:
+ creds = H2TestCA._make_ca_credentials(name=spec.name, issuer=issuer,
+ valid_from=valid_from, valid_to=valid_to,
+ key_type=key_type)
+ else:
+ raise Exception(f"unrecognized certificate specification: {spec}")
+ return creds
+
+ @staticmethod
+ def _make_x509_name(org_name: str = None, common_name: str = None, parent: x509.Name = None) -> x509.Name:
+ name_pieces = []
+ if org_name:
+ oid = NameOID.ORGANIZATIONAL_UNIT_NAME if parent else NameOID.ORGANIZATION_NAME
+ name_pieces.append(x509.NameAttribute(oid, org_name))
+ elif common_name:
+ name_pieces.append(x509.NameAttribute(NameOID.COMMON_NAME, common_name))
+ if parent:
+ name_pieces.extend([rdn for rdn in parent])
+ return x509.Name(name_pieces)
+
+ @staticmethod
+ def _make_csr(
+ subject: x509.Name,
+ pkey: Any,
+ issuer_subject: Optional[Credentials],
+ valid_from_delta: timedelta = None,
+ valid_until_delta: timedelta = None
+ ):
+ pubkey = pkey.public_key()
+ issuer_subject = issuer_subject if issuer_subject is not None else subject
+
+ valid_from = datetime.now()
+ if valid_until_delta is not None:
+ valid_from += valid_from_delta
+ valid_until = datetime.now()
+ if valid_until_delta is not None:
+ valid_until += valid_until_delta
+
+ return (
+ x509.CertificateBuilder()
+ .subject_name(subject)
+ .issuer_name(issuer_subject)
+ .public_key(pubkey)
+ .not_valid_before(valid_from)
+ .not_valid_after(valid_until)
+ .serial_number(x509.random_serial_number())
+ .add_extension(
+ x509.SubjectKeyIdentifier.from_public_key(pubkey),
+ critical=False,
+ )
+ )
+
+ @staticmethod
+ def _add_ca_usages(csr: Any) -> Any:
+ return csr.add_extension(
+ x509.BasicConstraints(ca=True, path_length=9),
+ critical=True,
+ ).add_extension(
+ x509.KeyUsage(
+ digital_signature=True,
+ content_commitment=False,
+ key_encipherment=False,
+ data_encipherment=False,
+ key_agreement=False,
+ key_cert_sign=True,
+ crl_sign=True,
+ encipher_only=False,
+ decipher_only=False),
+ critical=True
+ ).add_extension(
+ x509.ExtendedKeyUsage([
+ ExtendedKeyUsageOID.CLIENT_AUTH,
+ ExtendedKeyUsageOID.SERVER_AUTH,
+ ExtendedKeyUsageOID.CODE_SIGNING,
+ ]),
+ critical=True
+ )
+
+ @staticmethod
+ def _add_leaf_usages(csr: Any, domains: List[str], issuer: Credentials) -> Any:
+ return csr.add_extension(
+ x509.BasicConstraints(ca=False, path_length=None),
+ critical=True,
+ ).add_extension(
+ x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(
+ issuer.certificate.extensions.get_extension_for_class(
+ x509.SubjectKeyIdentifier).value),
+ critical=False
+ ).add_extension(
+ x509.SubjectAlternativeName([x509.DNSName(domain) for domain in domains]),
+ critical=True,
+ ).add_extension(
+ x509.ExtendedKeyUsage([
+ ExtendedKeyUsageOID.SERVER_AUTH,
+ ]),
+ critical=True
+ )
+
+ @staticmethod
+ def _add_client_usages(csr: Any, issuer: Credentials, rfc82name: str = None) -> Any:
+ cert = csr.add_extension(
+ x509.BasicConstraints(ca=False, path_length=None),
+ critical=True,
+ ).add_extension(
+ x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(
+ issuer.certificate.extensions.get_extension_for_class(
+ x509.SubjectKeyIdentifier).value),
+ critical=False
+ )
+ if rfc82name:
+ cert.add_extension(
+ x509.SubjectAlternativeName([x509.RFC822Name(rfc82name)]),
+ critical=True,
+ )
+ cert.add_extension(
+ x509.ExtendedKeyUsage([
+ ExtendedKeyUsageOID.CLIENT_AUTH,
+ ]),
+ critical=True
+ )
+ return cert
+
+ @staticmethod
+ def _make_ca_credentials(name, key_type: Any,
+ issuer: Credentials = None,
+ valid_from: timedelta = timedelta(days=-1),
+ valid_to: timedelta = timedelta(days=89),
+ ) -> Credentials:
+ pkey = _private_key(key_type=key_type)
+ if issuer is not None:
+ issuer_subject = issuer.certificate.subject
+ issuer_key = issuer.private_key
+ else:
+ issuer_subject = None
+ issuer_key = pkey
+ subject = H2TestCA._make_x509_name(org_name=name, parent=issuer.subject if issuer else None)
+ csr = H2TestCA._make_csr(subject=subject,
+ issuer_subject=issuer_subject, pkey=pkey,
+ valid_from_delta=valid_from, valid_until_delta=valid_to)
+ csr = H2TestCA._add_ca_usages(csr)
+ cert = csr.sign(private_key=issuer_key,
+ algorithm=hashes.SHA256(),
+ backend=default_backend())
+ return Credentials(name=name, cert=cert, pkey=pkey)
+
+ @staticmethod
+ def _make_server_credentials(name: str, domains: List[str], issuer: Credentials,
+ key_type: Any,
+ valid_from: timedelta = timedelta(days=-1),
+ valid_to: timedelta = timedelta(days=89),
+ ) -> Credentials:
+ name = name
+ pkey = _private_key(key_type=key_type)
+ subject = H2TestCA._make_x509_name(common_name=name, parent=issuer.subject)
+ csr = H2TestCA._make_csr(subject=subject,
+ issuer_subject=issuer.certificate.subject, pkey=pkey,
+ valid_from_delta=valid_from, valid_until_delta=valid_to)
+ csr = H2TestCA._add_leaf_usages(csr, domains=domains, issuer=issuer)
+ cert = csr.sign(private_key=issuer.private_key,
+ algorithm=hashes.SHA256(),
+ backend=default_backend())
+ return Credentials(name=name, cert=cert, pkey=pkey)
+
+ @staticmethod
+ def _make_client_credentials(name: str,
+ issuer: Credentials, email: Optional[str],
+ key_type: Any,
+ valid_from: timedelta = timedelta(days=-1),
+ valid_to: timedelta = timedelta(days=89),
+ ) -> Credentials:
+ pkey = _private_key(key_type=key_type)
+ subject = H2TestCA._make_x509_name(common_name=name, parent=issuer.subject)
+ csr = H2TestCA._make_csr(subject=subject,
+ issuer_subject=issuer.certificate.subject, pkey=pkey,
+ valid_from_delta=valid_from, valid_until_delta=valid_to)
+ csr = H2TestCA._add_client_usages(csr, issuer=issuer, rfc82name=email)
+ cert = csr.sign(private_key=issuer.private_key,
+ algorithm=hashes.SHA256(),
+ backend=default_backend())
+ return Credentials(name=name, cert=cert, pkey=pkey)
Added: httpd/httpd/trunk/test/modules/http2/h2_conf.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/h2_conf.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/h2_conf.py (added)
+++ httpd/httpd/trunk/test/modules/http2/h2_conf.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,147 @@
+import os
+
+
+class HttpdConf(object):
+
+ def __init__(self, env, path=None):
+ self.env = env
+ self._lines = []
+ self._has_ssl_vhost = False
+
+ def install(self):
+ if not self._has_ssl_vhost:
+ self.add_vhost_test1()
+ self.env.install_test_conf(self._lines)
+
+ def add(self, line):
+ if isinstance(line, list):
+ self._lines.extend(line)
+ else:
+ self._lines.append(line)
+ return self
+
+ def add_vhost(self, port, name, aliases=None, doc_root="htdocs", with_ssl=True):
+ self.start_vhost(port, name, aliases, doc_root, with_ssl)
+ self.end_vhost()
+ return self
+
+ def start_vhost(self, port, name, aliases=None, doc_root="htdocs", with_ssl=True):
+ server_domain = f"{name}.{self.env.http_tld}"
+ lines = [
+ f"<VirtualHost *:{port}>",
+ f" ServerName {server_domain}"
+ ]
+ if aliases:
+ lines.extend([
+ f" ServerAlias {alias}.{self.env.http_tld}" for alias in aliases])
+ lines.append(f" DocumentRoot {doc_root}")
+ if with_ssl:
+ self._has_ssl_vhost = True
+ lines.append(" SSLEngine on")
+ for cred in self.env.get_credentials_for_name(server_domain):
+ lines.extend([
+ f"SSLCertificateFile {cred.cert_file}",
+ f"SSLCertificateKeyFile {cred.pkey_file}",
+ ])
+ return self.add(lines)
+
+ def end_vhost(self):
+ self.add("</VirtualHost>")
+ return self
+
+ def add_proxies(self, host, proxy_self=False, h2proxy_self=False):
+ if proxy_self or h2proxy_self:
+ self.add(" ProxyPreserveHost on")
+ if proxy_self:
+ self.add(f"""
+ ProxyPass /proxy/ http://127.0.0.1:{self.env.http_port}/
+ ProxyPassReverse /proxy/ http://{host}.{self.env.http_tld}:{self.env.http_port}/
+ """)
+ if h2proxy_self:
+ self.add(f"""
+ ProxyPass /h2proxy/ h2://127.0.0.1:{self.env.https_port}/
+ ProxyPassReverse /h2proxy/ https://{host}.{self.env.http_tld}:self.env.https_port/
+ """)
+ return self
+
+ def add_vhost_test1(self, proxy_self=False, h2proxy_self=False, extras=None):
+ domain = f"test1.{self.env.http_tld}"
+ if extras and 'base' in extras:
+ self.add(extras['base'])
+ self.start_vhost(
+ self.env.http_port, "test1", aliases=["www1"], doc_root="htdocs/test1", with_ssl=False
+ ).add(
+ " Protocols h2c http/1.1"
+ ).end_vhost()
+ self.start_vhost(
+ self.env.https_port, "test1", aliases=["www1"], doc_root="htdocs/test1", with_ssl=True)
+ self.add(f"""
+ Protocols h2 http/1.1
+ <Location /006>
+ Options +Indexes
+ HeaderName /006/header.html
+ </Location>
+ {extras[domain] if extras and domain in extras else ""}
+ """)
+ self.add_proxies("test1", proxy_self, h2proxy_self)
+ self.end_vhost()
+ return self
+
+ def add_vhost_test2(self):
+ self.start_vhost(self.env.http_port, "test2", aliases=["www2"], doc_root="htdocs/test2", with_ssl=False)
+ self.add(" Protocols http/1.1 h2c")
+ self.end_vhost()
+ self.start_vhost(self.env.https_port, "test2", aliases=["www2"], doc_root="htdocs/test2", with_ssl=True)
+ self.add("""
+ Protocols http/1.1 h2
+ <Location /006>
+ Options +Indexes
+ HeaderName /006/header.html
+ </Location>""")
+ self.end_vhost()
+ return self
+
+ def add_vhost_cgi(self, proxy_self=False, h2proxy_self=False):
+ if proxy_self:
+ self.add_proxy_setup()
+ if h2proxy_self:
+ self.add(" SSLProxyEngine on")
+ self.add(" SSLProxyCheckPeerName off")
+ self.start_vhost(self.env.https_port, "cgi", aliases=["cgi-alias"], doc_root="htdocs/cgi", with_ssl=True)
+ self.add("""
+ Protocols h2 http/1.1
+ SSLOptions +StdEnvVars
+ AddHandler cgi-script .py
+ <Location \"/.well-known/h2/state\">
+ SetHandler http2-status
+ </Location>""")
+ self.add_proxies("cgi", proxy_self, h2proxy_self)
+ self.add(" <Location \"/h2test/echo\">")
+ self.add(" SetHandler h2test-echo")
+ self.add(" </Location>")
+ self.end_vhost()
+ self.start_vhost(self.env.http_port, "cgi", aliases=["cgi-alias"], doc_root="htdocs/cgi", with_ssl=False)
+ self.add(" AddHandler cgi-script .py")
+ self.end_vhost()
+ self.add(" LogLevel proxy:info")
+ self.add(" LogLevel proxy_http:info")
+ return self
+
+ def add_vhost_noh2(self):
+ self.start_vhost(self.env.https_port, "noh2", aliases=["noh2-alias"], doc_root="htdocs/noh2", with_ssl=True)
+ self.add(f"""
+ Protocols http/1.1
+ SSLOptions +StdEnvVars""")
+ self.end_vhost()
+ self.start_vhost(self.env.http_port, "noh2", aliases=["noh2-alias"], doc_root="htdocs/noh2", with_ssl=False)
+ self.add(" Protocols http/1.1")
+ self.add(" SSLOptions +StdEnvVars")
+ self.end_vhost()
+ return self
+
+ def add_proxy_setup(self):
+ self.add("ProxyStatus on")
+ self.add("ProxyTimeout 5")
+ self.add("SSLProxyEngine on")
+ self.add("SSLProxyVerify none")
+ return self
Added: httpd/httpd/trunk/test/modules/http2/h2_env.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/h2_env.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/h2_env.py (added)
+++ httpd/httpd/trunk/test/modules/http2/h2_env.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,543 @@
+import inspect
+import logging
+import re
+import os
+import shutil
+import stat
+import subprocess
+import sys
+import time
+from datetime import datetime, timedelta
+from string import Template
+from typing import List
+
+import requests
+
+from configparser import ConfigParser, ExtendedInterpolation
+from urllib.parse import urlparse
+
+from h2_certs import Credentials
+from h2_nghttp import Nghttp
+from h2_result import ExecResult
+
+
+log = logging.getLogger(__name__)
+
+
+class Dummy:
+ pass
+
+
+class H2TestSetup:
+
+ def __init__(self, env: 'H2TestEnv'):
+ self.env = env
+
+ def make(self):
+ self._make_dirs()
+ self._make_conf()
+ self._make_htdocs()
+ self._make_h2test()
+
+ def _make_dirs(self):
+ if os.path.exists(self.env.gen_dir):
+ shutil.rmtree(self.env.gen_dir)
+ os.makedirs(self.env.gen_dir)
+ if not os.path.exists(self.env.server_logs_dir):
+ os.makedirs(self.env.server_logs_dir)
+
+ def _make_conf(self):
+ conf_src_dir = os.path.join(self.env.test_dir, 'conf')
+ conf_dest_dir = os.path.join(self.env.server_dir, 'conf')
+ if not os.path.exists(conf_dest_dir):
+ os.makedirs(conf_dest_dir)
+ for name in os.listdir(conf_src_dir):
+ src_path = os.path.join(conf_src_dir, name)
+ m = re.match(r'(.+).template', name)
+ if m:
+ self._make_template(src_path, os.path.join(conf_dest_dir, m.group(1)))
+ elif os.path.isfile(src_path):
+ shutil.copy(src_path, os.path.join(conf_dest_dir, name))
+
+ def _make_template(self, src, dest):
+ var_map = dict()
+ for name, value in self.env.__class__.__dict__.items():
+ if isinstance(value, property):
+ var_map[name] = value.fget(self.env)
+ t = Template(''.join(open(src).readlines()))
+ with open(dest, 'w') as fd:
+ fd.write(t.substitute(var_map))
+
+ def _make_htdocs(self):
+ if not os.path.exists(self.env.server_docs_dir):
+ os.makedirs(self.env.server_docs_dir)
+ shutil.copytree(os.path.join(self.env.test_dir, 'htdocs'),
+ os.path.join(self.env.server_dir, 'htdocs'),
+ dirs_exist_ok=True)
+ cgi_dir = os.path.join(self.env.server_dir, 'htdocs/cgi')
+ for name in os.listdir(cgi_dir):
+ if re.match(r'.+\.py', name):
+ cgi_file = os.path.join(cgi_dir, name)
+ st = os.stat(cgi_file)
+ os.chmod(cgi_file, st.st_mode | stat.S_IEXEC)
+
+ def _make_h2test(self):
+ subprocess.run([self.env.apxs, '-c', 'mod_h2test.c'],
+ capture_output=True, check=True,
+ cwd=os.path.join(self.env.test_dir, 'mod_h2test'))
+
+
+class H2TestEnv:
+
+ def __init__(self, pytestconfig=None):
+ our_dir = os.path.dirname(inspect.getfile(Dummy))
+ self.config = ConfigParser(interpolation=ExtendedInterpolation())
+ self.config.read(os.path.join(our_dir, 'config.ini'))
+
+ self._apxs = self.config.get('global', 'apxs')
+ self._prefix = self.config.get('global', 'prefix')
+ self._apachectl = self.config.get('global', 'apachectl')
+ self._libexec_dir = self.get_apxs_var('LIBEXECDIR')
+
+ self._curl = self.config.get('global', 'curl_bin')
+ self._nghttp = self.config.get('global', 'nghttp')
+ self._h2load = self.config.get('global', 'h2load')
+ self._ca = None
+
+ self._http_port = int(self.config.get('test', 'http_port'))
+ self._https_port = int(self.config.get('test', 'https_port'))
+ self._http_tld = self.config.get('test', 'http_tld')
+ self._test_dir = self.config.get('test', 'test_dir')
+ self._test_src_dir = self.config.get('test', 'test_src_dir')
+ self._gen_dir = self.config.get('test', 'gen_dir')
+ self._server_dir = self.config.get('test', 'server_dir')
+ self._server_conf_dir = os.path.join(self._server_dir, "conf")
+ self._server_docs_dir = os.path.join(self._server_dir, "htdocs")
+ self._server_logs_dir = os.path.join(self.server_dir, "logs")
+ self._server_error_log = os.path.join(self._server_logs_dir, "error_log")
+ self._domains = [
+ f"test1.{self._http_tld}",
+ f"test2.{self._http_tld}",
+ f"test3.{self._http_tld}",
+ f"cgi.{self._http_tld}",
+ f"push.{self._http_tld}",
+ f"hints.{self._http_tld}",
+ f"ssl.{self._http_tld}",
+ f"pad0.{self._http_tld}",
+ f"pad1.{self._http_tld}",
+ f"pad2.{self._http_tld}",
+ f"pad3.{self._http_tld}",
+ f"pad8.{self._http_tld}",
+ ]
+ self._domains_noh2 = [
+ f"noh2.{self._http_tld}",
+ ]
+ self._mpm_type = os.environ['MPM'] if 'MPM' in os.environ else 'event'
+
+ self._httpd_addr = "127.0.0.1"
+ self._http_base = f"http://{self._httpd_addr}:{self.http_port}"
+ self._https_base = f"https://{self._httpd_addr}:{self.https_port}"
+
+ self._test_conf = os.path.join(self._server_conf_dir, "test.conf")
+ self._httpd_base_conf = f"""
+ LoadModule mpm_{self.mpm_type}_module \"{self.libexec_dir}/mod_mpm_{self.mpm_type}.so\"
+ H2MinWorkers 1
+ H2MaxWorkers 64
+ SSLSessionCache "shmcb:ssl_gcache_data(32000)"
+ """
+ py_verbosity = pytestconfig.option.verbose if pytestconfig is not None else 0
+ if py_verbosity >= 2:
+ self._httpd_base_conf += f"""
+ LogLevel http2:trace2 proxy_http2:info
+ LogLevel core:trace5 mpm_{self.mpm_type}:trace5
+ """
+ if py_verbosity >= 1:
+ self._httpd_base_conf += "LogLevel http2:debug proxy_http2:debug"
+ else:
+ self._httpd_base_conf += "LogLevel http2:info proxy_http2:info"
+
+ self._verify_certs = False
+ self._setup = H2TestSetup(env=self)
+ self._setup.make()
+
+ @property
+ def apxs(self) -> str:
+ return self._apxs
+
+ @property
+ def prefix(self) -> str:
+ return self._prefix
+
+ @property
+ def mpm_type(self) -> str:
+ return self._mpm_type
+
+ @property
+ def http_port(self) -> int:
+ return self._http_port
+
+ @property
+ def https_port(self) -> int:
+ return self._https_port
+
+ @property
+ def http_tld(self) -> str:
+ return self._http_tld
+
+ @property
+ def domain_test1(self) -> str:
+ return self._domains[0]
+
+ @property
+ def domains(self) -> List[str]:
+ return self._domains
+
+ @property
+ def domains_noh2(self) -> List[str]:
+ return self._domains_noh2
+
+ @property
+ def http_base_url(self) -> str:
+ return self._http_base
+
+ @property
+ def https_base_url(self) -> str:
+ return self._https_base
+
+ @property
+ def gen_dir(self) -> str:
+ return self._gen_dir
+
+ @property
+ def test_dir(self) -> str:
+ return self._test_dir
+
+ @property
+ def test_src_dir(self) -> str:
+ return self._test_src_dir
+
+ @property
+ def server_dir(self) -> str:
+ return self._server_dir
+
+ @property
+ def server_logs_dir(self) -> str:
+ return self._server_logs_dir
+
+ @property
+ def libexec_dir(self) -> str:
+ return self._libexec_dir
+
+ @property
+ def server_conf_dir(self) -> str:
+ return self._server_conf_dir
+
+ @property
+ def server_docs_dir(self) -> str:
+ return self._server_docs_dir
+
+ @property
+ def httpd_base_conf(self) -> str:
+ return self._httpd_base_conf
+
+ @property
+ def h2load(self) -> str:
+ return self._h2load
+
+ @property
+ def ca(self) -> Credentials:
+ return self._ca
+
+ def set_ca(self, ca: Credentials):
+ self._ca = ca
+
+ def get_credentials_for_name(self, dns_name) -> List['Credentials']:
+ for domains in [self._domains, self._domains_noh2]:
+ if dns_name in domains:
+ return self.ca.get_credentials_for_name(domains[0])
+ return []
+
+ def has_h2load(self):
+ return self._h2load != ""
+
+ def has_nghttp(self):
+ return self._nghttp != ""
+
+ def has_nghttp_get_assets(self):
+ if not self.has_nghttp():
+ return False
+ args = [self._nghttp, "-a"]
+ p = subprocess.run(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ rv = p.returncode
+ if rv != 0:
+ return False
+ return p.stderr == ""
+
+ def get_apxs_var(self, name: str) -> str:
+ p = subprocess.run([self._apxs, "-q", name], capture_output=True, text=True)
+ if p.returncode != 0:
+ return ""
+ return p.stdout.strip()
+
+ def get_httpd_version(self) -> str:
+ return self.get_apxs_var("HTTPD_VERSION")
+
+ def mkpath(self, path):
+ if not os.path.exists(path):
+ return os.makedirs(path)
+
+ def test_src(self, path):
+ return os.path.join(self._test_src_dir, path)
+
+ def run(self, args) -> ExecResult:
+ log.debug("execute: %s", " ".join(args))
+ start = datetime.now()
+ p = subprocess.run(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ return ExecResult(exit_code=p.returncode, stdout=p.stdout, stderr=p.stderr,
+ duration=datetime.now() - start)
+
+ def mkurl(self, scheme, hostname, path='/'):
+ port = self.https_port if scheme == 'https' else self.http_port
+ return "%s://%s.%s:%s%s" % (scheme, hostname, self.http_tld, port, path)
+
+ def install_test_conf(self, conf: List[str]):
+ with open(self._test_conf, 'w') as fd:
+ fd.write(f"{self.httpd_base_conf}\n")
+ for line in conf:
+ fd.write(f"{line}\n")
+
+ def is_live(self, url, timeout: timedelta = None):
+ s = requests.Session()
+ if not timeout:
+ timeout = timedelta(seconds=10)
+ try_until = datetime.now() + timeout
+ log.debug("checking reachability of %s", url)
+ while datetime.now() < try_until:
+ try:
+ req = requests.Request('HEAD', url).prepare()
+ s.send(req, verify=self._verify_certs, timeout=timeout.total_seconds())
+ return True
+ except IOError:
+ log.debug("connect error: %s", sys.exc_info()[0])
+ time.sleep(.2)
+ except:
+ log.warning("Unexpected error: %s", sys.exc_info()[0])
+ time.sleep(.2)
+ log.debug(f"Unable to contact '{url}' after {timeout} sec")
+ return False
+
+ def is_dead(self, url, timeout: timedelta = None):
+ s = requests.Session()
+ if not timeout:
+ timeout = timedelta(seconds=10)
+ try_until = datetime.now() + timeout
+ log.debug("checking reachability of %s", url)
+ while datetime.now() < try_until:
+ try:
+ req = requests.Request('HEAD', url).prepare()
+ s.send(req, verify=self._verify_certs, timeout=timeout)
+ time.sleep(.2)
+ except IOError:
+ return True
+ except:
+ return True
+ log.debug("Server still responding after %d sec", timeout)
+ return False
+
+ def apachectl(self, cmd, check_live=True):
+ args = [self._apachectl,
+ "-d", self.server_dir,
+ "-f", os.path.join(self._server_dir, 'conf/httpd.conf'),
+ "-k", cmd]
+ log.debug("execute: %s", " ".join(args))
+ p = subprocess.run(args, capture_output=True, text=True)
+ rv = p.returncode
+ if rv == 0:
+ timeout = timedelta(seconds=10)
+ if check_live:
+ rv = 0 if self.is_live(self._http_base, timeout=timeout) else -1
+ else:
+ rv = 0 if self.is_dead(self._http_base, timeout=timeout) else -1
+ log.debug("waited for a apache.is_dead, rv=%d", rv)
+ else:
+ log.warning(f"exit {rv}, stdout: {p.stdout}, stderr: {p.stderr}")
+ return rv
+
+ def apache_restart(self):
+ return self.apachectl("graceful")
+
+ def apache_start(self):
+ return self.apachectl("start")
+
+ def apache_stop(self):
+ return self.apachectl("stop", check_live=False)
+
+ def apache_error_log_clear(self):
+ if os.path.isfile(self._server_error_log):
+ os.remove(self._server_error_log)
+
+ RE_APLOGNO = re.compile(r'.*\[(?P<module>[^:]+):(error|warn)].* (?P<aplogno>AH\d+): .+')
+ RE_SSL_LIB_ERR = re.compile(r'.*\[ssl:error].* SSL Library Error: error:(?P<errno>\S+):.+')
+ RE_ERRLOG_ERROR = re.compile(r'.*\[(?P<module>[^:]+):error].*')
+ RE_ERRLOG_WARN = re.compile(r'.*\[(?P<module>[^:]+):warn].*')
+
+ def apache_errors_and_warnings(self):
+ errors = []
+ warnings = []
+
+ if os.path.isfile(self._server_error_log):
+ for line in open(self._server_error_log):
+ m = self.RE_APLOGNO.match(line)
+ if m and m.group('aplogno') in [
+ 'AH02032',
+ 'AH01276',
+ 'AH01630',
+ 'AH00135',
+ 'AH02261', # Re-negotiation handshake failed (our test_101
+ ]:
+ # we know these happen normally in our tests
+ continue
+ m = self.RE_SSL_LIB_ERR.match(line)
+ if m and m.group('errno') in [
+ '1417A0C1', # cipher suite mismatch, test_101
+ '1417C0C7', # client cert not accepted, test_101
+ ]:
+ # we know these happen normally in our tests
+ continue
+ m = self.RE_ERRLOG_ERROR.match(line)
+ if m and m.group('module') not in ['cgid']:
+ errors.append(line)
+ continue
+ m = self.RE_ERRLOG_WARN.match(line)
+ if m:
+ warnings.append(line)
+ continue
+ return errors, warnings
+
+ def curl_complete_args(self, urls, timeout, options):
+ if not isinstance(urls, list):
+ urls = [urls]
+ u = urlparse(urls[0])
+ assert u.hostname, f"hostname not in url: {urls[0]}"
+ assert u.port, f"port not in url: {urls[0]}"
+ headerfile = ("%s/curl.headers" % self.gen_dir)
+ if os.path.isfile(headerfile):
+ os.remove(headerfile)
+
+ args = [
+ self._curl,
+ "--cacert", self.ca.cert_file,
+ "-s", "-D", headerfile,
+ "--resolve", ("%s:%s:%s" % (u.hostname, u.port, self._httpd_addr)),
+ "--connect-timeout", ("%d" % timeout)
+ ]
+ if options:
+ args.extend(options)
+ args += urls
+ return args, headerfile
+
+ def curl_raw(self, urls, timeout, options):
+ args, headerfile = self.curl_complete_args(urls, timeout, options)
+ r = self.run(args)
+ if r.exit_code == 0:
+ lines = open(headerfile).readlines()
+ exp_stat = True
+ header = {}
+ for line in lines:
+ if exp_stat:
+ log.debug("reading 1st response line: %s", line)
+ m = re.match(r'^(\S+) (\d+) (.*)$', line)
+ assert m
+ r.add_response({
+ "protocol": m.group(1),
+ "status": int(m.group(2)),
+ "description": m.group(3),
+ "body": r.outraw
+ })
+ exp_stat = False
+ header = {}
+ elif re.match(r'^$', line):
+ exp_stat = True
+ else:
+ log.debug("reading header line: %s", line)
+ m = re.match(r'^([^:]+):\s*(.*)$', line)
+ assert m
+ header[m.group(1).lower()] = m.group(2)
+ r.response["header"] = header
+ if r.json:
+ r.response["json"] = r.json
+ return r
+
+ def curl_get(self, url, timeout=5, options=None):
+ return self.curl_raw([url], timeout=timeout, options=options)
+
+ def curl_upload(self, url, fpath, timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend([
+ "--form", ("file=@%s" % fpath)
+ ])
+ return self.curl_raw([url], timeout, options)
+
+ def curl_post_data(self, url, data="", timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend(["--data", "%s" % data])
+ return self.curl_raw(url, timeout, options)
+
+ def curl_post_value(self, url, key, value, timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend(["--form", "{0}={1}".format(key, value)])
+ return self.curl_raw(url, timeout, options)
+
+ def curl_protocol_version(self, url, timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend(["-w", "%{http_version}\n", "-o", "/dev/null"])
+ r = self.curl_raw(url, timeout=timeout, options=options)
+ if r.exit_code == 0 and r.response:
+ return r.response["body"].decode('utf-8').rstrip()
+ return -1
+
+ def nghttp(self):
+ return Nghttp(self._nghttp, connect_addr=self._httpd_addr, tmp_dir=self.gen_dir)
+
+ def h2load_status(self, run: ExecResult):
+ stats = {}
+ m = re.search(
+ r'requests: (\d+) total, (\d+) started, (\d+) done, (\d+) succeeded'
+ r', (\d+) failed, (\d+) errored, (\d+) timeout', run.stdout)
+ if m:
+ stats["requests"] = {
+ "total": int(m.group(1)),
+ "started": int(m.group(2)),
+ "done": int(m.group(3)),
+ "succeeded": int(m.group(4))
+ }
+ m = re.search(r'status codes: (\d+) 2xx, (\d+) 3xx, (\d+) 4xx, (\d+) 5xx',
+ run.stdout)
+ if m:
+ stats["status"] = {
+ "2xx": int(m.group(1)),
+ "3xx": int(m.group(2)),
+ "4xx": int(m.group(3)),
+ "5xx": int(m.group(4))
+ }
+ run.add_results({"h2load": stats})
+ return run
+
+ def setup_data_1k_1m(self):
+ s100 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n"
+ with open(os.path.join(self.gen_dir, "data-1k"), 'w') as f:
+ for i in range(10):
+ f.write(s100)
+ with open(os.path.join(self.gen_dir, "data-10k"), 'w') as f:
+ for i in range(100):
+ f.write(s100)
+ with open(os.path.join(self.gen_dir, "data-100k"), 'w') as f:
+ for i in range(1000):
+ f.write(s100)
+ with open(os.path.join(self.gen_dir, "data-1m"), 'w') as f:
+ for i in range(10000):
+ f.write(s100)
Added: httpd/httpd/trunk/test/modules/http2/h2_nghttp.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/h2_nghttp.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/h2_nghttp.py (added)
+++ httpd/httpd/trunk/test/modules/http2/h2_nghttp.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,288 @@
+import re
+import os
+import subprocess
+from datetime import datetime
+from typing import Dict
+
+from urllib.parse import urlparse
+
+from h2_result import ExecResult
+
+
+def _get_path(x):
+ return x["path"]
+
+
+class Nghttp:
+
+ def __init__(self, path, connect_addr=None, tmp_dir="/tmp"):
+ self.NGHTTP = path
+ self.CONNECT_ADDR = connect_addr
+ self.TMP_DIR = tmp_dir
+
+ @staticmethod
+ def get_stream(streams, sid):
+ sid = int(sid)
+ if sid not in streams:
+ streams[sid] = {
+ "id": sid,
+ "header": {},
+ "request": {
+ "id": sid,
+ "body": b''
+ },
+ "response": {
+ "id": sid,
+ "body": b''
+ },
+ "paddings": [],
+ "promises": []
+ }
+ return streams[sid] if sid in streams else None
+
+ def run(self, urls, timeout, options):
+ return self._baserun(urls, timeout, options)
+
+ def complete_args(self, url, _timeout, options: [str]) -> [str]:
+ if not isinstance(url, list):
+ url = [url]
+ u = urlparse(url[0])
+ args = [self.NGHTTP]
+ if self.CONNECT_ADDR:
+ connect_host = self.CONNECT_ADDR
+ args.append("--header=host: %s:%s" % (u.hostname, u.port))
+ else:
+ connect_host = u.hostname
+ if options:
+ args.extend(options)
+ for xurl in url:
+ xu = urlparse(xurl)
+ nurl = "%s://%s:%s/%s" % (u.scheme, connect_host, xu.port, xu.path)
+ if xu.query:
+ nurl = "%s?%s" % (nurl, xu.query)
+ args.append(nurl)
+ return args
+
+ def _baserun(self, url, timeout, options):
+ return self._run(self.complete_args(url, timeout, options))
+
+ def parse_output(self, btext) -> Dict:
+ # getting meta data and response body out of nghttp's output
+ # is a bit tricky. Without '-v' we just get the body. With '-v' meta
+ # data and timings in both directions are listed.
+ # We rely on response :status: to be unique and on
+ # response body not starting with space.
+ # Something not good enough for general purpose, but for these tests.
+ output = {}
+ body = ''
+ streams = {}
+ skip_indents = True
+ # chunk output into lines. nghttp mixes text
+ # meta output with bytes from the response body.
+ lines = [l.decode() for l in btext.split(b'\n')]
+ for lidx, l in enumerate(lines):
+ if len(l) == 0:
+ body += '\n'
+ continue
+ m = re.match(r'\[.*] recv \(stream_id=(\d+)\) (\S+): (\S*)', l)
+ if m:
+ s = self.get_stream(streams, m.group(1))
+ hname = m.group(2)
+ hval = m.group(3)
+ print("stream %d header %s: %s" % (s["id"], hname, hval))
+ header = s["header"]
+ if hname in header:
+ header[hname] += ", %s" % hval
+ else:
+ header[hname] = hval
+ body = ''
+ continue
+
+ m = re.match(r'\[.*] recv HEADERS frame <.* stream_id=(\d+)>', l)
+ if m:
+ s = self.get_stream(streams, m.group(1))
+ if s:
+ print("stream %d: recv %d header" % (s["id"], len(s["header"])))
+ response = s["response"]
+ hkey = "header"
+ if "header" in response:
+ h = response["header"]
+ if ":status" in h and int(h[":status"]) >= 200:
+ hkey = "trailer"
+ else:
+ prev = {
+ "header": h
+ }
+ if "previous" in response:
+ prev["previous"] = response["previous"]
+ response["previous"] = prev
+ response[hkey] = s["header"]
+ s["header"] = {}
+ body = ''
+ continue
+
+ m = re.match(r'(.*)\[.*] recv DATA frame <length=(\d+), .*stream_id=(\d+)>', l)
+ if m:
+ s = self.get_stream(streams, m.group(3))
+ body += m.group(1)
+ blen = int(m.group(2))
+ if s:
+ print("stream %d: %d DATA bytes added" % (s["id"], blen))
+ padlen = 0
+ if len(lines) > lidx + 2:
+ mpad = re.match(r' +\(padlen=(\d+)\)', lines[lidx+2])
+ if mpad:
+ padlen = int(mpad.group(1))
+ s["paddings"].append(padlen)
+ blen -= padlen
+ s["response"]["body"] += body[-blen:].encode()
+ body = ''
+ skip_indents = True
+ continue
+
+ m = re.match(r'\[.*] recv PUSH_PROMISE frame <.* stream_id=(\d+)>', l)
+ if m:
+ s = self.get_stream(streams, m.group(1))
+ if s:
+ # headers we have are request headers for the PUSHed stream
+ # these have been received on the originating stream, the promised
+ # stream id it mentioned in the following lines
+ print("stream %d: %d PUSH_PROMISE header" % (s["id"], len(s["header"])))
+ if len(lines) > lidx+2:
+ m2 = re.match(r'\s+\(.*promised_stream_id=(\d+)\)', lines[lidx+2])
+ if m2:
+ s2 = self.get_stream(streams, m2.group(1))
+ s2["request"]["header"] = s["header"]
+ s["promises"].append(s2)
+ s["header"] = {}
+ continue
+
+ m = re.match(r'(.*)\[.*] recv (\S+) frame <length=(\d+), .*stream_id=(\d+)>', l)
+ if m:
+ print("recv frame %s on stream %s" % (m.group(2), m.group(4)))
+ body += m.group(1)
+ skip_indents = True
+ continue
+
+ m = re.match(r'(.*)\[.*] send (\S+) frame <length=(\d+), .*stream_id=(\d+)>', l)
+ if m:
+ print("send frame %s on stream %s" % (m.group(2), m.group(4)))
+ body += m.group(1)
+ skip_indents = True
+ continue
+
+ if skip_indents and l.startswith(' '):
+ continue
+
+ if '[' != l[0]:
+ skip_indents = None
+ body += l + '\n'
+
+ # the main request is done on the lowest odd numbered id
+ main_stream = 99999999999
+ for sid in streams:
+ s = streams[sid]
+ if ":status" in s["response"]["header"]:
+ s["response"]["status"] = int(s["response"]["header"][":status"])
+ if (sid % 2) == 1 and sid < main_stream:
+ main_stream = sid
+
+ output["streams"] = streams
+ if main_stream in streams:
+ output["response"] = streams[main_stream]["response"]
+ output["paddings"] = streams[main_stream]["paddings"]
+ return output
+
+ def _raw(self, url, timeout, options):
+ args = ["-v"]
+ if options:
+ args.extend(options)
+ r = self._baserun(url, timeout, args)
+ if 0 == r.exit_code:
+ r.add_results(self.parse_output(r.outraw))
+ return r
+
+ def get(self, url, timeout=5, options=None):
+ return self._raw(url, timeout, options)
+
+ def assets(self, url, timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend(["-ans"])
+ r = self._baserun(url, timeout, options)
+ assets = []
+ if 0 == r.exit_code:
+ lines = re.findall(r'[^\n]*\n', r.stdout, re.MULTILINE)
+ for lidx, l in enumerate(lines):
+ m = re.match(r'\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+/(.*)', l)
+ if m:
+ assets.append({
+ "path": m.group(7),
+ "status": int(m.group(5)),
+ "size": m.group(6)
+ })
+ assets.sort(key=_get_path)
+ r.add_assets(assets)
+ return r
+
+ def post_data(self, url, data, timeout=5, options=None):
+ reqbody = ("%s/nghttp.req.body" % self.TMP_DIR)
+ with open(reqbody, 'wb') as f:
+ f.write(data.encode('utf-8'))
+ if not options:
+ options = []
+ options.extend(["--data=%s" % reqbody])
+ return self._raw(url, timeout, options)
+
+ def post_name(self, url, name, timeout=5, options=None):
+ reqbody = ("%s/nghttp.req.body" % self.TMP_DIR)
+ with open(reqbody, 'w') as f:
+ f.write("--DSAJKcd9876\n")
+ f.write("Content-Disposition: form-data; name=\"value\"; filename=\"xxxxx\"\n")
+ f.write("Content-Type: text/plain\n")
+ f.write("\n%s\n" % name)
+ f.write("--DSAJKcd9876\n")
+ if not options:
+ options = []
+ options.extend(["--data=%s" % reqbody])
+ return self._raw(url, timeout, options)
+
+ def upload(self, url, fpath, timeout=5, options=None):
+ if not options:
+ options = []
+ options.extend(["--data=%s" % fpath])
+ return self._raw(url, timeout, options)
+
+ def upload_file(self, url, fpath, timeout=5, options=None):
+ fname = os.path.basename(fpath)
+ reqbody = ("%s/nghttp.req.body" % self.TMP_DIR)
+ with open(fpath, 'rb') as fin:
+ with open(reqbody, 'wb') as f:
+ f.write(("""--DSAJKcd9876
+Content-Disposition: form-data; name="xxx"; filename="xxxxx"
+Content-Type: text/plain
+
+testing mod_h2
+--DSAJKcd9876
+Content-Disposition: form-data; name="file"; filename="%s"
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: binary
+
+""" % fname).encode('utf-8'))
+ f.write(fin.read())
+ f.write("""
+--DSAJKcd9876""".encode('utf-8'))
+ if not options:
+ options = []
+ options.extend([
+ "--data=%s" % reqbody,
+ "--expect-continue",
+ "-HContent-Type: multipart/form-data; boundary=DSAJKcd9876"])
+ return self._raw(url, timeout, options)
+
+ def _run(self, args) -> ExecResult:
+ print(("execute: %s" % " ".join(args)))
+ start = datetime.now()
+ p = subprocess.run(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ return ExecResult(exit_code=p.returncode, stdout=p.stdout, stderr=p.stderr,
+ duration=datetime.now() - start)
Added: httpd/httpd/trunk/test/modules/http2/h2_result.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/h2_result.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/h2_result.py (added)
+++ httpd/httpd/trunk/test/modules/http2/h2_result.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,71 @@
+import json
+from datetime import timedelta
+from typing import Optional, Dict, List
+
+
+class ExecResult:
+
+ def __init__(self, exit_code: int, stdout: bytes, stderr: bytes = None, duration: timedelta = None):
+ self._exit_code = exit_code
+ self._raw = stdout if stdout else b''
+ self._stdout = stdout.decode() if stdout is not None else ""
+ self._stderr = stderr.decode() if stderr is not None else ""
+ self._duration = duration if duration is not None else timedelta()
+ self._response = None
+ self._results = {}
+ self._assets = []
+ # noinspection PyBroadException
+ try:
+ self._json_out = json.loads(self._stdout)
+ except:
+ self._json_out = None
+
+ @property
+ def exit_code(self) -> int:
+ return self._exit_code
+
+ @property
+ def outraw(self) -> bytes:
+ return self._raw
+
+ @property
+ def stdout(self) -> str:
+ return self._stdout
+
+ @property
+ def json(self) -> Optional[Dict]:
+ """Output as JSON dictionary or None if not parseable."""
+ return self._json_out
+
+ @property
+ def stderr(self) -> str:
+ return self._stderr
+
+ @property
+ def duration(self) -> timedelta:
+ return self._duration
+
+ @property
+ def response(self) -> Optional[Dict]:
+ return self._response
+
+ @property
+ def results(self) -> Dict:
+ return self._results
+
+ @property
+ def assets(self) -> List:
+ return self._assets
+
+ def add_response(self, resp: Dict):
+ if self._response:
+ resp['previous'] = self._response
+ self._response = resp
+
+ def add_results(self, results: Dict):
+ self._results.update(results)
+ if 'response' in results:
+ self.add_response(results['response'])
+
+ def add_assets(self, assets: List):
+ self._assets.extend(assets)
Added: httpd/httpd/trunk/test/modules/http2/htdocs/alive.json
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/alive.json?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/alive.json (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/alive.json Fri Aug 20 16:07:44 2021
@@ -0,0 +1,4 @@
+{
+ "host" : "generic",
+ "alive" : true
+}
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echo.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echo.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echo.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echo.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+import sys, cgi, os
+
+status = '200 Ok'
+
+content = ''
+for line in sys.stdin:
+ content += line
+
+# Just echo what we get
+print("Status: 200")
+print("Content-Type: application/data\n")
+sys.stdout.write(content)
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+form = cgi.FieldStorage()
+name = form.getvalue('name')
+
+if name:
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+ print("""%s: %s""" % (name, os.environ['HTTP_'+name]))
+else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+<html><body>
+<p>No name was specified</p>
+</body></html>""")
+
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+ input = form['name']
+
+ # Test if the file was uploaded
+ if input.value is not None:
+ val = os.environ[input.value] if input.value in os.environ else ""
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+ print("{0}={1}".format(input.value, val))
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No name was specified: %s</p>
+ </body></html>""" % (count.value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="name">
+ <button type="submit">submit</button></form>
+ </body></html>""")
+ pass
+
+
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/files/empty.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/files/empty.txt?rev=1892476&view=auto
==============================================================================
(empty)
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+
+ # A nested FieldStorage instance holds the file
+ name = form['name'].value
+ value = ''
+
+ try:
+ value = form['value'].value
+ except KeyError:
+ value = os.environ.get("HTTP_"+name, "unset")
+
+ # Test if a value was given
+ if name:
+ print("Status: 200")
+ print("%s: %s" % (name, value,))
+ print ("""\
+Content-Type: text/plain\n""")
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No name and value was specified: %s %s</p>
+ </body></html>""" % (name, value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="name">
+ <input type="text" name="value">
+ <button type="submit">Echo</button></form>
+ </body></html>""")
+ pass
+
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hello.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hello.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hello.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hello.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import os
+
+print("Content-Type: application/json")
+print()
+print("{")
+print(" \"https\" : \"%s\"," % (os.getenv('HTTPS', '')))
+print(" \"host\" : \"%s\"," % (os.getenv('SERVER_NAME', '')))
+print(" \"protocol\" : \"%s\"," % (os.getenv('SERVER_PROTOCOL', '')))
+print(" \"ssl_protocol\" : \"%s\"," % (os.getenv('SSL_PROTOCOL', '')))
+print(" \"h2\" : \"%s\"," % (os.getenv('HTTP2', '')))
+print(" \"h2push\" : \"%s\"" % (os.getenv('H2PUSH', '')))
+print("}")
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import cgi
+import cgitb; cgitb.enable()
+import os
+import sys
+
+try:
+ form = cgi.FieldStorage()
+ count = form['count'].value
+ text = form['text'].value
+except KeyError:
+ text="a"
+ count=77784
+
+
+print("Status: 200 OK")
+print("Content-Type: text/html")
+print()
+sys.stdout.write(text*int(count))
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+import cgi, os
+import time
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+ count = form['count']
+ text = form['text']
+
+ waitsec = float(form['wait1'].value) if 'wait1' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ if int(count.value):
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+
+ waitsec = float(form['wait2'].value) if 'wait2' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ i = 0;
+ for i in range(0, int(count.value)):
+ print("%s" % (text.value))
+
+ waitsec = float(form['wait3'].value) if 'wait3' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No count was specified: %s</p>
+ </body></html>""" % (count.value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="count">
+ <input type="text" name="text">
+ <button type="submit">Echo</button></form>
+ </body></html>""")
+ pass
+
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py Fri Aug 20 16:07:44 2021
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb
+cgitb.enable()
+
+status = '200 Ok'
+
+try: # Windows needs stdio set for binary mode.
+ import msvcrt
+ msvcrt.setmode (0, os.O_BINARY) # stdin = 0
+ msvcrt.setmode (1, os.O_BINARY) # stdout = 1
+except ImportError:
+ pass
+
+form = cgi.FieldStorage()
+
+# Test if the file was uploaded
+if 'file' in form:
+ fileitem = form['file']
+ # strip leading path from file name to avoid directory traversal attacks
+ fn = os.path.basename(fileitem.filename)
+ f = open(('%s/files/%s' % (os.environ["DOCUMENT_ROOT"], fn)), 'wb');
+ f.write(fileitem.file.read())
+ f.close()
+ message = "The file %s was uploaded successfully" % (fn)
+ print("Status: 201 Created")
+ print("Content-Type: text/html")
+ print("Location: %s://%s/files/%s" % (os.environ["REQUEST_SCHEME"], os.environ["HTTP_HOST"], fn))
+ print("")
+ print("<html><body><p>%s</p></body></html>" % (message))
+
+elif 'remove' in form:
+ remove = form['remove'].value
+ try:
+ fn = os.path.basename(remove)
+ os.remove('./files/' + fn)
+ message = 'The file "' + fn + '" was removed successfully'
+ except OSError as e:
+ message = 'Error removing ' + fn + ': ' + e.strerror
+ status = '404 File Not Found'
+ print("Status: %s" % (status))
+ print("""
+Content-Type: text/html
+
+<html><body>
+<p>%s</p>
+</body></html>""" % (message))
+
+else:
+ message = '''\
+ Upload File<form method="POST" enctype="multipart/form-data">
+ <input type="file" name="file">
+ <button type="submit">Upload</button></form>
+ '''
+ print("Status: %s" % (status))
+ print("""\
+Content-Type: text/html
+
+<html><body>
+<p>%s</p>
+</body></html>""" % (message))
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/forbidden.html
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/forbidden.html?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/forbidden.html (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/forbidden.html Fri Aug 20 16:07:44 2021
@@ -0,0 +1,11 @@
+<html>
+ <head>
+ <title>403 - Forbidden</title>
+ </head>
+ <body>
+ <h1>403 - Forbidden</h1>
+ <p>
+ An example of an error document.
+ </p>
+ </body>
+</html>
Added: httpd/httpd/trunk/test/modules/http2/htdocs/index.html
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/index.html?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/index.html (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/index.html Fri Aug 20 16:07:44 2021
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>mod_h2 test site generic</title>
+ </head>
+ <body>
+ <h1>mod_h2 test site generic</h1>
+ </body>
+</html>
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/noh2/alive.json
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/noh2/alive.json?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/noh2/alive.json (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/noh2/alive.json Fri Aug 20 16:07:44 2021
@@ -0,0 +1,5 @@
+{
+ "host" : "noh2",
+ "alive" : true
+}
+
Added: httpd/httpd/trunk/test/modules/http2/htdocs/noh2/index.html
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/noh2/index.html?rev=1892476&view=auto
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/noh2/index.html (added)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/noh2/index.html Fri Aug 20 16:07:44 2021
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>mod_h2 test site noh2</title>
+ </head>
+ <body>
+ <h1>mod_h2 test site noh2</h1>
+ </body>
+</html>
+