|
36 | 36 | _ConnectTunnelConnection, |
37 | 37 | _DNSCacheTable, |
38 | 38 | ) |
| 39 | +from aiohttp.pytest_plugin import AiohttpClient, AiohttpServer |
39 | 40 | from aiohttp.resolver import ResolveResult |
40 | 41 | from aiohttp.test_utils import unused_port |
41 | 42 | from aiohttp.tracing import Trace |
@@ -2515,6 +2516,36 @@ async def test_start_tls_exception_with_ssl_shutdown_timeout_nonzero_pre_311( |
2515 | 2516 | underlying_transport.abort.assert_not_called() |
2516 | 2517 |
|
2517 | 2518 |
|
| 2519 | +async def test_start_tls_with_zero_total_timeout( |
| 2520 | + aiohttp_server: AiohttpServer, |
| 2521 | + aiohttp_client: AiohttpClient, |
| 2522 | + ssl_ctx: ssl.SSLContext, |
| 2523 | + client_ssl_ctx: ssl.SSLContext, |
| 2524 | +) -> None: |
| 2525 | + """Test that ClientTimeout(total=0) works with TLS connections. |
| 2526 | +
|
| 2527 | + Regression test for https://github.com/aio-libs/aiohttp/issues/11859 |
| 2528 | + When total=0 (meaning no timeout), ssl_handshake_timeout should receive |
| 2529 | + None instead of 0, as asyncio raises ValueError for 0. |
| 2530 | + """ |
| 2531 | + |
| 2532 | + async def handler(request: web.Request) -> web.Response: |
| 2533 | + return web.Response(text="ok") |
| 2534 | + |
| 2535 | + app = web.Application() |
| 2536 | + app.router.add_get("/", handler) |
| 2537 | + server = await aiohttp_server(app, ssl=ssl_ctx) |
| 2538 | + |
| 2539 | + connector = aiohttp.TCPConnector(ssl=client_ssl_ctx) |
| 2540 | + client = await aiohttp_client(server, connector=connector) |
| 2541 | + |
| 2542 | + # This used to raise ValueError: ssl_handshake_timeout should be a |
| 2543 | + # positive number, got 0 |
| 2544 | + async with client.get("/", timeout=ClientTimeout(total=0)) as resp: |
| 2545 | + assert resp.status == 200 |
| 2546 | + assert await resp.text() == "ok" |
| 2547 | + |
| 2548 | + |
2518 | 2549 | async def test_invalid_ssl_param() -> None: |
2519 | 2550 | with pytest.raises(TypeError): |
2520 | 2551 | aiohttp.TCPConnector(ssl=object()) # type: ignore[arg-type] |
|
0 commit comments