Skip to content

Commit

Permalink
* test: latest revision from svn trunk
Browse files Browse the repository at this point in the history
 * Makefile.am: cleanup of test dist files
  • Loading branch information
Stefan Eissing committed Nov 17, 2021
1 parent 7baa03a commit b975761
Show file tree
Hide file tree
Showing 32 changed files with 272 additions and 179 deletions.
9 changes: 2 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ EXTRA_DIST = \
test/unit \
test/Makefile.in \
test/Makefile.am \
test/mod_h2test/mod_h2test.c \
test/mod_h2test/mod_h2test.h \
test/conf \
test/data \
test/htdocs \
test/*.py \
test/*.ini.in
test/modules \
test/pyhttpd


dist_doc_DATA = README README.md LICENSE
Expand Down
3 changes: 2 additions & 1 deletion test/modules/http2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def pytest_report_header(config, startdir):
env = H2TestEnv(setup_dirs=False)
env = H2TestEnv()
return f"mod_h2 [apache: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]"


Expand All @@ -36,6 +36,7 @@ def env(pytestconfig) -> H2TestEnv:
logging.getLogger('').addHandler(console)
logging.getLogger('').setLevel(level=level)
env = H2TestEnv(pytestconfig=pytestconfig)
env.setup_httpd()
env.apache_access_log_clear()
env.httpd_error_log.clear_log()
return env
Expand Down
64 changes: 32 additions & 32 deletions test/modules/http2/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ class H2TestSetup(HttpdTestSetup):

def __init__(self, env: 'HttpdTestEnv'):
super().__init__(env=env)
self.add_source_dir(os.path.dirname(inspect.getfile(H2TestSetup)))
self.add_modules(["http2", "proxy_http2", "cgid", "autoindex"])

def make(self):
super().make(add_modules=["http2", "proxy_http2"])
super().make()
self._add_h2test()
self._setup_data_1k_1m()

def _add_h2test(self):
local_dir = os.path.dirname(inspect.getfile(H2TestSetup))
p = subprocess.run([self.env.apxs, '-c', 'mod_h2test.c'],
capture_output=True,
cwd=os.path.join(self.env.local_dir, 'mod_h2test'))
cwd=os.path.join(local_dir, 'mod_h2test'))
rv = p.returncode
if rv != 0:
log.error(f"compiling md_h2test failed: {p.stderr}")
Expand All @@ -33,20 +37,34 @@ def _add_h2test(self):
modules_conf = os.path.join(self.env.server_dir, 'conf/modules.conf')
with open(modules_conf, 'a') as fd:
# load our test module which is not installed
fd.write(f"LoadModule h2test_module \"{self.env.local_dir}/mod_h2test/.libs/mod_h2test.so\"\n")
fd.write(f"LoadModule h2test_module \"{local_dir}/mod_h2test/.libs/mod_h2test.so\"\n")

def _setup_data_1k_1m(self):
s90 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n"
with open(os.path.join(self.env.gen_dir, "data-1k"), 'w') as f:
for i in range(10):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.env.gen_dir, "data-10k"), 'w') as f:
for i in range(100):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.env.gen_dir, "data-100k"), 'w') as f:
for i in range(1000):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.env.gen_dir, "data-1m"), 'w') as f:
for i in range(10000):
f.write(f"{i:09d}-{s90}")


class H2TestEnv(HttpdTestEnv):

def __init__(self, pytestconfig=None, setup_dirs=True):
super().__init__(pytestconfig=pytestconfig,
local_dir=os.path.dirname(inspect.getfile(H2TestEnv)),
add_base_conf=[
def __init__(self, pytestconfig=None):
super().__init__(pytestconfig=pytestconfig)
self.add_httpd_conf([
"H2MinWorkers 1",
"H2MaxWorkers 64",
"Protocols h2 http/1.1 h2c",
],
interesting_modules=["http2", "proxy_http2", "h2test"])
])
self.add_httpd_log_modules(["http2", "proxy_http2", "h2test"])
self.add_cert_specs([
CertificateSpec(domains=[
f"push.{self._http_tld}",
Expand All @@ -70,29 +88,12 @@ def __init__(self, pytestconfig=None, setup_dirs=True):
])
self.httpd_error_log.add_ignored_patterns([
re.compile(r'.*malformed header from script \'hecho.py\': Bad header: x.*'),
re.compile(r'.*:tls_post_process_client_hello:.*'),
re.compile(r'.*:tls_process_client_certificate:.*'),
])

if setup_dirs:
self._setup = H2TestSetup(env=self)
self._setup.make()
self.issue_certs()
self.setup_data_1k_1m()


def setup_data_1k_1m(self):
s90 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n"
with open(os.path.join(self.gen_dir, "data-1k"), 'w') as f:
for i in range(10):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.gen_dir, "data-10k"), 'w') as f:
for i in range(100):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.gen_dir, "data-100k"), 'w') as f:
for i in range(1000):
f.write(f"{i:09d}-{s90}")
with open(os.path.join(self.gen_dir, "data-1m"), 'w') as f:
for i in range(10000):
f.write(f"{i:09d}-{s90}")
def setup_httpd(self, setup: HttpdTestSetup = None):
super().setup_httpd(setup=H2TestSetup(env=self))


class H2Conf(HttpdConf):
Expand All @@ -105,7 +106,7 @@ def __init__(self, env: HttpdTestEnv, extras: Dict[str, Any] = None):
]
}))

def start_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=False):
def start_vhost(self, domains, port=None, doc_root="htdocs", with_ssl=None):
super().start_vhost(domains=domains, port=port, doc_root=doc_root, with_ssl=with_ssl)
if f"noh2.{self.env.http_tld}" in domains:
protos = ["http/1.1"]
Expand Down Expand Up @@ -133,4 +134,3 @@ def add_vhost_test1(self, proxy_self=False, h2proxy_self=False):

def add_vhost_test2(self):
return super().add_vhost_test2()

2 changes: 1 addition & 1 deletion test/modules/http2/test_001_httpd_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestBasicAlive:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_002_curl_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestCurlBasics:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
4 changes: 2 additions & 2 deletions test/modules/http2/test_003_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .env import H2Conf


class TestStore:
class TestGet:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_h2_003_20(self, env):
<title>Index of /006</title>
</head>
<body>
<title>My Header Title</title>
<h1>Index of /006</h1>
<ul><li><a href="/"> Parent Directory</a></li>
<li><a href="006.css"> 006.css</a></li>
<li><a href="006.js"> 006.js</a></li>
Expand Down
16 changes: 10 additions & 6 deletions test/modules/http2/test_004_post.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import difflib
import email.parser
import inspect
import json
import os
import re
Expand All @@ -10,14 +11,17 @@
from .env import H2Conf


class TestStore:
class TestPost:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
env.setup_data_1k_1m()
TestPost._local_dir = os.path.dirname(inspect.getfile(TestPost))
H2Conf(env).add_vhost_cgi().install()
assert env.apache_restart() == 0

def local_src(self, fname):
return os.path.join(TestPost._local_dir, fname)

# upload and GET again using curl, compare to original content
def curl_upload_and_verify(self, env, fname, options=None):
url = env.mkurl("https", "cgi", "/upload.py")
Expand All @@ -29,7 +33,7 @@ def curl_upload_and_verify(self, env, fname, options=None):
r2 = env.curl_get(r.response["header"]["location"])
assert r2.exit_code == 0
assert r2.response["status"] == 200
with open(env.local_src(fpath), mode='rb') as file:
with open(self.local_src(fpath), mode='rb') as file:
src = file.read()
assert src == r2.response["body"]

Expand Down Expand Up @@ -84,7 +88,7 @@ def nghttp_post_and_verify(self, env, fname, options=None):
assert r.exit_code == 0
assert r.response["status"] >= 200 and r.response["status"] < 300

with open(env.local_src(fpath), mode='rb') as file:
with open(self.local_src(fpath), mode='rb') as file:
src = file.read()
assert 'request-length' in r.response["header"]
assert int(r.response["header"]['request-length']) == len(src)
Expand Down Expand Up @@ -123,7 +127,7 @@ def nghttp_upload_and_verify(self, env, fname, options=None):
r2 = env.nghttp().get(r.response["header"]["location"])
assert r2.exit_code == 0
assert r2.response["status"] == 200
with open(env.local_src(fpath), mode='rb') as file:
with open(self.local_src(fpath), mode='rb') as file:
src = file.read()
assert src == r2.response["body"]

Expand Down Expand Up @@ -204,7 +208,7 @@ def post_and_verify(fname, options=None):
if fname == part.get_filename():
filepart = part
assert filepart
with open(env.local_src(fpath), mode='rb') as file:
with open(self.local_src(fpath), mode='rb') as file:
src = file.read()
assert src == filepart.get_payload(decode=True)

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_006_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestAssets:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_100_conn_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestConnReuse:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_101_ssl_reneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .env import H2Conf


class TestStore:
class TestSslRenegotiation:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_102_require.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestRequire:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_103_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestUpgrade:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_104_padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def frame_padding(payload, padbits):
return ((payload + 9 + mask) & ~mask) - (payload + 9)


class TestStore:
class TestPadding:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_105_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyhttpd.curl import CurlPiper


class TestStore:
class TestTimeout:

# Check that base servers 'Timeout' setting is observed on SSL handshake
def test_h2_105_01(self, env):
Expand Down
7 changes: 5 additions & 2 deletions test/modules/http2/test_106_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def long_request():
assert env.apache_reload() == 0
t.join()
# noinspection PyTypeChecker
time.sleep(1)
r: ExecResult = self.r
assert r.response["status"] == 200
assert len(r.response["body"]) == (lines * (len(text)+1))
assert r.exit_code == 0
assert r.response, f"no response via {r.args} in {r.stderr}\nstdout: {len(r.stdout)} bytes"
assert r.response["status"] == 200, f"{r}"
assert len(r.response["body"]) == (lines * (len(text)+1)), f"{r}"
2 changes: 1 addition & 1 deletion test/modules/http2/test_200_header_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestInvalidHeaders:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_201_header_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestConditionalHeaders:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_202_trailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup_data(env):

# The trailer tests depend on "nghttp" as no other client seems to be able to send those
# rare things.
class TestStore:
class TestTrailers:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_300_interim.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .env import H2Conf


class TestStore:
class TestInterimResponses:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_400_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# The push tests depend on "nghttp"
class TestStore:
class TestPush:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http2/test_401_early_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


# The push tests depend on "nghttp"
class TestStore:
class TestEarlyHints:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
Expand Down
Loading

0 comments on commit b975761

Please sign in to comment.