Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c091a1e
Switch des3 encryption of keys to aes256. Switch generation of
minfrin Oct 31, 2026
0844ef8
Merge ff9f2cd0c3 from trunk (conflicts resolved in test/modules/sessi…
PaulLodge Nov 10, 2026
0b146ad
Add TLS 1.3 cipher and version tests (#803)
PaulLodge Nov 11, 2026
5e61b7a
Corrected file serial number and test naming (#1002)
PaulLodge Nov 13, 2026
3dd1abf
Merge f48aba8456 from trunk (conflicts resolved in test/modules/filte…
PaulLodge Nov 13, 2026
617b603
The tests verify RewriteCond/RewriteRule-based redirects: (#800)
PaulLodge Nov 11, 2026
4277c3a
Refactor the mod_rewite tests to the correct directory (#1021)
PaulLodge Nov 13, 2026
bc5ceab
* test/modules/ssl/test_005_vhost_compat.py (TestVhostCompatPolicy):
notroj Nov 13, 2026
ef3be4b
Merge 15181bb757 from trunk (test_108_goaway.py, test_09_hcheck_log_u…
notroj Nov 13, 2026
e6985fd
Add forward proxy long hostname tests (#845)
PaulLodge Nov 16, 2026
157755a
Add mod_cache_disk tests (#841)
PaulLodge Nov 16, 2026
a29edab
Merge 4c0de9e3e8 from trunk (conflicts resolved in test/modules/aaa/e…
notroj Nov 16, 2026
974c347
Merge 4e32ddc84f from trunk (conflicts resolved in test/modules/filte…
PaulLodge Nov 17, 2026
febb80e
Merge a3cb16677b from trunk (conflicts resolved in test/modules/proxy…
PaulLodge Nov 18, 2026
89ea590
Check that a malformed Digest header does not leak anything (#1094)
PaulLodge Nov 27, 2026
2d835e4
* test/modules/core/test_013_expr_proto_version.py: New test suite.
notroj Nov 8, 2026
37a196a
* test/modules/core/test_013_expr_proto_version.py: Mark as backported
notroj Nov 13, 2026
0e7762f
Merge 0956b89d16 from trunk (changes already on 2.4.x and test/module…
covener Nov 29, 2026
1fb3424
cache test: Cover an empty Content-Type and add mod_cache_socache tes…
PaulLodge Nov 30, 2026
04b9f07
Add DeflateAlterETag and mod_sed large input filter tests (#1102)
PaulLodge Nov 30, 2026
0584396
Metadata test: Cover malformed PROXY protocol headers (#1134)
PaulLodge Dec 1, 2026
d8f65fe
mod_md: Add regression test for requests without a Host header (#1144)
ichristod Dec 2, 2026
fcb2597
http2 test: Cover empty header values, client cancellation, throttled…
PaulLodge Dec 2, 2026
0a5af74
session test: Cover a cookie-name header override and session_crypto …
PaulLodge Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion test/modules/aaa/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import os
import sqlite3
from typing import List, Optional
from typing import Dict, List, Optional

from pyhttpd.env import HttpdTestEnv, HttpdTestSetup
from pyhttpd.result import ExecResult
Expand Down Expand Up @@ -104,6 +104,27 @@ def digest_pwfile(self) -> str:
def digest_pwfile2(self) -> str:
return self._digest_pwfile2

@staticmethod
def write_basic_pwfile(path: str, users: Dict[str, str]):
"""Write a Basic auth password file holding `users`, a dict of
user name to password, replacing the file atomically. The
passwords are stored as {SHA} hashes, which need no htpasswd."""
with open(path + ".tmp", 'w') as fd:
for user, password in users.items():
sha = base64.b64encode(
hashlib.sha1(password.encode()).digest()).decode()
fd.write(f"{user}:{{SHA}}{sha}\n")
os.replace(path + ".tmp", path)

def write_digest_pwfile(self, path: str, users: Dict[str, str]):
"""As write_basic_pwfile(), for a Digest password file in REALM."""
with open(path + ".tmp", 'w') as fd:
for user, password in users.items():
ha1 = hashlib.md5(
f"{user}:{self.REALM}:{password}".encode()).hexdigest()
fd.write(f"{user}:{self.REALM}:{ha1}\n")
os.replace(path + ".tmp", path)

@contextlib.contextmanager
def preserved_test_conf(self):
"""Put back the installed test configuration on exit and restart
Expand Down
437 changes: 437 additions & 0 deletions test/modules/aaa/test_016_authn_socache.py

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions test/modules/aaa/test_017_malformed_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""A malformed Digest Authorization header must leak nothing.

test_001 covers that a malformed header is rejected with a 401 and a
fresh (non-stale) challenge. These tests watch what the rejection path
itself emits: parsing a header with bogus fields must not read
uninitialized memory into the error log, and the challenge carried by
the response must stay printable ASCII rather than echo raw bytes back
at the client.
"""

from . import digest_client as dc
from .env import AAATestEnv


class TestMalformedHeader:

def url(self, env):
return env.mkurl("http", "aaa", "/digest/default/secret.txt")

def test_digest_170_no_leaked_fill_bytes_in_error_log(self, env):
# When httpd processes a malformed Digest header, no fill-pattern
# bytes (e.g. repeated 0x41 = 'A' from a valgrind malloc-fill)
# should appear in the error log, which would indicate
# uninitialized memory being read.
#
# Read the current end-of-log position, send the malformed
# request, then check the new lines for the fill pattern.
log_pos = env.httpd_error_log.current_pos()
malformed_auth = (
'Digest username, realm="' + AAATestEnv.REALM + '", '
'nonce=a, uri=/digest/default/secret.txt, '
'digest=a, cnonce=a, nonce_count=10, response=A'
)
r = env.curl_get(self.url(env),
options=["-H", f"Authorization: {malformed_auth}"])
assert r.response["status"] == 401
# Check the error log lines written since log_pos do not contain
# a run of 'A' characters that would indicate leaked
# uninitialized memory.
with open(env.httpd_error_log.path) as fd:
fd.seek(log_pos)
for line in fd:
assert "AAAA" not in line, \
f"possible uninitialized memory leak in error log: {line}"
env.httpd_error_log.ignore_recent(lognos=["AH01782"])

def test_digest_171_challenge_is_printable_ascii(self, env):
# After a malformed Authorization, the response headers must not
# contain raw or binary data outside the expected Digest challenge
# parameters.
malformed_auth = (
'Digest username="x", realm="wrong", '
'nonce="bad", uri="/digest/default/secret.txt", '
'response="' + ("41" * 16) + '", qop=auth, '
'nc=00000001, cnonce="test"'
)
r = env.curl_get(self.url(env),
options=["-H", f"Authorization: {malformed_auth}"])
assert r.response["status"] == 401
www_auth = r.response["header"]["www-authenticate"]
# The WWW-Authenticate value must start with "Digest " and contain
# only printable ASCII characters.
assert www_auth.startswith("Digest ")
assert all(32 <= ord(c) < 127 for c in www_auth), \
f"non-printable characters in WWW-Authenticate: {www_auth!r}"
env.httpd_error_log.ignore_recent(lognos=["AH01782", "AH01788",
"AH01776", "AH01794"])
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_001_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class TestSystemdNotify:
across the server lifecycle."""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
conf = HttpdConf(env)
conf.add_vhost_test1()
conf.install()
Expand Down
10 changes: 6 additions & 4 deletions test/modules/arch/linux/test_002_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class TestSystemdMonitor:
"systemctl status httpd" shows below the unit description."""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
conf = HttpdConf(env, extras={
'base': """
<Location "/server-status">
Expand All @@ -39,7 +40,8 @@ def wait_report(env, above=-1):
return MONITOR_STATUS.match(msg['STATUS'])

@pytest.fixture(scope='class')
def reports(self, env, _class_scope):
@classmethod
def reports(cls, env, _class_scope):
"""Two consecutive reports with requests served between them, and
the mod_status report as of the second.

Expand All @@ -48,11 +50,11 @@ def reports(self, env, _class_scope):
below share one pair rather than each waiting for its own.
"""
env.notify.clear()
first = self.wait_report(env)
first = cls.wait_report(env)
for _ in range(10):
r = env.curl_get(env.mkurl("http", "test1", "/"))
assert r.response['status'] == 200
second = self.wait_report(env, above=int(first.group('requests')))
second = cls.wait_report(env, above=int(first.group('requests')))
r = env.curl_get(env.mkurl("http", "test1", "/server-status?auto"))
assert r.response['status'] == 200
auto = {}
Expand Down
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_003_extended_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class TestSystemdExtendedStatus:
report, which changes what the rest of the server records too."""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
yield
conf = HttpdConf(env)
conf.add_vhost_test1()
Expand Down
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_004_socket_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class TestSystemdSocketActivation:
"""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
# The activated servers use the same server root; keep the one
# started by other tests out of the way.
assert env.apache_stop() == 0
Expand Down
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_005_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class TestSystemdService:
"""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
assert env.apache_stop() == 0
yield
assert env.apache_stop() == 0
Expand Down
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_006_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class TestSystemdWatchdog:
"""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
# These run their own servers on the second port; the shared one
# would only add its notifications to the same socket.
assert env.apache_stop() == 0
Expand Down
3 changes: 2 additions & 1 deletion test/modules/arch/linux/test_007_notify_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class TestNotifyReload:
"""

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, env):
assert env.apache_stop() == 0
yield
assert env.apache_stop() == 0
Expand Down
Empty file added test/modules/cache/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions test/modules/cache/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import logging
import os
import sys

import pytest

from .env import CacheTestEnv

sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))


def pytest_report_header(config, start_path):
env = CacheTestEnv()
return f"cache [apache: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]"


@pytest.fixture(scope="package")
def env(pytestconfig) -> CacheTestEnv:
logging.getLogger('').setLevel(level=logging.INFO)
env = CacheTestEnv(pytestconfig=pytestconfig)
env.setup_httpd()
env.apache_access_log_clear()
env.httpd_error_log.clear_log()
return env


@pytest.fixture(autouse=True, scope="package")
def _stop_package_scope(env):
yield
assert env.apache_stop() == 0
26 changes: 26 additions & 0 deletions test/modules/cache/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import inspect
import logging
import os

from pyhttpd.env import HttpdTestEnv, HttpdTestSetup

log = logging.getLogger(__name__)


class CacheTestSetup(HttpdTestSetup):

def __init__(self, env: 'HttpdTestEnv'):
super().__init__(env=env)
self.add_source_dir(os.path.dirname(inspect.getfile(CacheTestSetup)))
self.add_modules(["cache", "cache_disk", "cache_socache"])
self.add_cgi_module()


class CacheTestEnv(HttpdTestEnv):

def __init__(self, pytestconfig=None):
super().__init__(pytestconfig=pytestconfig)
self.add_httpd_log_modules(["cache", "cache_disk", "cache_socache"])

def setup_httpd(self, setup: HttpdTestSetup = None):
super().setup_httpd(setup=CacheTestSetup(env=self))
5 changes: 5 additions & 0 deletions test/modules/cache/htdocs/cgi/cache_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
import time
print("Content-Type: text/plain")
print()
print(f"time={time.time()}")
5 changes: 5 additions & 0 deletions test/modules/cache/htdocs/cgi/empty_ct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
import time
print("Content-Type:")
print()
print(f"time={time.time()}")
9 changes: 9 additions & 0 deletions test/modules/cache/htdocs/cgi/socache_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
import time
body = f"time={time.time()}\n"
print("Content-Type: text/plain")
print("Cache-Control: must-revalidate, max-age=10")
print("Vary: Accept-Encoding")
print(f"Content-Length: {len(body)}")
print()
print(body, end="")
93 changes: 93 additions & 0 deletions test/modules/cache/test_001_disk_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import re
import shutil
import time

import pytest

from pyhttpd.conf import HttpdConf


class TestDiskCache:

CACHE_EXPIRY = 4

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
cache_dir = os.path.join(env.gen_dir, "cache")
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)
os.makedirs(cache_dir, exist_ok=True)
conf = HttpdConf(env, extras={
f"cgi.{env.http_tld}": [
f'CacheEnable disk /cache_time.py',
f'CacheRoot "{cache_dir}"',
f'CacheDefaultExpire {TestDiskCache.CACHE_EXPIRY}',
f'CacheIgnoreNoLastMod On',
],
})
conf.add_vhost_cgi()
conf.install()
assert env.apache_restart() == 0

@staticmethod
def _get_timestamp(env):
url = env.mkurl("http", "cgi", "/cache_time.py")
r = env.curl_get(url)
assert r.response["status"] == 200
body = r.response["body"].decode("utf-8")
m = re.search(r"time=(\S+)", body)
assert m, f"Could not find time= in response body: {body}"
return float(m.group(1))

@staticmethod
def _clear_cache(env):
cache_dir = os.path.join(env.gen_dir, "cache")
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)
os.makedirs(cache_dir, exist_ok=True)

def test_cache_001_01(self, env):
"""Cache hit: second request within expiry returns the same timestamp."""
self._clear_cache(env)
ts1 = self._get_timestamp(env)
time.sleep(1)
ts2 = self._get_timestamp(env)
assert ts1 == ts2, (
f"Expected cached response with same timestamp, "
f"but got {ts1} and {ts2}"
)

def test_cache_001_02(self, env):
"""Cache expiry: request after expiry returns a new timestamp."""
self._clear_cache(env)
ts1 = self._get_timestamp(env)
time.sleep(TestDiskCache.CACHE_EXPIRY + 1)
ts2 = self._get_timestamp(env)
assert ts1 != ts2, (
f"Expected different timestamp after cache expiry, "
f"but both were {ts1}"
)

def test_cache_001_03(self, env):
"""Cache disabled: requests always return different timestamps."""
self._clear_cache(env)
conf = HttpdConf(env, extras={
f"cgi.{env.http_tld}": [
f'CacheEnable disk /cache_time.py',
f'CacheRoot "{env.gen_dir}/cache"',
f'CacheDefaultExpire {TestDiskCache.CACHE_EXPIRY}',
f'CacheIgnoreNoLastMod On',
f'CacheDisable /cache_time.py',
],
})
conf.add_vhost_cgi()
conf.install()
assert env.apache_restart() == 0
ts1 = self._get_timestamp(env)
time.sleep(1)
ts2 = self._get_timestamp(env)
assert ts1 != ts2, (
f"Expected different timestamps with cache disabled, "
f"but both were {ts1}"
)
Loading
Loading