Refuse the bookmark addresses that a ts3server:// link would change
The engine hands the TeamSpeak side its bookmark as a ts3server:// link and reads the options back from it. A link cannot say all an address can: a port that is no u16 (host:99999) was dropped silently and the connection went to the default port; a bare host with a '?' in it ended there and hid the channel behind the next '?' that to_url writes; a '/' or '#' ended the host and a '%' was decoded. The TeamSpeak library had refused every one of those when it resolved the address. connect_params returns a Result now. A bookmark whose port is not a number from 1 to 65535 (in host:port and [v6]:port), or whose host is empty, holds a '?', '#', '/' or '%', white space or a control character, or has an unclosed '[', fails the connect with a reason that shows the address without its query. The other normalisations of the round trip (blanks cut, [v6] without a port read as v6, an empty option is none, the model's rules for an address that is a link) are listed in docs/session-seam.md. Tests: the refused and the accepted addresses (the channel survives the round trip of each accepted one), the empty options, and a connect with a bad port that ends in Disconnected with the reason before any link is asked. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8db1a85f0
commit
2bee828022
3 files changed
+162
-10
No files matched your search
@@ -207,7 +207,10 @@ async fn drive(
|
||||
) -> Option<String> {
|
||||
let (media_tx, media_rx) = mpsc::unbounded_channel();
|
||||
let sink: Arc<dyn MediaSink> = Arc::new(MediaQueue(media_tx));
|
||||
let params = crate::ts_session::connect_params(options, sink, backends);
|
||||
let params = match crate::ts_session::connect_params(options, sink, backends) {
|
||||
Ok(params) => params,
|
||||
Err(e) => return connect_failure(&e),
|
||||
};
|
||||
let local = LocalCtx::new(ctx.clone(), options.audio, options.stream_peer.clone());
|
||||
let mut early: VecDeque<LinkCmd> = VecDeque::new();
|
||||
|
||||
|
||||
@@ -2253,3 +2253,25 @@ async fn the_features_of_a_server_are_the_hosts_narrowed_by_the_servers_list() {
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// A port that is no port is refused in words, not dropped: the connection
|
||||
/// would go to another port than the one the bookmark names.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_bookmark_with_a_port_that_is_no_port_does_not_connect() {
|
||||
let mut backends = Backends::empty();
|
||||
let (conns, mut seen) = mpsc::unbounded_channel();
|
||||
backends.register_local(Arc::new(LinkConnector::any(Arc::new(Recorder(conns)))));
|
||||
let link = SessionLink::new(backends);
|
||||
let ctx = LocalCtx::standalone().link;
|
||||
let (_cmd_tx, cmd_rx) = mpsc::unbounded_channel();
|
||||
let (event_tx, mut events) = mpsc::unbounded_channel();
|
||||
link.spawn(ConnectOptions::new("ts.example.com:99999", "tester"), ctx, cmd_rx, event_tx);
|
||||
let reason = event_of(&mut events, |e| match e {
|
||||
LinkEvent::Disconnected(reason) => Some(reason),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
let reason = reason.expect("a reason");
|
||||
assert!(reason.contains("65535") && reason.contains("ts.example.com:99999"), "{reason}");
|
||||
assert!(seen.try_recv().is_err(), "a link was asked to connect anyway");
|
||||
}
|
||||
Reference in new issue
Block a user