summaryrefslogtreecommitdiffstats
path: root/test/modules/tls/test_04_get.py
blob: 6944381307b5d33b175316f8be6dd4d6b297c7fe (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import time
from datetime import timedelta

import pytest

from .env import TlsTestEnv
from .conf import TlsTestConf


def mk_text_file(fpath: str, lines: int):
    t110 = 11 * "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")


class TestGet:

    @pytest.fixture(autouse=True, scope='class')
    def _class_scope(self, env):
        conf = TlsTestConf(env=env)
        conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b])
        conf.install()
        docs_a = os.path.join(env.server_docs_dir, env.domain_a)
        mk_text_file(os.path.join(docs_a, "1k.txt"), 8)
        mk_text_file(os.path.join(docs_a, "10k.txt"), 80)
        mk_text_file(os.path.join(docs_a, "100k.txt"), 800)
        mk_text_file(os.path.join(docs_a, "1m.txt"), 8000)
        mk_text_file(os.path.join(docs_a, "10m.txt"), 80000)
        assert env.apache_restart() == 0

    @pytest.mark.parametrize("fname, flen", [
        ("1k.txt", 1024),
        ("10k.txt", 10*1024),
        ("100k.txt", 100 * 1024),
        ("1m.txt", 1000 * 1024),
        ("10m.txt", 10000 * 1024),
    ])
    def test_tls_04_get(self, env, fname, flen):
        # do we see the correct json for the domain_a?
        docs_a = os.path.join(env.server_docs_dir, env.domain_a)
        r = env.tls_get(env.domain_a, "/{0}".format(fname))
        assert r.exit_code == 0
        assert len(r.stdout) == flen
        pref = os.path.join(docs_a, fname)
        pout = os.path.join(docs_a, "{0}.out".format(fname))
        with open(pout, 'w') as fd:
            fd.write(r.stdout)
        dr = env.run_diff(pref, pout)
        assert dr.exit_code == 0, "differences found:\n{0}".format(dr.stdout)

    @pytest.mark.parametrize("fname, flen", [
        ("1k.txt", 1024),
    ])
    def test_tls_04_double_get(self, env, fname, flen):
        # we'd like to check that we can do >1 requests on the same connection
        # however curl hides that from us, unless we analyze its verbose output
        docs_a = os.path.join(env.server_docs_dir, env.domain_a)
        r = env.tls_get(env.domain_a, no_stdout_list=True, paths=[
            "/{0}".format(fname),
            "/{0}".format(fname)
        ])
        assert r.exit_code == 0
        assert len(r.stdout) == 2*flen