|
| 1 | +''' |
| 2 | +Verify that tunnel active timeout produces ERR_TUN_ACTIVE_TIMEOUT squid code. |
| 3 | +''' |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 5 | +# or more contributor license agreements. See the NOTICE file |
| 6 | +# distributed with this work for additional information |
| 7 | +# regarding copyright ownership. The ASF licenses this file |
| 8 | +# to you under the Apache License, Version 2.0 (the |
| 9 | +# "License"); you may not use this file except in compliance |
| 10 | +# with the License. You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | + |
| 20 | +import os |
| 21 | +import sys |
| 22 | + |
| 23 | +Test.Summary = ''' |
| 24 | +Verify that tunnel active timeout produces ERR_TUN_ACTIVE_TIMEOUT squid code. |
| 25 | +''' |
| 26 | + |
| 27 | +ts = Test.MakeATSProcess("ts", enable_tls=True) |
| 28 | +server = Test.MakeOriginServer("server", ssl=True) |
| 29 | + |
| 30 | +# Simple response from origin |
| 31 | +request_header = {"headers": "GET / HTTP/1.1\r\nHost: server\r\n\r\n", "timestamp": "1234", "body": ""} |
| 32 | +response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1234", "body": "hello"} |
| 33 | +server.addResponse("sessionlog.json", request_header, response_header) |
| 34 | + |
| 35 | +ts.addDefaultSSLFiles() |
| 36 | + |
| 37 | +ts.Disk.ssl_multicert_config.AddLine('dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key') |
| 38 | + |
| 39 | +ts.Disk.records_config.update( |
| 40 | + { |
| 41 | + 'proxy.config.diags.debug.enabled': 1, |
| 42 | + 'proxy.config.diags.debug.tags': 'http|ssl|tunnel', |
| 43 | + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, |
| 44 | + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, |
| 45 | + 'proxy.config.ssl.client.verify.server.policy': 'PERMISSIVE', |
| 46 | + 'proxy.config.http.connect_ports': f'{server.Variables.SSL_Port}', |
| 47 | + # Set a short active timeout for tunnels (2 seconds) |
| 48 | + 'proxy.config.http.transaction_active_timeout_in': 2, |
| 49 | + # Force log flush every second for test reliability |
| 50 | + 'proxy.config.log.max_secs_per_buffer': 1, |
| 51 | + }) |
| 52 | + |
| 53 | +ts.Disk.remap_config.AddLine(f'map / https://127.0.0.1:{server.Variables.SSL_Port}') |
| 54 | + |
| 55 | +# Configure custom log format to capture squid code |
| 56 | +ts.Disk.logging_yaml.AddLines( |
| 57 | + ''' |
| 58 | +logging: |
| 59 | + formats: |
| 60 | + - name: custom |
| 61 | + format: '%<crc> %<pssc> %<cqhm>' |
| 62 | + logs: |
| 63 | + - filename: squid.log |
| 64 | + format: custom |
| 65 | +'''.split("\n")) |
| 66 | + |
| 67 | +# Test: Perform a CONNECT request that will time out |
| 68 | +tr = Test.AddTestRun("Tunnel active timeout test") |
| 69 | +tr.Processes.Default.StartBefore(server) |
| 70 | +tr.Processes.Default.StartBefore(ts) |
| 71 | + |
| 72 | +# Use the tunnel_timeout_client.py script to establish a CONNECT tunnel and then |
| 73 | +# just hold the connection until ATS times it out |
| 74 | +tr.Setup.Copy('tunnel_timeout_client.py') |
| 75 | + |
| 76 | +# Connect, establish tunnel, then sleep to trigger active timeout |
| 77 | +tr.Processes.Default.Command = ( |
| 78 | + f'{sys.executable} tunnel_timeout_client.py 127.0.0.1 {ts.Variables.port} ' |
| 79 | + f'127.0.0.1 {server.Variables.SSL_Port} 5') |
| 80 | +# The connection will be closed by ATS due to timeout |
| 81 | +tr.Processes.Default.ReturnCode = 0 |
| 82 | +tr.StillRunningAfter = ts |
| 83 | + |
| 84 | +# Wait for the access log to be written |
| 85 | +tr = Test.AddTestRun("Wait for the access log to write out") |
| 86 | +tr.DelayStart = 3 |
| 87 | +tr.StillRunningAfter = ts |
| 88 | +tr.Processes.Default.Command = 'echo "waiting for log flush"' |
| 89 | +tr.Processes.Default.ReturnCode = 0 |
| 90 | + |
| 91 | +# Verify the squid code in the access log |
| 92 | +ts.Disk.File(os.path.join(ts.Variables.LOGDIR, 'squid.log')).Content = Testers.ContainsExpression( |
| 93 | + 'ERR_TUN_ACTIVE_TIMEOUT.*CONNECT', 'Verify the tunnel timeout squid code is logged') |
0 commit comments