The test-tunnel runner infrastructure
test_tunnel.run_test
Provide a base class for running tunnel tests.
This module provides the TestTunnel
class to be used as a base class for implementing
test runners for various tunnel programs.
Its run()
method sets the test environment up, determines addresses and ports to use for
testing the connections, invokes an implementation-specific method to start the tunnel/proxy
server, and then loops over a predetermined set of connection addresses, again invoking
an implementation-specific method to prepare an established TCP connection for forwarding data.
The test_tunnel.cmd_test
sample modules may be used as a starting point for implementing
tool-specific test classes using TestTunnel
.
The test runner base class
test_tunnel.run_test.TestTunnel
Bases: ABC
Base class for running tunnel tests.
This class mainly provides the run()
method that determines some addresses and ports to
use for the connections, sets up a listener, and invokes implementation-specific methods to
start the tunnel/proxy server and prepare some TCP connections for forwarding data.
A tool-specific implementation must override at least the slug()
, do_spawn_server()
, and
do_handshake()
methods.
Source code in src/test_tunnel/run_test.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
cfg: defs.ConfigProg = cfg
instance-attribute
The tunnel proxy configuration.
__init__(cfg)
do_handshake(cli_sock, svc_listen)
abstractmethod
Perform the protocol-specific tunnel handshake.
Once the tunnel/proxy server has been started by do_spawn_server()
and a client
connection to it has been established by run()
, this method sends and receives
any data necessary for a "handshake" as required by the tunnel protocol, e.g.
negotiation and authentication for a SOCKS5 proxy, a CONNECT request for
an HTTP/HTTPS proxy, etc.
This method may optionally return the source address and port of the forwarded connection if it can be obtained from the tunnel protocol, e.g. SOCKS5 will sometimes return that information.
Source code in src/test_tunnel/run_test.py
do_spawn_server(proxy_listen, svc_listen)
abstractmethod
Spawn the tunnel-specific server process.
This method will most probably invoke an external program to start the implementation-specific tunnel/proxy server. It may also possibly create a configuration file in a temporary directory before running the program itself.
It must return a process instance that the run()
method may monitor and
wait for after completing the connection and data transfer tests.
Source code in src/test_tunnel/run_test.py
do_test_conn_connect(cli_sock, address, port)
Connect to the specified address/port.
This method is invoked internally by run()
to make sure that the tunnel/proxy
server started by the do_spawn_server()
method can at least accept TCP connections at
the addresses it should have been configured to listen on.
Source code in src/test_tunnel/run_test.py
do_test_conn_xfer(cli_sock, srv_sock, svc_listen)
Perform the protocol handshake and conversation.
Invoked internally by run()
, this method checks that a client connection to
the internal server can indeed be established via the tunnel/proxy server
(using the do_handshake()
method), and that it can indeed forward data in
both directions.
Source code in src/test_tunnel/run_test.py
expect_read(sock, expected, tag, *, compare_len=None)
Read some data, make sure it is as expected.
This method is used internally by run()
after establishing a TCP connection through
the tunnel/proxy server (and after the do_handshake()
method has set the connection up)
to make sure that the data sent along the connection is forwarded correctly.
If the compare_len
parameter is specified, only so many bytes at the start of
the response are compared; the rest is allowed to vary, although it must still have
the expected total length in bytes.
Source code in src/test_tunnel/run_test.py
run()
Gather addresses, group them in pairs, run tests.
This is the main entry point for instances of classes derived from TestTunnel
.
It uses the test_tunnel.addresses
module's routines to determine several
sets of addresses to use for a client connection, a proxy server, and an internal
server, and then uses the implementation-specific methods to start a tunnel/proxy
server, establish a client connection through it, and make sure that data can
flow both ways.
Source code in src/test_tunnel/run_test.py
slug()
abstractmethod
Provide a short string to identify the tested tunnel implementation.
The returned string is used in logging and diagnostic messages so that it is clear which tool is being tested.
Source code in src/test_tunnel/run_test.py
test_conn(proxy_listen, svc_listen)
Test the connectivity across a tunnel.