source: mod_gnutls/test/tests/28_HTTP2_support/hooks.py

mod_gnutls/0.12.0
Last change on this file was 32e62a3, checked in by Fiona Klute <fiona.klute@…>, 10 months ago

Fix a flake8 warning

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import os
2import re
3import subprocess
4from mgstest import require_apache_modules, require_match
5from unittest import SkipTest
6
7
8def prepare_env():
9    require_apache_modules('mod_http2.so')
10    curl = os.environ['HTTP_CLI']
11    if curl == 'no':
12        raise SkipTest('curl not found!')
13    proc = subprocess.run([curl, '-V'], stdout=subprocess.PIPE,
14                          check=True, text=True)
15    if not re.search(r'\bHTTP2\b', proc.stdout):
16        raise SkipTest(f'{curl} does not support HTTP/2!')
17
18
19def run_connection(testname, conn_log, response_log):
20    """Check if HTTP/2 connections using mod_gnutls and mod_http2 work."""
21
22    url = f'https://{os.environ["TEST_HOST"]}:{os.environ["TEST_PORT"]}' \
23        '/status?auto'
24    command = [os.environ['HTTP_CLI'], '--http2', '--location', '--verbose',
25               '--cacert', 'authority/x509.pem', url]
26
27    proc = subprocess.run(command,
28                          stdout=subprocess.PIPE, stderr=subprocess.PIPE,
29                          text=True)
30    print(proc.stderr)
31    print(proc.stderr, file=conn_log)
32    print(proc.stdout)
33    print(proc.stdout, file=response_log)
34    proc.check_returncode()
35
36
37def post_check(conn_log, response_log):
38    print('Checking for HTTP/2 in logged header:')
39    print(require_match(re.compile(r'\bHTTP/2 200\b'), conn_log).group(0))
40    print('Checking for TLS session status:')
41    print(require_match(re.compile(r'^Current TLS session:\s\(TLS.*$'),
42                        response_log)
43          .group(0))
Note: See TracBrowser for help on using the repository browser.