blob: ee653684ac01e9c22f7eb2ce6d28a51e237e5bf1 [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 re
import shutil
import pytest
from tools.uranium.services import ATS, ATSFactory, Curl, HttpBinServer, ServiceFactory, assert_matches_gold, wait_for_file_lines
TEST_DIRECTORY = Path(__file__).parent
def configure_httpbin(services: ServiceFactory) -> HttpBinServer:
"""Create the POST origin used by the protocol clients.
:param services: Factory owning support services and their cleanup.
"""
return services.httpbin("httpbin")
def configure_ats(ats_factory: ATSFactory, *, _enable_quic: bool, _httpbin: HttpBinServer) -> ATS:
"""Load the session-info plugin and enable TLS plus optional QUIC.
:param _enable_quic: Test-local enable quic configured by the test.
:param _httpbin: Test-local httpbin configured by the test.
:param ats_factory: Factory for isolated Traffic Server instances.
"""
ats = ats_factory.create("ts", enable_tls=True, enable_quic=_enable_quic)
ats.add_default_ssl_files()
ats.copy_custom_plugin("{AtsBuildUraniumTestsDir}/pluginTest/tsapi/.libs/test_TSHttpSsnInfo.so")
ats.plugin_config.add_line("test_TSHttpSsnInfo.so")
ats.set_environment("OUTPUT_FILE", str(ats.log_directory / "test_TSHttpSsnInfo_plugin_log.txt"))
ats.remap_config.add_line(f"map /httpbin/ http://127.0.0.1:{_httpbin.port}/")
ats.ssl_multicert_config.add_lines(
(
"ssl_multicert:",
' - dest_ip: "*"',
" ssl_cert_name: server.pem",
" ssl_key_name: server.key",
)
)
ats.records.update(
{
"proxy.config.diags.debug.enabled": 1,
"proxy.config.diags.debug.tags": "http2|http3|quic|test_TSHttpSsnInfo",
}
)
return ats
def test_test_TSHttpSsnInfo(ats_factory: ATSFactory, services: ServiceFactory, curl: Curl) -> None:
"""HTTP session APIs report the expected HTTP/2 frame metrics.
:param ats_factory: Factory for isolated Traffic Server instances.
:param services: Factory owning support services and their cleanup.
:param curl: Transport-aware curl command runner.
"""
_enable_quic = ats_factory.has_feature("TS_USE_QUIC") and curl.supports("http3")
_httpbin = configure_httpbin(services)
_ats = configure_ats(ats_factory, _enable_quic=_enable_quic, _httpbin=_httpbin)
_log = _ats.log_directory / "test_TSHttpSsnInfo_plugin_log.txt"
if shutil.which("nghttp") is None:
pytest.skip("nghttp is required")
post_body = _ats.run_directory / "post_body"
post_body.parent.mkdir(parents=True, exist_ok=True)
post_body.write_text("0123456789abcdef" * 8)
_httpbin.start()
_ats.start()
h2 = _ats.run_shell(
f"nghttp -vn --continuation 'https://localhost:{_ats.https_port}/httpbin/post' "
f"-d '{post_body.name}' | grep -v 'continuation-test'",
timeout=10,
)
assert h2.returncode == 0, h2.output
assert_matches_gold(h2.stdout, TEST_DIRECTORY / "test_TSHttpSsnInfo_nghttp0.gold")
if _enable_quic:
# HTTP/3 needs the QUIC listener, which the clear-text Unix socket cannot
# stand in for, so this request uses curl.run even in the curl UDS mode.
h3 = curl.run(
f"--insecure --http3 --data post_body 'https://localhost:{_ats.https_port}/httpbin/post'",
)
assert h3.returncode == 0, h3.output
assert_matches_gold(h3.stdout, TEST_DIRECTORY / "test_TSHttpSsnInfo_curl0.gold")
log = wait_for_file_lines(_log, "H2 Frames Received:", 1)
expected_frames = r"H2 Frames Received:D1,H1,PR\d+,RS0,S2,PP0,P0,G1,WU0,C1,U0"
assert re.search(expected_frames, log), log
assert "H2 OOB(11)=0,OOB(1000)=0" in log
assert_matches_gold(log, TEST_DIRECTORY / "test_TSHttpSsnInfo_plugin_log.gold")