Skip to content

Commit 65099a9

Browse files
test(dgw): assert missing krb_kdc never dials the target
Checkout-before-connect on the stack below lets the fail-closed path prove accepted==0. Issue: DGW-1900 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 19dd8f5 commit 65099a9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎testsuite/tests/cli/dgw/cred_injection_kdc.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,12 @@ async fn kerberos_missing_krb_kdc_fails_closed() -> anyhow::Result<()> {
12591259
!logs.contains(FORWARD_LOG) && !logs.contains(INJECT_LOG),
12601260
"missing krb_kdc must fail closed; logs:\n{logs}"
12611261
);
1262+
tokio::time::sleep(Duration::from_millis(250)).await;
1263+
anyhow::ensure!(
1264+
rdp.accepted() == 0,
1265+
"missing krb_kdc must not dial the target; accepted={}",
1266+
rdp.accepted()
1267+
);
12621268
let _ = gateway.process.start_kill();
12631269
Ok(())
12641270
}
@@ -1303,20 +1309,28 @@ async fn ntlm_injection_completes_credssp_both_legs() -> anyhow::Result<()> {
13031309

13041310
struct FakeClosedTarget {
13051311
port: u16,
1312+
accepted: Arc<AtomicUsize>,
13061313
}
13071314

13081315
impl FakeClosedTarget {
13091316
async fn start() -> anyhow::Result<Self> {
13101317
let listener = TcpListener::bind("127.0.0.1:0").await.context("bind closed target")?;
13111318
let port = listener.local_addr()?.port();
1319+
let accepted = Arc::new(AtomicUsize::new(0));
1320+
let accepted_task = Arc::clone(&accepted);
13121321
tokio::spawn(async move {
13131322
loop {
13141323
let Ok((_stream, _)) = listener.accept().await else {
13151324
break;
13161325
};
1326+
accepted_task.fetch_add(1, Ordering::SeqCst);
13171327
}
13181328
});
1319-
Ok(Self { port })
1329+
Ok(Self { port, accepted })
1330+
}
1331+
1332+
fn accepted(&self) -> usize {
1333+
self.accepted.load(Ordering::SeqCst)
13201334
}
13211335
}
13221336

0 commit comments

Comments
 (0)