From f3b47f7da59e26ab8aa17defe56b77954b21a6a3 Mon Sep 17 00:00:00 2001 From: Zach Kelling Date: Fri, 6 Nov 2026 17:18:39 -0800 Subject: [PATCH] test(auth): ask a reopened port, do not count it finish_answers_the_tab_and_its_retry_then_closes_the_port asserted that a connect to the freed loopback port is refused. The kernel hands that port out again and the binary's other tests bind loopback ports in parallel, so it failed on main (run 42322666479) with nothing wrong in finish. A connection that opens is now asked, and must not be answered with the signed-in page. Co-authored-by: Hanzo Dev --- src/iam/oauth.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/iam/oauth.rs b/src/iam/oauth.rs index 422f4d42a..3559f7ffb 100644 --- a/src/iam/oauth.rs +++ b/src/iam/oauth.rs @@ -1613,7 +1613,25 @@ mod tests { go.send(()).unwrap(); assert_eq!(finished.await.unwrap().unwrap(), 7); - assert!(TcpStream::connect(addr).await.is_err(), "the port stayed open"); + // Closed means nothing here answers any more. The freed port is the + // kernel's to hand out again, and the other tests of this binary bind + // loopback ports in parallel, so a connection that opens is asked + // rather than counted: one of theirs never serves this page. + if let Ok(mut late) = TcpStream::connect(addr).await { + let _ = late + .write_all(b"GET /callback?code=abc&state=xyz HTTP/1.1\r\nHost: localhost\r\n\r\n") + .await; + let mut answer = Vec::new(); + let _ = tokio::time::timeout( + std::time::Duration::from_millis(500), + late.read_to_end(&mut answer), + ) + .await; + assert!( + !String::from_utf8_lossy(&answer).contains("You're signed in"), + "the port stayed open" + ); + } } /// RP-Initiated Logout through the CLI's own client: the loopback and state