Changeset e3e0de1 in mod_gnutls for test/mgstest/tests.py


Ignore:
Timestamp:
Dec 7, 2019, 9:42:07 AM (12 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.