From 47d10ee3bd2584168ae329a3ce26bbd1d035edbb Mon Sep 17 00:00:00 2001 From: aschumann-virtualcable Date: Tue, 17 Nov 2026 23:58:06 +0100 Subject: [PATCH] Accept a user without a password in the URP module The broker sends the user name in the script parameters and keeps the password inside the ticket for the agent, so a URP start with user and no password is the normal shape. The module rejected it with "'user' and 'password' must come together", which made every broker-launched session fail. Reject only a password without a user. --- crates/js/src/js_modules/urp.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/js/src/js_modules/urp.rs b/crates/js/src/js_modules/urp.rs index 1935703..5865feb 100644 --- a/crates/js/src/js_modules/urp.rs +++ b/crates/js/src/js_modules/urp.rs @@ -98,9 +98,9 @@ impl JsUrpSettings { .as_slice() .try_into() .map_err(|_| "'shared_secret' must be 32 bytes".to_string())?; - // Credentials travel together or not at all. - if self.user.is_some() != self.password.is_some() { - return Err("'user' and 'password' must come together".into()); + // The broker never sends a password here: it stays inside the ticket for the agent. + if self.password.is_some() && self.user.is_none() { + return Err("'password' requires 'user'".into()); } let red = self.redirections.clone().unwrap_or_default(); let defs = UrpRedirections::default(); @@ -313,15 +313,35 @@ mod tests { #[tokio::test] #[serial_test::serial(js_modules)] - async fn test_rejects_half_credentials() -> Result<()> { + async fn test_rejects_password_without_user() -> Result<()> { let messages_rx = test_setup()?; let mut ctx = create_context(None)?; register(&mut ctx)?; let script = format!( - r#"URP.start({{ server: "h", ticket: "{VALID_TICKET}", shared_secret: {VALID_SECRET_JS}, user: "u" }});"# + r#"URP.start({{ server: "h", ticket: "{VALID_TICKET}", shared_secret: {VALID_SECRET_JS}, password: "p" }});"# ); assert!(exec_script(&mut ctx, &script).await.is_err()); assert!(messages_rx.try_recv().is_err()); Ok(()) } + + #[tokio::test] + #[serial_test::serial(js_modules)] + async fn test_accepts_user_without_password() -> Result<()> { + let messages_rx = test_setup()?; + let mut ctx = create_context(None)?; + register(&mut ctx)?; + let script = format!( + r#"URP.start({{ server: "h", ticket: "{VALID_TICKET}", shared_secret: {VALID_SECRET_JS}, user: "u" }});"# + ); + exec_script(&mut ctx, &script).await.map_err(|e| anyhow::anyhow!(e))?; + match messages_rx.try_recv() { + Ok(GuiMessage::ConnectUrp(settings)) => { + assert_eq!(settings.user.as_deref(), Some("u")); + assert!(settings.password.is_none()); + } + other => panic!("Expected GuiMessage::ConnectUrp, got {:?}", other.is_ok()), + } + Ok(()) + } }