File: test_09_timeout.py

package info (click to toggle)
apache2 2.4.62-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 59,516 kB
  • sloc: ansic: 216,122; python: 15,147; perl: 11,308; sh: 6,449; php: 1,315; javascript: 1,314; awk: 749; makefile: 714; lex: 374; yacc: 161; xml: 2
file content (43 lines) | stat: -rw-r--r-- 1,288 bytes parent folder | download
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
import socket
from datetime import timedelta

import pytest

from .conf import TlsTestConf


class TestTimeout:

    @pytest.fixture(autouse=True, scope='class')
    def _class_scope(self, env):
        conf = TlsTestConf(env=env, extras={
            'base': "RequestReadTimeout handshake=1",
        })
        conf.add_tls_vhosts(domains=[env.domain_a, env.domain_b])
        conf.install()
        assert env.apache_restart() == 0

    @pytest.fixture(autouse=True, scope='function')
    def _function_scope(self, env):
        pass

    def test_tls_09_timeout_handshake(self, env):
        # in domain_b root, the StdEnvVars is switch on
        s = socket.create_connection(('localhost', env.https_port))
        s.send(b'1234')
        s.settimeout(0.0)
        try:
            s.recv(1024)
            assert False, "able to recv() on a TLS connection before we sent a hello"
        except BlockingIOError:
            pass
        s.settimeout(3.0)
        try:
            while True:
                buf = s.recv(1024)
                if not buf:
                    break
                print("recv() -> {0}".format(buf))
        except (socket.timeout, BlockingIOError):
            assert False, "socket not closed as handshake timeout should trigger"
        s.close()