fix(protocol,bridge): wire nickname validation to connect (TODO-045)
Add validate_nickname() to ProtocolClient::connect() and bridge connect(). Trim whitespace, reject empty, truncate to 30 chars. Re-export validate_nickname from protocol and core.
This commit is contained in:
@@ -68,8 +68,8 @@ pub use chanora_diagnostics::{
|
|||||||
RedactingLogLayer, Redactor, DEFAULT_LOG_CAPACITY,
|
RedactingLogLayer, Redactor, DEFAULT_LOG_CAPACITY,
|
||||||
};
|
};
|
||||||
pub use chanora_protocol::{
|
pub use chanora_protocol::{
|
||||||
ChannelInfo, ChatMessage, ClientInfo, ClientProfile, ConnectConfig, DisconnectReason,
|
validate_nickname, ChannelInfo, ChatMessage, ClientInfo, ClientProfile, ConnectConfig,
|
||||||
MessageTarget, PokeStrength, ProtocolError, ServerActivity, ServerSnapshot,
|
DisconnectReason, MessageTarget, PokeStrength, ProtocolError, ServerActivity, ServerSnapshot,
|
||||||
};
|
};
|
||||||
pub use chanora_storage::{Bookmark, BookmarkRepository, IdentityFileStore};
|
pub use chanora_storage::{Bookmark, BookmarkRepository, IdentityFileStore};
|
||||||
pub use events::{
|
pub use events::{
|
||||||
|
|||||||
@@ -603,6 +603,8 @@ pub async fn connect(
|
|||||||
nickname: String,
|
nickname: String,
|
||||||
password: String,
|
password: String,
|
||||||
) -> Result<BridgeSnapshot, BridgeError> {
|
) -> Result<BridgeSnapshot, BridgeError> {
|
||||||
|
let nickname = chanora_core::validate_nickname(&nickname)
|
||||||
|
.map_err(|e| BridgeError::InvalidCommand(e.to_string()))?;
|
||||||
let cfg = chanora_core::ConnectConfig {
|
let cfg = chanora_core::ConnectConfig {
|
||||||
address: host,
|
address: host,
|
||||||
nickname,
|
nickname,
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ use tsproto_packets::packets::{Direction, Flags, InAudioBuf, OutCommand, OutPack
|
|||||||
use tsproto_types::ClientType;
|
use tsproto_types::ClientType;
|
||||||
|
|
||||||
use crate::dto::{
|
use crate::dto::{
|
||||||
ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, MessageTarget,
|
validate_nickname, ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile,
|
||||||
ProtocolDelta, ServerActivity, ServerSnapshot,
|
MessageTarget, ProtocolDelta, ServerActivity, ServerSnapshot,
|
||||||
};
|
};
|
||||||
use crate::poke_limiter::PokeLimiter;
|
use crate::poke_limiter::PokeLimiter;
|
||||||
use crate::ProtocolError;
|
use crate::ProtocolError;
|
||||||
@@ -324,9 +324,10 @@ impl ProtocolClient {
|
|||||||
if cfg.address.trim().is_empty() {
|
if cfg.address.trim().is_empty() {
|
||||||
return Err(ProtocolError::Invalid("address is empty".to_string()));
|
return Err(ProtocolError::Invalid("address is empty".to_string()));
|
||||||
}
|
}
|
||||||
if cfg.nickname.trim().is_empty() {
|
let validated_nick = validate_nickname(&cfg.nickname)
|
||||||
return Err(ProtocolError::Invalid("nickname is empty".to_string()));
|
.map_err(|e| ProtocolError::Invalid(e.to_string()))?;
|
||||||
}
|
let mut cfg = cfg;
|
||||||
|
cfg.nickname = validated_nick;
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel::<Request>(8);
|
let (tx, rx) = mpsc::channel::<Request>(8);
|
||||||
let (voice_out_tx, voice_out_rx) = mpsc::channel::<OutPacket>(64);
|
let (voice_out_tx, voice_out_rx) = mpsc::channel::<OutPacket>(64);
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ pub mod poke_limiter;
|
|||||||
|
|
||||||
pub use adapter::{ConnectConfig, DisconnectReason, InboundVoice, ProtocolClient, SnapshotProbe};
|
pub use adapter::{ConnectConfig, DisconnectReason, InboundVoice, ProtocolClient, SnapshotProbe};
|
||||||
pub use dto::{
|
pub use dto::{
|
||||||
ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile, MessageTarget,
|
validate_nickname, ChannelId, ChannelInfo, ChatMessage, ClientId, ClientInfo, ClientProfile,
|
||||||
PokeStrength, ProtocolDelta, ServerActivity, ServerSnapshot,
|
MessageTarget, PokeStrength, ProtocolDelta, ServerActivity, ServerSnapshot,
|
||||||
};
|
};
|
||||||
pub use poke_limiter::PokeLimiter;
|
pub use poke_limiter::PokeLimiter;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user