blob: 7d7a4d355709b173d58a21671ab7f05a4ac932d2 [file]
# 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.
from pathlib import Path
import sys
from tools.uranium.services import (
ATS,
ATSFactory,
CommandResult,
OriginServer,
ProcessService,
ServiceFactory,
wait_for_file_lines,
)
TEST_DIRECTORY = Path(__file__).parent
def configure_origin(services: ServiceFactory) -> OriginServer:
"""Provide the TLS endpoint reached through the tunnel.
:param services: Factory owning support services and their cleanup.
"""
origin = services.origin("origin", ssl=True)
origin.add_response(
{"headers": "GET / HTTP/1.1\r\nHost: server\r\n\r\n", "body": ""},
{"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "body": "hello"},
)
return origin
def configure_ats(ats_factory: ATSFactory, *, _origin: OriginServer) -> ATS:
"""Allow the CONNECT target and configure a two-second active timeout.
:param _origin: Test-local origin configured by the test.
:param ats_factory: Factory for isolated Traffic Server instances.
"""
ats = ats_factory.create("ts", enable_tls=True)
ats.records.update(
{
"proxy.config.diags.debug.enabled": 1,
"proxy.config.diags.debug.tags": "http|ssl|tunnel",
"proxy.config.ssl.client.verify.server.policy": "PERMISSIVE",
"proxy.config.http.connect_ports": str(_origin.https_port),
"proxy.config.http.transaction_active_timeout_in": 2,
"proxy.config.log.max_secs_per_buffer": 1,
}
)
ats.remap_config.add_line(f"map / https://127.0.0.1:{_origin.https_port}")
ats.allow_private_connect()
ats.set_logging_yaml(
{
"logging": {
"formats": [{"name": "custom", "format": "%<crc> %<pssc> %<cqhm>"}],
"logs": [{"filename": "squid.log", "format": "custom"}],
}
}
)
return ats
def configure_client(services: ServiceFactory, *, _ats: ATS, _origin: OriginServer) -> ProcessService:
"""Establish the tunnel and leave it idle long enough to expire.
:param _ats: Test-local ats configured by the test.
:param _origin: Test-local origin configured by the test.
:param services: Factory owning support services and their cleanup.
"""
return services.process(
"client",
(
sys.executable,
TEST_DIRECTORY / "tunnel_timeout_client.py",
"127.0.0.1",
str(_ats.http_port),
"127.0.0.1",
str(_origin.https_port),
"5",
),
)
def verify_client(result: CommandResult) -> None:
"""Require the client to observe and tolerate the timeout closure.
:param result: Completed command result to validate.
"""
assert result.returncode == 0, result.output
def test_tunnel_active_timeout(ats_factory: ATSFactory, services: ServiceFactory) -> None:
"""Tunnel expiration is logged as ERR_TUN_ACTIVE_TIMEOUT.
:param ats_factory: Factory for isolated Traffic Server instances.
:param services: Factory owning support services and their cleanup.
"""
_origin = configure_origin(services)
_ats = configure_ats(ats_factory, _origin=_origin)
_client = configure_client(services, _ats=_ats, _origin=_origin)
_origin.start()
_ats.start()
verify_client(_client.run(timeout=15))
wait_for_file_lines(_ats.log_directory / "squid.log", r"ERR_TUN_ACTIVE_TIMEOUT.*CONNECT", 1, timeout=10)