summaryrefslogtreecommitdiff
path: root/test/pyhttpd
diff options
context:
space:
mode:
authorStefan Eissing <icing@apache.org>2021-11-30 15:58:30 +0000
committerStefan Eissing <icing@apache.org>2021-11-30 15:58:30 +0000
commit5144278ddb267e2fda2b0e4ad96a1be4ef0b5d25 (patch)
treeb04f8e1fa1ae2ba6f5dfa1a46a26284735ba2595 /test/pyhttpd
parent7fd23f82ab33d45a43eef879e87f4b40d6c37d89 (diff)
downloadhttpd-5144278ddb267e2fda2b0e4ad96a1be4ef0b5d25.tar.gz
* test: allow more flexibility in the ssl modules used
for a vhost. Adjust http2 and md test cases for working with modules other than mod_ssl. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1895429 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/pyhttpd')
-rw-r--r--test/pyhttpd/conf.py46
-rw-r--r--test/pyhttpd/env.py13
2 files changed, 42 insertions, 17 deletions
diff --git a/test/pyhttpd/conf.py b/test/pyhttpd/conf.py
index 3fefffaa8c..a2eeab9bfe 100644
--- a/test/pyhttpd/conf.py
+++ b/test/pyhttpd/conf.py
@@ -17,6 +17,7 @@ class HttpdConf(object):
self._extras = extras.copy() if extras else {}
if 'base' in self._extras:
self.add(self._extras['base'])
+ self._tls_engine_ports = set()
def __repr__(self):
s = '\n'.join(self._lines)
@@ -36,29 +37,45 @@ class HttpdConf(object):
self._lines.extend(line)
return self
- def add_certificate(self, cert_file, key_file):
- if self.env.ssl_module == "ssl":
+ def add_certificate(self, cert_file, key_file, ssl_module=None):
+ if ssl_module is None:
+ ssl_module = self.env.ssl_module
+ if ssl_module == 'mod_ssl':
self.add([
f"SSLCertificateFile {cert_file}",
f"SSLCertificateKeyFile {key_file if key_file else cert_file}",
])
- elif self.env.ssl_module == "tls":
- self.add(f"""
- TLSCertificate {cert_file} {key_file}
- """)
+ elif ssl_module == 'mod_tls':
+ self.add(f"TLSCertificate {cert_file} {key_file if key_file else ''}")
+ elif ssl_module == 'mod_gnutls':
+ self.add([
+ f"GnuTLSCertificateFile {cert_file}",
+ f"GnuTLSKeyFile {key_file if key_file else cert_file}",
+ ])
+ else:
+ raise Exception(f"unsupported ssl module: {ssl_module}")
- def add_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=None):
- self.start_vhost(domains=domains, port=port, doc_root=doc_root, with_ssl=with_ssl)
+ def add_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=None,
+ with_certificates=None, ssl_module=None):
+ self.start_vhost(domains=domains, port=port, doc_root=doc_root,
+ with_ssl=with_ssl, with_certificates=with_certificates,
+ ssl_module=ssl_module)
self.end_vhost()
return self
- def start_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=None):
+ def start_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=None,
+ ssl_module=None, with_certificates=None):
if not isinstance(domains, list):
domains = [domains]
if port is None:
port = self.env.https_port
+ if ssl_module is None:
+ ssl_module = self.env.ssl_module
if with_ssl is None:
- with_ssl = (self.env.https_port == port)
+ with_ssl = self.env.https_port == port
+ if with_ssl and ssl_module == 'mod_tls' and port not in self._tls_engine_ports:
+ self.add(f"TLSEngine {port}")
+ self._tls_engine_ports.add(port)
self.add("")
self.add(f"<VirtualHost *:{port}>")
self._indents += 1
@@ -67,10 +84,13 @@ class HttpdConf(object):
self.add(f"ServerAlias {alias}")
self.add(f"DocumentRoot {doc_root}")
if with_ssl:
- if self.env.ssl_module == "ssl":
+ if ssl_module == 'mod_ssl':
self.add("SSLEngine on")
- for cred in self.env.get_credentials_for_name(domains[0]):
- self.add_certificate(cred.cert_file, cred.pkey_file)
+ elif ssl_module == 'mod_gnutls':
+ self.add("GnuTLSEnable on")
+ if with_certificates is not False:
+ for cred in self.env.get_credentials_for_name(domains[0]):
+ self.add_certificate(cred.cert_file, cred.pkey_file, ssl_module=ssl_module)
if domains[0] in self._extras:
self.add(self._extras[domains[0]])
return self
diff --git a/test/pyhttpd/env.py b/test/pyhttpd/env.py
index 73044ae40b..be28e99790 100644
--- a/test/pyhttpd/env.py
+++ b/test/pyhttpd/env.py
@@ -72,9 +72,7 @@ class HttpdTestSetup:
self._source_dirs.append(source_dir)
def add_modules(self, modules: List[str]):
- for m in modules:
- if m not in self._modules:
- self._modules.append(m)
+ self._modules.extend(modules)
def make(self):
self._make_dirs()
@@ -122,11 +120,17 @@ class HttpdTestSetup:
fd.write(t.substitute(var_map))
def _make_modules_conf(self):
+ loaded = set()
modules_conf = os.path.join(self.env.server_dir, 'conf/modules.conf')
with open(modules_conf, 'w') as fd:
# issue load directives for all modules we want that are shared
missing_mods = list()
for m in self._modules:
+ match = re.match(r'^mod_(.+)$', m)
+ if match:
+ m = match.group(1)
+ if m in loaded:
+ continue
mod_path = os.path.join(self.env.libexec_dir, f"mod_{m}.so")
if os.path.isfile(mod_path):
fd.write(f"LoadModule {m}_module \"{mod_path}\"\n")
@@ -134,6 +138,7 @@ class HttpdTestSetup:
fd.write(f"#built static: LoadModule {m}_module \"{mod_path}\"\n")
else:
missing_mods.append(m)
+ loaded.add(m)
if len(missing_mods) > 0:
raise Exception(f"Unable to find modules: {missing_mods} "
f"DSOs: {self.env.dso_modules}")
@@ -162,7 +167,7 @@ class HttpdTestEnv:
@classmethod
def get_ssl_module(cls):
- return os.environ['SSL'] if 'SSL' in os.environ else 'ssl'
+ return os.environ['SSL'] if 'SSL' in os.environ else 'mod_ssl'
def __init__(self, pytestconfig=None):
self._our_dir = os.path.dirname(inspect.getfile(Dummy))