| 1 | module http |
| 2 | |
| 3 | import net |
| 4 | import time |
| 5 | |
| 6 | fn test_tls_accept_timeouts_finite_handshake_for_infinite_accept() { |
| 7 | // An infinite accept timeout (<= 0, or net.infinite_timeout) must still |
| 8 | // yield a finite handshake timeout, so a client stalling mid-handshake |
| 9 | // cannot wedge the accept thread or block shutdown. |
| 10 | // net.infinite_timeout is i64.max (positive), so the > 0 guard alone is |
| 11 | // insufficient — mbedtls treats it as an infinite deadline. |
| 12 | accept_poll_timeout, handshake_timeout := tls_accept_timeouts(0, tls_handshake_timeout) |
| 13 | assert accept_poll_timeout == tls_accept_poll_timeout |
| 14 | assert handshake_timeout == tls_handshake_timeout |
| 15 | _, neg_handshake_timeout := tls_accept_timeouts(-1, tls_handshake_timeout) |
| 16 | assert neg_handshake_timeout == tls_handshake_timeout |
| 17 | _, inf_handshake_timeout := tls_accept_timeouts(net.infinite_timeout, tls_handshake_timeout) |
| 18 | assert inf_handshake_timeout == tls_handshake_timeout |
| 19 | } |
| 20 | |
| 21 | fn test_tls_accept_timeouts_cap_poll_without_changing_handshake_timeout() { |
| 22 | accept_poll_timeout, handshake_timeout := tls_accept_timeouts(time.second, |
| 23 | tls_handshake_timeout) |
| 24 | assert accept_poll_timeout == tls_accept_poll_timeout |
| 25 | assert handshake_timeout == time.second |
| 26 | } |
| 27 | |
| 28 | fn test_tls_accept_timeouts_keep_short_accept_timeout() { |
| 29 | accept_poll_timeout, handshake_timeout := tls_accept_timeouts(50 * time.millisecond, |
| 30 | tls_handshake_timeout) |
| 31 | assert accept_poll_timeout == 50 * time.millisecond |
| 32 | assert handshake_timeout == 50 * time.millisecond |
| 33 | } |
| 34 | |
| 35 | fn test_tls_accept_timeouts_configurable_fallback() { |
| 36 | // When accept_timeout is infinite, the handshake_fallback parameter |
| 37 | // (Server.tls_handshake_timeout) governs the budget — not the constant. |
| 38 | custom_fallback := 5 * time.second |
| 39 | _, handshake_timeout := tls_accept_timeouts(0, custom_fallback) |
| 40 | assert handshake_timeout == custom_fallback |
| 41 | } |
| 42 | |