sxia-aviatrix commented on code in PR #13574: URL: https://github.com/apache/trafficserver/pull/13574#discussion_r3864934119
########## tests/gold_tests/slow_post/partial_post_client.py: ########## @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Send a partial POST to trigger the abort_tunnel code path. + +Sends POST headers claiming a large Content-Length but only sends a small +chunk of body data. When a request transform plugin is active, this causes +ATS to call abort_tunnel() while the transform entry is still in the vc_table. +""" + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import socket +import sys + + +def main() -> int: + """Run the client.""" + host = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1' + port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080 + + request = ( + 'POST / HTTP/1.1\r\n' + 'Host: quick.server.com\r\n' + 'Content-Type: application/octet-stream\r\n' + 'Content-Length: 100000\r\n' + '\r\n').encode() + + partial_body = b'x' * 4096 + + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(5) + try: + sock.connect((host, port)) + sock.sendall(request + partial_body) + print(f'Sent POST headers (Content-Length: 100000) + {len(partial_body)} bytes') + + try: + response = sock.recv(4096) + except ConnectionError: + # ATS may reset the connection after responding since the POST + # body is incomplete. This is acceptable — the important thing + # is that ATS did not crash. + print('HTTP/1.1 connection reset (expected for partial POST)') + return 0 Review Comment: I have updated the code ########## tests/gold_tests/slow_post/quick_server.test.py: ########## @@ -105,22 +116,30 @@ def run(self): http_utils = os.path.join(tools_dir, 'http_utils.py') tr.Setup.CopyAs(self._init_file, Test.RunDirectory) tr.Setup.CopyAs(http_utils, Test.RunDirectory) - tr.Setup.CopyAs(self._slow_post_client, Test.RunDirectory) tr.Setup.CopyAs(self._quick_server, Test.RunDirectory) - client_command = (f'{sys.executable} {self._slow_post_client} ' - '127.0.0.1 ' - f'{self._ts.Variables.port} ') - if not self._should_abort_request: - client_command += '--finish-request ' - p = tr.Processes.Default - p.Command = client_command - if self._should_abort_request or self._should_abort_response_headers: - p.Streams.All += Testers.ExcludesExpression('HTTP/1.1 200 OK', 'Verify response was received') + if self._use_request_transform: + tr.Setup.CopyAs(self._partial_post_client, Test.RunDirectory) + p = tr.Processes.Default + p.Command = (f'{sys.executable} {self._partial_post_client} ' + f'127.0.0.1 {self._ts.Variables.port}') + p.ReturnCode = 0 + p.Streams.All += Testers.ContainsExpression('HTTP/1.1', 'Verify client received an HTTP response') Review Comment: I have updated the code for this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
