Changeset 09774e2 in mod_gnutls
- Timestamp:
- Dec 19, 2019, 7:11:17 AM (3 years ago)
- Branches:
- asyncio, main, master, proxy-ticket
- Children:
- 006f91a
- Parents:
- 45b0a24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/mgstest/tests.py
r45b0a24 r09774e2 77 77 f'description={self.description!r})') 78 78 79 def run(self, timeout=5.0, conn_log=None ):79 def run(self, timeout=5.0, conn_log=None, response_log=None): 80 80 # note: "--logfile" option requires GnuTLS version >= 3.6.7 81 81 command = ['gnutls-cli', '--logfile=/dev/stderr'] … … 96 96 for act in self.actions: 97 97 if type(act) is TestRequest: 98 act.run(conn )98 act.run(conn, response_log) 99 99 elif type(act) is TestRaw10: 100 act.run(command, timeout )100 act.run(command, timeout, conn_log, response_log) 101 101 else: 102 102 raise TypeError(f'Unsupported action requested: {act!r}') … … 139 139 f'expect={self.expect!r})') 140 140 141 def run(self, conn ):141 def run(self, conn, response_log=None): 142 142 try: 143 143 conn.request(self.method, self.path, headers=self.headers) … … 153 153 raise err 154 154 body = resp.read().decode() 155 print(format_response(resp, body)) 155 log_str = format_response(resp, body) 156 print(log_str) 157 if response_log: 158 print(log_str, file=response_log) 156 159 self.check_response(resp, body) 157 160 … … 258 261 f'headers={self.headers!r}, expect={self.expect!r})') 259 262 260 def run(self, command, timeout=None ):263 def run(self, command, timeout=None, conn_log=None, response_log=None): 261 264 req = f'{self.method} {self.path} HTTP/1.0\r\n' 262 265 for name, value in self.headers.items(): 263 266 req = req + f'{name}: {value}\r\n' 264 267 req = req + f'\r\n' 265 proc = subprocess.Popen(command, stdout=subprocess.PIPE, 266 stdin=subprocess.PIPE, close_fds=True, 268 proc = subprocess.Popen(command, 269 stdout=subprocess.PIPE, 270 stderr=subprocess.PIPE, 271 stdin=subprocess.PIPE, 272 close_fds=True, 267 273 bufsize=0) 268 274 try: 269 # Note: errs will be empty because stderr is not captured270 275 outs, errs = proc.communicate(input=req.encode(), 271 276 timeout=timeout) … … 273 278 proc.kill() 274 279 outs, errs = proc.communicate() 280 281 if conn_log: 282 print(errs.decode(), file=conn_log) 275 283 276 284 # first line of the received data must be the status … … 280 288 # log response for debugging 281 289 print(f'{status}\n{headers}\n\n{body}') 290 if response_log: 291 print(f'{status}\n{headers}\n\n{body}', file=response_log) 282 292 283 293 m = self.status_re.match(status) … … 374 384 375 385 376 def run_test_conf(test_config, timeout=5.0, conn_log=None ):386 def run_test_conf(test_config, timeout=5.0, conn_log=None, response_log=None): 377 387 conns = None 378 388 … … 394 404 print(f'Running test connection {i}.') 395 405 sys.stdout.flush() 396 test_conn.run(timeout=timeout, conn_log=conn_log) 406 test_conn.run(timeout=timeout, conn_log=conn_log, 407 response_log=response_log)
Note: See TracChangeset
for help on using the changeset viewer.