Changeset e3e0de1 in mod_gnutls


Ignore:
Timestamp:
Dec 7, 2019, 9:42:07 AM (3 years ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, main, master, proxy-ticket
Children:
8b72599
Parents:
09d923b
Message:

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.

Location:
test
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • test/https-test-client.py

    r09d923b re3e0de1  
    1616# limitations under the License.
    1717
     18import os
    1819import yaml
    1920
     
    2526        description='Send HTTP requests through gnutls-cli',
    2627        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    27     parser.add_argument('host', nargs='?', help='Access the specified host',
    28                         default='localhost')
    29     parser.add_argument('-p', '--port', type=int,
    30                         help='Access the specified port', default='8000')
     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.')
    3134    parser.add_argument('--timeout', type=float,
    3235                        help='Timeout for HTTP requests', default='5.0')
     
    4346    args = parser.parse_args()
    4447
     48    if args.host:
     49        os.environ['TEST_TARGET'] = args.host
     50    if args.port:
     51        os.environ['TEST_PORT'] = args.port
     52
    4553    conns = None
    4654
     
    5664
    5765    for test_conn in conns:
    58         test_conn.run(host=args.host, port=args.port, timeout=args.timeout)
     66        test_conn.run(timeout=args.timeout)
  • test/mgstest/tests.py

    r09d923b re3e0de1  
    2121"""
    2222
     23import os
    2324import re
    2425import subprocess
    2526import yaml
     27
     28from string import Template
    2629
    2730from . import TestExpectationFailed
     
    4245    yaml_tag = '!connection'
    4346
    44     def __init__(self, actions, gnutls_params=[], transport='gnutls'):
     47    def __init__(self, actions, host=None, port=None, gnutls_params=[],
     48                 transport='gnutls'):
    4549        self.gnutls_params = gnutls_params
    4650        self.actions = actions
    4751        self.transport = transport
     52        if host:
     53            self.host = subst_env(host)
     54        else:
     55            self.host = os.environ.get('TEST_TARGET', 'localhost')
     56        if port:
     57            self.port = int(subst_env(port))
     58        else:
     59            self.port = int(os.environ.get('TEST_PORT', 8000))
    4860
    4961    def __repr__(self):
    5062        return (f'{self.__class__.__name__!s}'
    51                 f'(gnutls_params={self.gnutls_params!r}, '
     63                f'(host={self.host!r}, port={self.port!r}, '
     64                f'gnutls_params={self.gnutls_params!r}, '
    5265                f'actions={self.actions!r}, transport={self.transport!r})')
    5366
    54     def run(self, host, port, timeout=5.0):
     67    def run(self, timeout=5.0):
    5568        # note: "--logfile" option requires GnuTLS version >= 3.6.7
    5669        command = ['gnutls-cli', '--logfile=/dev/stderr']
    5770        for s in self.gnutls_params:
    5871            command.append('--' + s)
    59         command = command + ['-p', str(port), host]
    60 
    61         conn = HTTPSubprocessConnection(command, host, port,
     72        command = command + ['-p', str(self.port), self.host]
     73
     74        conn = HTTPSubprocessConnection(command, self.host, self.port,
    6275                                        output_filter=filter_cert_log,
    6376                                        timeout=timeout)
     
    322335    s = s + '\n\n' + body
    323336    return s
     337
     338
     339
     340def subst_env(text):
     341    t = Template(text)
     342    return t.substitute(os.environ)
  • test/runtests

    r09d923b re3e0de1  
    191191
    192192if [ -n "${TARGET_IP}" ]; then
    193     TARGET="${TARGET_IP}"
    194 else
    195     TARGET="${TEST_HOST}"
    196 fi
    197 
    198 ${PYTHON} ${srcdir}/https-test-client.py -p "${TEST_PORT}" "${TARGET}" \
     193    export TEST_TARGET="${TARGET_IP}"
     194else
     195    export TEST_TARGET="${TEST_HOST}"
     196fi
     197
     198${PYTHON} ${srcdir}/https-test-client.py \
    199199          --test-config "${testdir}/test.yml" \
    200200          --timeout "${TEST_QUERY_TIMEOUT}" \
  • test/tests/21_TLS_reverse_proxy_wrong_cert/test.yml

    r09d923b re3e0de1  
    1 !connection
    2 gnutls_params:
    3   - x509cafile=authority/x509.pem
    4 actions:
    5   - !request
    6     path: /proxy/test.txt
    7     expect:
    8       status: 502
    9       body:
    10         contains:
    11           - 'Proxy Error'
    12           - 'Error reading from remote server'
     1# The reverse proxy can't access the backend (certificate validation
     2# fails)
     3- !connection
     4  gnutls_params:
     5    - x509cafile=authority/x509.pem
     6  actions:
     7    - !request
     8      path: /proxy/test.txt
     9      expect:
     10        status: 502
     11        body:
     12          contains:
     13            - 'Proxy Error'
     14            - 'Error reading from remote server'
     15
     16# Check if the proxy itself works correctly and presents the expected
     17# bad certificate
     18- !connection
     19  host: '${BACKEND_HOST}'
     20  port: '${BACKEND_PORT}'
     21  gnutls_params:
     22    - x509cafile=authority/x509.pem
     23    - verify-hostname=imposter.example
     24  actions:
     25    - !request
     26      path: /test.txt
     27      expect:
     28        status: 200
     29        body:
     30          exactly: |
     31            test
Note: See TracChangeset for help on using the changeset viewer.