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