Skip to content

Commit d958349

Browse files
committed
Arrange pytest to run with mod_ssl, still skipping some tests.
this closes #433 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1917039 13f79535-47bb-0310-9956-ffa450edef68
1 parent 906fd95 commit d958349

11 files changed

+180
-17
lines changed

test/modules/md/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def env(pytestconfig) -> MDTestEnv:
3939
@pytest.fixture(autouse=True, scope="package")
4040
def _md_package_scope(env):
4141
env.httpd_error_log.add_ignored_lognos([
42-
"AH10085" # There are no SSL certificates configured and no other module contributed any
42+
"AH10085", # There are no SSL certificates configured and no other module contributed any
43+
"AH10045", # No VirtualHost matches Managed Domain
44+
"AH10105", # MDomain does not match any VirtualHost with 'SSLEngine on'
4345
])
4446

4547

test/modules/tls/conf.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def __init__(self, env: HttpdTestEnv, extras: Dict[str, Any] = None):
1313

1414
def start_tls_vhost(self, domains: List[str], port=None, ssl_module=None):
1515
if ssl_module is None:
16-
ssl_module = 'mod_tls'
16+
if not self.env.has_shared_module("tls"):
17+
ssl_module = "mod_ssl"
18+
else:
19+
ssl_module = 'mod_tls'
1720
super().start_vhost(domains=domains, port=port, doc_root=f"htdocs/{domains[0]}", ssl_module=ssl_module)
1821

1922
def end_tls_vhost(self):
@@ -39,8 +42,12 @@ def add_md_vhosts(self, domains: List[str], port = None):
3942
f" MDCertificateKeyFile {pkey_file}",
4043
])
4144
self.add("</MDomain>")
45+
if self.env.has_shared_module("tls"):
46+
ssl_module= "mod_tls"
47+
else:
48+
ssl_module= "mod_ssl"
4249
super().add_vhost(domains=[domain], port=port, doc_root=f"htdocs/{domain}",
43-
with_ssl=True, with_certificates=False, ssl_module='mod_tls')
50+
with_ssl=True, with_certificates=False, ssl_module=ssl_module)
4451

4552
def add_md_base(self, domain: str):
4653
self.add([

test/modules/tls/env.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ def __init__(self, pytestconfig=None):
129129
]),
130130
CertificateSpec(name="user1", client=True, single_file=True),
131131
])
132-
self.add_httpd_log_modules(['tls'])
132+
if not HttpdTestEnv.has_shared_module("tls"):
133+
self.add_httpd_log_modules(['ssl'])
134+
else:
135+
self.add_httpd_log_modules(['tls'])
133136

134137

135138
def setup_httpd(self, setup: TlsTestSetup = None):

test/modules/tls/test_02_conf.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ def test_tls_02_conf_cert_listen_wrong(self, env):
6464
])
6565
def test_tls_02_conf_cert_listen_valid(self, env, listen: str):
6666
conf = TlsTestConf(env=env)
67-
conf.add("TLSEngine {listen}".format(listen=listen))
68-
conf.install()
69-
assert env.apache_restart() == 0
67+
if not env.has_shared_module("tls"):
68+
# Without cert/key openssl will complain
69+
conf.add("SSLEngine on");
70+
conf.install()
71+
assert env.apache_restart() == 1
72+
else:
73+
conf.add("TLSEngine {listen}".format(listen=listen))
74+
conf.install()
75+
assert env.apache_restart() == 0
7076

7177
def test_tls_02_conf_cert_listen_cert(self, env):
7278
domain = env.domain_a

test/modules/tls/test_06_ciphers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ def test_tls_06_ciphers_pref_unsupported(self, env):
181181
})
182182
conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b])
183183
conf.install()
184-
assert env.apache_restart() == 0
184+
if not conf.env.has_shared_module("tls"):
185+
assert env.apache_restart() != 0
186+
else:
187+
assert env.apache_restart() == 0
185188
#
186189
env.httpd_error_log.ignore_recent(
187190
lognos = [
@@ -204,4 +207,6 @@ def test_tls_06_ciphers_supp_unsupported(self, env):
204207
})
205208
conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b])
206209
conf.install()
210+
if not conf.env.has_shared_module("tls"):
211+
return
207212
assert env.apache_restart() == 0

test/modules/tls/test_08_vars.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def _class_scope(self, env):
2323
def test_tls_08_vars_root(self, env):
2424
# in domain_b root, the StdEnvVars is switch on
2525
exp_proto = "TLSv1.2"
26-
exp_cipher = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
26+
if env.has_shared_module("tls"):
27+
exp_cipher = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
28+
else:
29+
exp_cipher = "ECDHE-ECDSA-AES256-GCM-SHA384"
2730
options = [ '--tls-max', '1.2']
2831
r = env.tls_get(env.domain_b, "/vars.py", options=options)
2932
assert r.exit_code == 0, r.stderr
@@ -47,7 +50,12 @@ def test_tls_08_vars_root(self, env):
4750
def test_tls_08_vars_const(self, env, name: str, value: str):
4851
r = env.tls_get(env.domain_b, f"/vars.py?name={name}")
4952
assert r.exit_code == 0, r.stderr
50-
assert r.json == {name: value}, r.stdout
53+
if env.has_shared_module("tls"):
54+
assert r.json == {name: value}, r.stdout
55+
else:
56+
if name == "SSL_SECURE_RENEG":
57+
value = "true"
58+
assert r.json == {name: value}, r.stdout
5159

5260
@pytest.mark.parametrize("name, pattern", [
5361
("SSL_VERSION_INTERFACE", r'mod_tls/\d+\.\d+\.\d+'),
@@ -57,4 +65,11 @@ def test_tls_08_vars_match(self, env, name: str, pattern: str):
5765
r = env.tls_get(env.domain_b, f"/vars.py?name={name}")
5866
assert r.exit_code == 0, r.stderr
5967
assert name in r.json
60-
assert re.match(pattern, r.json[name]), r.json
68+
if env.has_shared_module("tls"):
69+
assert re.match(pattern, r.json[name]), r.json
70+
else:
71+
if name == "SSL_VERSION_INTERFACE":
72+
pattern = r'mod_ssl/\d+\.\d+\.\d+'
73+
else:
74+
pattern = r'OpenSSL/\d+\.\d+\.\d+'
75+
assert re.match(pattern, r.json[name]), r.json

test/modules/tls/test_14_proxy_ssl.py

+40-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
import pytest
33

44
from .conf import TlsTestConf
5+
from pyhttpd.env import HttpdTestEnv
56

67

78
class TestProxySSL:
89

910
@pytest.fixture(autouse=True, scope='class')
1011
def _class_scope(self, env):
1112
# add vhosts a+b and a ssl proxy from a to b
13+
if not HttpdTestEnv.has_shared_module("tls"):
14+
myoptions="SSLOptions +StdEnvVars"
15+
myssl="mod_ssl"
16+
else:
17+
myoptions="TLSOptions +StdEnvVars"
18+
myssl="mod_tls"
1219
conf = TlsTestConf(env=env, extras={
1320
'base': [
1421
"LogLevel proxy:trace1 proxy_http:trace1 ssl:trace1 proxy_http2:trace1",
@@ -33,10 +40,10 @@ def _class_scope(self, env):
3340
f'ProxyPass /proxy-ssl/ https://127.0.0.1:{env.https_port}/',
3441
f'ProxyPass /proxy-local/ https://localhost:{env.https_port}/',
3542
f'ProxyPass /proxy-h2-ssl/ h2://127.0.0.1:{env.https_port}/',
36-
"TLSOptions +StdEnvVars",
43+
myoptions,
3744
],
3845
})
39-
conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b])
46+
conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b], ssl_module=myssl)
4047
conf.install()
4148
assert env.apache_restart() == 0
4249

@@ -69,7 +76,24 @@ def test_tls_14_proxy_ssl_h2_get(self, env):
6976
("SSL_CIPHER_EXPORT", "false"),
7077
("SSL_CLIENT_VERIFY", "NONE"),
7178
])
79+
def test_tls_14_proxy_tsl_vars_const(self, env, name: str, value: str):
80+
if not HttpdTestEnv.has_shared_module("tls"):
81+
return
82+
r = env.tls_get(env.domain_b, f"/proxy-ssl/vars.py?name={name}")
83+
assert r.exit_code == 0, r.stderr
84+
assert r.json == {name: value}, r.stdout
85+
86+
@pytest.mark.parametrize("name, value", [
87+
("SERVER_NAME", "b.mod-tls.test"),
88+
("SSL_SESSION_RESUMED", "Initial"),
89+
("SSL_SECURE_RENEG", "true"),
90+
("SSL_COMPRESS_METHOD", "NULL"),
91+
("SSL_CIPHER_EXPORT", "false"),
92+
("SSL_CLIENT_VERIFY", "NONE"),
93+
])
7294
def test_tls_14_proxy_ssl_vars_const(self, env, name: str, value: str):
95+
if HttpdTestEnv.has_shared_module("tls"):
96+
return
7397
r = env.tls_get(env.domain_b, f"/proxy-ssl/vars.py?name={name}")
7498
assert r.exit_code == 0, r.stderr
7599
assert r.json == {name: value}, r.stdout
@@ -78,7 +102,21 @@ def test_tls_14_proxy_ssl_vars_const(self, env, name: str, value: str):
78102
("SSL_VERSION_INTERFACE", r'mod_tls/\d+\.\d+\.\d+'),
79103
("SSL_VERSION_LIBRARY", r'rustls-ffi/\d+\.\d+\.\d+/rustls/\d+\.\d+\.\d+'),
80104
])
105+
def test_tls_14_proxy_tsl_vars_match(self, env, name: str, pattern: str):
106+
if not HttpdTestEnv.has_shared_module("tls"):
107+
return
108+
r = env.tls_get(env.domain_b, f"/proxy-ssl/vars.py?name={name}")
109+
assert r.exit_code == 0, r.stderr
110+
assert name in r.json
111+
assert re.match(pattern, r.json[name]), r.json
112+
113+
@pytest.mark.parametrize("name, pattern", [
114+
("SSL_VERSION_INTERFACE", r'mod_ssl/\d+\.\d+\.\d+'),
115+
("SSL_VERSION_LIBRARY", r'OpenSSL/\d+\.\d+\.\d+'),
116+
])
81117
def test_tls_14_proxy_ssl_vars_match(self, env, name: str, pattern: str):
118+
if HttpdTestEnv.has_shared_module("tls"):
119+
return
82120
r = env.tls_get(env.domain_b, f"/proxy-ssl/vars.py?name={name}")
83121
assert r.exit_code == 0, r.stderr
84122
assert name in r.json

test/modules/tls/test_15_proxy_tls.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import pytest
44

55
from .conf import TlsTestConf
6+
from pyhttpd.env import HttpdTestEnv
67

8+
@pytest.mark.skipif(condition=not HttpdTestEnv.has_shared_module("tls"), reason="no mod_tls available")
79

810
class TestProxyTLS:
911

test/modules/tls/test_16_proxy_mixed.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import pytest
44

55
from .conf import TlsTestConf
6+
from pyhttpd.env import HttpdTestEnv
7+
8+
@pytest.mark.skipif(condition=not HttpdTestEnv.has_shared_module("tls"), reason="no mod_tls available")
69

710

811
class TestProxyMixed:

test/modules/tls/test_17_proxy_machine_cert.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import pytest
44

55
from .conf import TlsTestConf
6+
from pyhttpd.env import HttpdTestEnv
67

7-
8+
@pytest.mark.skipif(condition=not HttpdTestEnv.has_shared_module("tls"), reason="no mod_tls available")
89
class TestProxyMachineCert:
910

1011
@pytest.fixture(autouse=True, scope='class')

test/pyhttpd/conf.py

+84-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,96 @@ def __repr__(self):
2626
def install(self):
2727
self.env.install_test_conf(self._lines)
2828

29+
def replacetlsstr(self, line):
30+
l = line.replace("TLS_", "")
31+
l = l.replace("\n", " ")
32+
l = l.replace("\\", " ")
33+
l = " ".join(l.split())
34+
l = l.replace(" ", ":")
35+
l = l.replace("_", "-")
36+
l = l.replace("-WITH", "")
37+
l = l.replace("AES-", "AES")
38+
l = l.replace("POLY1305-SHA256", "POLY1305")
39+
return l
40+
41+
def replaceinstr(self, line):
42+
if line.startswith("TLSCiphersPrefer"):
43+
# the "TLS_" are changed into "".
44+
l = self.replacetlsstr(line)
45+
l = l.replace("TLSCiphersPrefer:", "SSLCipherSuite ")
46+
elif line.startswith("TLSCiphersSuppress"):
47+
# like SSLCipherSuite but with :!
48+
l = self.replacetlsstr(line)
49+
l = l.replace("TLSCiphersSuppress:", "SSLCipherSuite !")
50+
l = l.replace(":", ":!")
51+
elif line.startswith("TLSCertificate"):
52+
l = line.replace("TLSCertificate", "SSLCertificateFile")
53+
elif line.startswith("TLSProtocol"):
54+
# mod_ssl is different (+ no supported and 0x code have to be translated)
55+
l = line.replace("TLSProtocol", "SSLProtocol")
56+
l = l.replace("+", "")
57+
l = l.replace("default", "all")
58+
l = l.replace("0x0303", "1.2") # need to check 1.3 and 1.1
59+
elif line.startswith("SSLProtocol"):
60+
l = line # we have that in test/modules/tls/test_05_proto.py
61+
elif line.startswith("TLSHonorClientOrder"):
62+
# mod_ssl has SSLHonorCipherOrder on = use server off = use client.
63+
l = line.lower()
64+
if "on" in l:
65+
l = "SSLHonorCipherOrder off"
66+
else:
67+
l = "SSLHonorCipherOrder on"
68+
elif line.startswith("TLSEngine"):
69+
# In fact it should go in the corresponding VirtualHost... Not sure how to do that.
70+
l = "SSLEngine On"
71+
else:
72+
if line != "":
73+
l = line.replace("TLS", "SSL")
74+
else:
75+
l = line
76+
return l
77+
2978
def add(self, line: Any):
79+
# make we transform the TLS to SSL if we are using mod_ssl
3080
if isinstance(line, str):
81+
if not HttpdTestEnv.has_shared_module("tls"):
82+
line = self.replaceinstr(line)
3183
if self._indents > 0:
3284
line = f"{' ' * self._indents}{line}"
3385
self._lines.append(line)
3486
else:
35-
if self._indents > 0:
36-
line = [f"{' ' * self._indents}{l}" for l in line]
37-
self._lines.extend(line)
87+
if not HttpdTestEnv.has_shared_module("tls"):
88+
new = []
89+
previous = ""
90+
for l in line:
91+
if previous.startswith("SSLCipherSuite"):
92+
if l.startswith("TLSCiphersPrefer") or l.startswith("TLSCiphersSuppress"):
93+
# we need to merge it
94+
l = self.replaceinstr(l)
95+
l = l.replace("SSLCipherSuite ", ":")
96+
previous = previous + l
97+
continue
98+
else:
99+
if self._indents > 0:
100+
previous = f"{' ' * self._indents}{previous}"
101+
new.append(previous)
102+
previous = ""
103+
l = self.replaceinstr(l)
104+
if l.startswith("SSLCipherSuite"):
105+
previous = l
106+
continue
107+
if self._indents > 0:
108+
l = f"{' ' * self._indents}{l}"
109+
new.append(l)
110+
if previous != "":
111+
if self._indents > 0:
112+
previous = f"{' ' * self._indents}{previous}"
113+
new.append(previous)
114+
self._lines.extend(new)
115+
else:
116+
if self._indents > 0:
117+
line = [f"{' ' * self._indents}{l}" for l in line]
118+
self._lines.extend(line)
38119
return self
39120

40121
def add_certificate(self, cert_file, key_file, ssl_module=None):

0 commit comments

Comments
 (0)