Skip to content

Commit c400393

Browse files
committed
Arrange more tests.
1 parent 6de48da commit c400393

File tree

6 files changed

+126
-14
lines changed

6 files changed

+126
-14
lines changed

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/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_05_proto.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def test_tls_05_proto_close(self, env):
5050
def test_tls_05_proto_ssl_close(self, env):
5151
conf = TlsTestConf(env=env, extras={
5252
'base': "LogLevel ssl:debug",
53-
env.domain_a: "SSLProtocol TLSv1.3",
54-
env.domain_b: "SSLProtocol TLSv1.2",
53+
env.domain_a: "TLSProtocol TLSv1.3",
54+
env.domain_b: "TLSProtocol TLSv1.2",
5555
})
5656
for d in [env.domain_a, env.domain_b]:
5757
conf.add_vhost(domains=[d], port=env.https_port)

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/pyhttpd/conf.py

+82-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,94 @@ 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.3") # need to check 1.2 and 1.1
59+
elif line.startswith("TLSHonorClientOrder"):
60+
# mod_ssl has SSLHonorCipherOrder on = use server off = use client.
61+
l = line.lower()
62+
if "on" in l:
63+
l = "SSLHonorCipherOrder off"
64+
else:
65+
l = "SSLHonorCipherOrder on"
66+
elif line.startswith("TLSEngine"):
67+
# In fact it should go in the corresponding VirtualHost... Not sure how to do that.
68+
l = "SSLEngine On"
69+
else:
70+
if line != "":
71+
l = line.replace("TLS", "SSL")
72+
else:
73+
l = line
74+
return l
75+
2976
def add(self, line: Any):
77+
# make we transform the TLS to SSL if we are using mod_ssl
3078
if isinstance(line, str):
79+
if not HttpdTestEnv.has_shared_module("tls"):
80+
line = self.replaceinstr(line)
3181
if self._indents > 0:
3282
line = f"{' ' * self._indents}{line}"
3383
self._lines.append(line)
3484
else:
35-
if self._indents > 0:
36-
line = [f"{' ' * self._indents}{l}" for l in line]
37-
self._lines.extend(line)
85+
if not HttpdTestEnv.has_shared_module("tls"):
86+
new = []
87+
previous = ""
88+
for l in line:
89+
if previous.startswith("SSLCipherSuite"):
90+
if l.startswith("TLSCiphersPrefer") or l.startswith("TLSCiphersSuppress"):
91+
# we need to merge it
92+
l = self.replaceinstr(l)
93+
l = l.replace("SSLCipherSuite ", ":")
94+
previous = previous + l
95+
continue
96+
else:
97+
if self._indents > 0:
98+
previous = f"{' ' * self._indents}{previous}"
99+
new.append(previous)
100+
previous = ""
101+
l = self.replaceinstr(l)
102+
if l.startswith("SSLCipherSuite"):
103+
previous = l
104+
continue
105+
if self._indents > 0:
106+
l = f"{' ' * self._indents}{l}"
107+
new.append(l)
108+
if previous != "":
109+
if self._indents > 0:
110+
previous = f"{' ' * self._indents}{previous}"
111+
new.append(previous)
112+
self._lines.extend(new)
113+
else:
114+
if self._indents > 0:
115+
line = [f"{' ' * self._indents}{l}" for l in line]
116+
self._lines.extend(line)
38117
return self
39118

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

0 commit comments

Comments
 (0)