summaryrefslogtreecommitdiff
path: root/test/modules/http2/test_107_frame_lengths.py
blob: d6360939bea0a0516ed7730a4d156d34f26047af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import pytest

from .env import H2Conf, H2TestEnv


def mk_text_file(fpath: str, lines: int):
    t110 = ""
    for _ in range(11):
        t110 += "0123456789"
    with open(fpath, "w") as fd:
        for i in range(lines):
            fd.write("{0:015d}: ".format(i))  # total 128 bytes per line
            fd.write(t110)
            fd.write("\n")


@pytest.mark.skipif(condition=H2TestEnv.is_unsupported, reason="mod_http2 not supported here")
class TestFrameLengths:

    URI_PATHS = []

    @pytest.fixture(autouse=True, scope='class')
    def _class_scope(self, env):
        docs_a = os.path.join(env.server_docs_dir, "cgi/files")
        for fsize in [10, 100]:
            fname = f'0-{fsize}k.txt'
            mk_text_file(os.path.join(docs_a, fname), 8 * fsize)
            self.URI_PATHS.append(f"/files/{fname}")

    @pytest.mark.parametrize("data_frame_len", [
        99, 1024, 8192
    ])
    def test_h2_107_01(self, env, data_frame_len):
        conf = H2Conf(env, extras={
            f'cgi.{env.http_tld}': [
                f'H2MaxDataFrameLen {data_frame_len}',
            ]
        })
        conf.add_vhost_cgi()
        conf.install()
        assert env.apache_restart() == 0
        for p in self.URI_PATHS:
            url = env.mkurl("https", "cgi", p)
            r = env.nghttp().get(url, options=[
                '--header=Accept-Encoding: none',
            ])
            assert r.response["status"] == 200
            assert len(r.results["data_lengths"]) > 0, f'{r}'
            too_large = [ x for x in r.results["data_lengths"] if x > data_frame_len]
            assert len(too_large) == 0, f'{p}: {r.results["data_lengths"]}'