source: mod_gnutls/test/https-test-client.py @ e3e0de1

asyncioproxy-ticket
Last change on this file since e3e0de1 was e3e0de1, checked in by Fiona Klute <fiona.klute@…>, 17 months ago

https-test-client.py: Make host and port configurable per connection

Both variables can use environment variables. If unset they default to
TEST_TARGET and TEST_PORT. This makes it possible to connect to
different servers in one test, for example in proxy tests to check
that the backend server is behaving as expected.

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/python3
2# PYTHON_ARGCOMPLETE_OK
3
4# Copyright 2019 Fiona Klute
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import os
19import yaml
20
21from mgstest.tests import TestConnection
22
23if __name__ == "__main__":
24    import argparse
25    parser = argparse.ArgumentParser(
26        description='Send HTTP requests through gnutls-cli',
27        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
28    parser.add_argument('host', nargs='?', default=None,
29                        help='Access this host. Overrides TEST_TARGET, '
30                        'but not the test configuration file.')
31    parser.add_argument('-p', '--port', default=None,
32                        help='Access this port. Overrides TEST_PORT, '
33                        'but not the test configuration file.')
34    parser.add_argument('--timeout', type=float,
35                        help='Timeout for HTTP requests', default='5.0')
36    parser.add_argument('--test-config', type=argparse.FileType('r'),
37                        required=True, help='load YAML test configuration')
38
39    # enable bash completion if argcomplete is available
40    try:
41        import argcomplete
42        argcomplete.autocomplete(parser)
43    except ImportError:
44        pass
45
46    args = parser.parse_args()
47
48    if args.host:
49        os.environ['TEST_TARGET'] = args.host
50    if args.port:
51        os.environ['TEST_PORT'] = args.port
52
53    conns = None
54
55    config = yaml.load(args.test_config, Loader=yaml.Loader)
56    if type(config) is TestConnection:
57        conns = [config]
58    elif type(config) is list:
59        # assume list elements are connections
60        conns = config
61    else:
62        raise TypeError(f'Unsupported configuration: {config!r}')
63    print(conns)
64
65    for test_conn in conns:
66        test_conn.run(timeout=args.timeout)
Note: See TracBrowser for help on using the repository browser.