Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ server or MPM changes. On Unix, verify these pass locally by running
`make check-pytest PYTEST_DIRS=test/modules/xxx` — this can be done
without running `make install` first.

A module that only some tests in a package use goes in that package's
`add_optional_modules()`, not `add_modules()`, and those tests check
for it with `env.require(env.has_shared_module(...), ...)`. A module
listed in `add_modules()` that the build lacks stops setup with "Unable
to find modules", which fails every test in the package. See
`test/README.pytest` ("If your test needs a module").

`test/` is kept identical on trunk and 2.4.x (`test/check-test-sync.sh`),
so a new test reaches 2.4.x before the fix it tests. Any test that fails
without the trunk change must carry a `not_backported` mark from
Expand Down
28 changes: 24 additions & 4 deletions test/README.pytest
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ and cache the answer:
@H2TestEnv.needs_h2load("1.41.0")
@HttpdTestEnv.needs_multipart()

If your test needs a module, list it in the test package's
'*TestSetup' (its env.py). 'add_modules()' is for modules that
every test in the package needs: a build without one of them
stops setup with "Unable to find modules", so the whole package
fails. A module that only some of the tests use goes in
'add_optional_modules()', which loads it when it is there, and
the tests that use it check for it:

env.require(env.has_shared_module("proxy_fcgi"),
"mod_proxy_fcgi not available",
dep="mod_proxy_fcgi",
detected=f"no mod_proxy_fcgi.so in {env.libexec_dir}")

'has_shared_module()' is true for a module built as a DSO and for
one compiled into httpd. test/modules/proxy/test_13_fcgi_setenvif.py
is an example.

For a check that can only be made once the test is running,
'env.require()' does the same job from inside the body:

Expand Down Expand Up @@ -268,12 +285,15 @@ This directory is the same on trunk and on 2.4.x: a test is written on trunk,
then `test/` is copied to 2.4.x as it is, and `check-test-sync.sh` fails if
the two branches differ. A test covering a trunk change that 2.4.x does not
have yet carries a mark from `pyhttpd/backport.py` (or, in `pytest_suite/`,
`apache_pytest.not_backported`) naming the trunk revision:
`apache_pytest.not_backported`) naming the pull request that made the
change:

from pyhttpd.backport import not_backported, skip_not_backported

@not_backported("r1939033", "nonce-count validation")
def test_digest_001(self, env): ...
@not_backported("gh-1096", "mod_substitute empty matches")
def test_filters_010_01(self, env): ...

Older marks name svn revisions ("r1939033"), from before the move to git.

`not_backported` makes the test an expected failure on a server older than
2.5.0, `skip_not_backported` skips it where failing would hang or crash the
Expand All @@ -292,7 +312,7 @@ skipped, or failed under `--strict-optional`.

When the change is backported, add the 2.4.x release it first appears in:

@not_backported("r1939033", "nonce-count validation", backported_in="2.4.71")
@not_backported("gh-1096", "mod_substitute empty matches", backported_in="2.4.72")

on trunk, then copy `test/` to 2.4.x again. Older 2.4.x servers keep the
expectation. `platform="win32"` limits it to one `sys.platform`.
14 changes: 13 additions & 1 deletion test/modules/filters/test_010_substitute_empty_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from pyhttpd.backport import not_backported, skip_not_backported
from pyhttpd.conf import HttpdConf

# Patterns that can match the empty string must not loop forever (or until
Expand Down Expand Up @@ -33,6 +34,17 @@
'mixed_empty_nonempty': ('b*', '-', 'f', 'abbc', '-a--c-'),
}

# Without the change, most of these loop until "Line too long" is logged,
# and star_empty_* loop forever.
WHAT = "mod_substitute empty matches"
SKIP = skip_not_backported("gh-1096", WHAT, backported_in="2.4.72")
MARKS = {
'anchor_nonempty': not_backported("gh-1096", WHAT, backported_in="2.4.72"),
'lookbehind': (),
}
PARAMS = [pytest.param(name, id=name, marks=MARKS.get(name, SKIP))
for name in CASES]


class TestSubstituteEmptyMatch:

Expand All @@ -58,7 +70,7 @@ def configure(self, env, pattern, repl, flags):
conf.install()
assert env.apache_restart() == 0

@pytest.mark.parametrize("name", list(CASES), ids=list(CASES))
@pytest.mark.parametrize("name", PARAMS)
def test_filters_010_01(self, env, name):
pattern, repl, flags, _, expected = CASES[name]
self.configure(env, pattern, repl, flags)
Expand Down
5 changes: 5 additions & 0 deletions test/modules/metadata/test_006_expr_backref.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from pyhttpd.backport import skip_not_backported
from pyhttpd.conf import HttpdConf

# An expression that evaluates to true without evaluating a capturing regex
Expand All @@ -15,6 +16,10 @@
LONG = "long-" + "x" * 200


# Without r1915271 the Header edit* lines below crash every request, so
# none of the tests can run.
@skip_not_backported("r1915271", "mod_headers edit* recursion on empty matches",
backported_in="2.4.72")
class TestExprBackref:

@pytest.fixture(autouse=True, scope='class')
Expand Down
10 changes: 6 additions & 4 deletions test/modules/proxy/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ class ProxyTestSetup(HttpdTestSetup):
def __init__(self, env: 'HttpdTestEnv'):
super().__init__(env=env)
self.add_source_dir(os.path.dirname(inspect.getfile(ProxyTestSetup)))
self.add_modules(["proxy", "proxy_http", "proxy_ajp", "proxy_balancer",
"proxy_connect", "proxy_uwsgi", "proxy_fcgi",
"lbmethod_byrequests", "remoteip"])
self.add_optional_modules(["proxy_hcheck", "proxy_scgi"])
self.add_modules(["proxy", "proxy_http", "proxy_balancer",
"proxy_connect", "lbmethod_byrequests", "remoteip"])
# Modules only some tests use: a build without one skips those
# tests (env.require()) instead of failing setup for the package.
self.add_optional_modules(["proxy_hcheck", "proxy_scgi", "proxy_ajp",
"proxy_uwsgi", "proxy_fcgi"])


class ProxyTestEnv(HttpdTestEnv):
Expand Down
8 changes: 6 additions & 2 deletions test/modules/proxy/test_03_uwsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class TestProxyUwsgi:

@pytest.fixture(scope="class")
def _proxy_uwsgi_setup(self, env):
env.require(env.has_shared_module("proxy_uwsgi"), "mod_proxy_uwsgi not available",
dep="mod_proxy_uwsgi",
detected=f"no mod_proxy_uwsgi.so in {env.libexec_dir}")
faker = UwsgiFaker(port=UWSGI_PORT)
faker.start()

Expand All @@ -67,8 +70,9 @@ def _proxy_uwsgi_setup(self, env):

@pytest.fixture(scope='class')
def _class_scope(self, env):
if not env.has_shared_module("proxy_uwsgi"):
pytest.skip("mod_proxy_uwsgi not available")
env.require(env.has_shared_module("proxy_uwsgi"), "mod_proxy_uwsgi not available",
dep="mod_proxy_uwsgi",
detected=f"no mod_proxy_uwsgi.so in {env.libexec_dir}")
faker = _UWSGIFaker("127.0.0.1", env.http_port2)
faker.start()
conf = HttpdConf(env)
Expand Down
3 changes: 3 additions & 0 deletions test/modules/proxy/test_13_fcgi_setenvif.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from pyhttpd.backport import not_backported
from pyhttpd.conf import HttpdConf
from .fcgi_faker import FCGIFaker

Expand Down Expand Up @@ -46,6 +47,8 @@ def get_params(self, env, headers):
assert r.response["status"] == 200, r.response
return r.response["json"]

@not_backported("gh-1096", "ProxyFCGISetEnvIf backreferences without a capturing match",
backported_in="2.4.72")
def test_proxy_13_01_short_circuit(self, env):
params = self.get_params(env, {"X-Match": "skip", "X-Prev": "previous"})
assert params["PREV_CAPTURE"] == "<previous>"
Expand Down
9 changes: 6 additions & 3 deletions test/pyhttpd/backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
appears in, on trunk and copy the file over; older 2.4.x releases keep the
expectation.

pytestmark = not_backported("r1939033", "nonce-count validation")
pytestmark = not_backported("gh-1096", "mod_substitute empty matches")

@skip_not_backported("r1938487", "recursion limit in mod_sed",
backported_in="2.4.71")
@skip_not_backported("gh-1096", "mod_substitute empty matches",
backported_in="2.4.72")
def test_...

The first argument names the pull request that made the change ("gh-1096").
Older marks name svn revisions ("r1939033"), from before the move to git.

platform limits the expectation to one sys.platform, for a failure on 2.4.x
which trunk does not have there.

Expand Down
Loading