diff --git a/crates/voelin-core/src/link/backends.rs b/crates/voelin-core/src/link/backends.rs index bca8c29..549add5 100644 --- a/crates/voelin-core/src/link/backends.rs +++ b/crates/voelin-core/src/link/backends.rs @@ -208,7 +208,15 @@ impl Backends { if let Some(local) = self.locals.iter().find(|c| c.accepts(&scheme)) { return local.connect_local(params, ctx); } - let connect = self.connectors.connect(params); + // Not `Connectors::connect`, which names the whole address when none serves it: + // the text is shown, and a TeamSpeak link carries a channel password. + let Some(connector) = self.connectors.for_address(¶ms.address) else { + let shown = without_query(¶ms.address).to_owned(); + return Box::pin(async move { + Err(SessionError::Protocol(format!("no connector for {shown}"))) + }); + }; + let connect = connector.connect(params); Box::pin(async move { let connected = connect.await?; Ok(LocalConnected { connected, streams: None }) @@ -216,6 +224,12 @@ impl Backends { } } +/// An address as it may be shown or logged: without its query and fragment, +/// where a link keeps a channel password or a host pin. +pub(crate) fn without_query(address: &str) -> &str { + address.split(['?', '#']).next().unwrap_or_default() +} + /// Refuses every host that asks to be trusted. struct RefuseUnknownHosts; @@ -237,4 +251,11 @@ mod tests { assert_eq!(Backends::scheme("teamspeak://x"), "teamspeak"); assert_eq!(Backends::scheme("voelin://host/i/code"), "voelin"); } + + #[test] + fn an_address_is_shown_without_its_secrets() { + assert_eq!(without_query("ts3server://h?port=1&channelpassword=hunter2"), "ts3server://h"); + assert_eq!(without_query("voelin://h/i/code#h=abcd"), "voelin://h/i/code"); + assert_eq!(without_query("host:9987"), "host:9987"); + } } diff --git a/crates/voelin-core/src/link/mod.rs b/crates/voelin-core/src/link/mod.rs index a94a49c..a736c8b 100644 --- a/crates/voelin-core/src/link/mod.rs +++ b/crates/voelin-core/src/link/mod.rs @@ -110,7 +110,9 @@ mod session_link; mod tests; pub use backends::Backends; -pub(crate) use backends::{LocalConnected, LocalConnector, LocalCtx, StreamEvent, StreamPort}; +pub(crate) use backends::{ + LocalConnected, LocalConnector, LocalCtx, StreamEvent, StreamPort, without_query, +}; pub(crate) use session_link::SessionLink; use std::path::PathBuf; diff --git a/crates/voelin-core/src/ts_session/mod.rs b/crates/voelin-core/src/ts_session/mod.rs index ccd4b1c..35405fd 100644 --- a/crates/voelin-core/src/ts_session/mod.rs +++ b/crates/voelin-core/src/ts_session/mod.rs @@ -148,7 +148,7 @@ fn inner_options(params: &ConnectParams, ctx: &LocalCtx) -> Result link, _ => { // Without the query: a channel password rides in it. - let shown = params.address.split('?').next().unwrap_or_default(); + let shown = crate::link::without_query(¶ms.address); return Err(SessionError::Protocol(format!("not a TeamSpeak server address: {shown}"))); } };