Refuse a TeamSpeak identity that holds no JSON

link::connect::credential sent a TeamSpeak IdentityBlob with an empty json as
an empty Credential::Foreign blob, which is what the TeamSpeak connector reads
as "make an identity up" (identity: None). An identity that holds nothing is no
identity: it is refused with SessionError::Protocol, as the Voelin branch
refuses a key that cannot be read, before any connector is asked. The comment
of ts::identity::to_blob ("a blob with no JSON is refused when it is used")
holds on both paths now: the gateway's from_blob already refused it.

Two tests: connect_params refuses "" and white space and still sends none as
the empty blob; an engine on the fake host answers ConnectVoice with the reason
and the connector is never asked and makes no session.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 10:58:34 +03:00
1 parent e13d401b9c
commit 87926e9b59
2 files changed
+52 -2

No files matched your search

+29 -1
View File
@@ -75,12 +75,19 @@ pub(crate) fn connect_params(
/// TeamSpeak identity goes as the JSON the key store keeps, and none at all as
/// an empty one, for which the TeamSpeak connector makes an identity up (the
/// protocol's convention for "generate one", follow-up P11); a Voelin key
/// signs.
/// signs. A TeamSpeak identity that holds no JSON is refused: sent as it is,
/// it would be that same empty blob and be taken for the request to make one
/// up, which only the absence of an identity may be.
fn credential(identity: Option<&IdentityBlob>) -> Result<Credential, SessionError> {
let Some(blob) = identity else {
return Ok(Credential::Foreign { kind: KIND_TEAMSPEAK, blob: Bytes::new() });
};
if blob.is_teamspeak() {
if blob.json.trim().is_empty() {
return Err(SessionError::Protocol(
"the TeamSpeak identity cannot be read: it is empty".into(),
));
}
let json = Bytes::copy_from_slice(blob.json.as_bytes());
Ok(Credential::Foreign { kind: KIND_TEAMSPEAK, blob: json })
} else if blob.is_voelin() {
@@ -206,6 +213,27 @@ mod tests {
assert_eq!(text, "an identity of kind \"account\" cannot be used to connect");
}
/// A TeamSpeak identity with no JSON is no identity. The empty blob is
/// what asks the TeamSpeak connector to make one up (`identity: None`), so
/// it is refused here instead of being sent as that request.
#[test]
fn a_teamspeak_identity_without_json_is_refused() {
let mut options = VoiceOptions::new("ts.example.com", "nick");
for json in ["", " \n\t"] {
options.identity = Some(IdentityBlob::teamspeak("uid=", 8, json));
let Err(SessionError::Protocol(text)) = params(&options) else {
panic!("a refusal for {json:?}")
};
assert_eq!(text, "the TeamSpeak identity cannot be read: it is empty");
}
// No identity at all is the request to make one up, as before.
options.identity = None;
assert!(matches!(
params(&options).unwrap().credential,
Credential::Foreign { kind: "teamspeak", blob } if blob.is_empty()
));
}
/// The client version spec rides the link as it was typed, whatever it
/// holds, and only for an address that is a TeamSpeak bookmark or link.
#[test]
+23 -1
View File
@@ -23,7 +23,8 @@ use voelin_core::history::MessageSource;
use voelin_core::settings::Settings;
use voelin_core::{
Backends, Command, DownloadTo, Engine, Event, History, HistoryMessage, HistorySource,
JoinFailure, SessionId, SessionState, Source, TransferState, VoiceOptions, VoiceState,
IdentityBlob, JoinFailure, SessionId, SessionState, Source, TransferState, VoiceOptions,
VoiceState,
};
use voelin_model::{ChatMessage, ChatTarget, Presence};
use voelin_proto::link::{CloseReason, Connector, FlowId, MediaPacket, SessionError, voice_sub};
@@ -1480,3 +1481,24 @@ async fn a_connect_that_fails_says_why_and_the_next_one_works() {
assert_eq!(first.address, "fake://host");
assert_eq!(first.hello.nickname, "tester");
}
/// A TeamSpeak identity that holds no JSON is refused with its reason before a
/// connector is asked for anything: an empty credential blob would ask a
/// TeamSpeak connector to make an identity up, which only `identity: None` may.
#[tokio::test(flavor = "multi_thread")]
async fn a_teamspeak_identity_without_json_is_refused_and_no_session_is_made() {
let mut h = Harness::start();
let mut options = VoiceOptions::new("fake://host", "tester");
options.identity = Some(IdentityBlob::teamspeak("uid=", 8, ""));
h.engine.send(Command::ConnectVoice { session: SESSION, options: Box::new(options) });
let state = h.state(|s| s.voice == VoiceState::Disconnected).await;
assert_eq!((state.own_channel, state.own_client), (None, None));
assert_eq!(h.error().await, "voice: the TeamSpeak identity cannot be read: it is empty");
assert!(h.connector.connects().is_empty(), "the connector was asked to connect");
assert!(h.connector.last_session().is_none(), "a session was made");
// Without an identity the connector is asked as usual.
let handle = h.connect().await;
assert!(handle.close_reason().is_none());
assert_eq!(h.connector.connects().len(), 1);
}