Return an error if a client attempts to authenticate again
Diff
src/client.rs | 8 +++++++-
src/connection.rs | 20 ++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
@@ -12,7 +12,7 @@
use crate::{
channel::Channel,
connection::{InitiatedConnection, MessageSink},
connection::{InitiatedConnection, MessageSink, SaslAlreadyAuthenticated},
messages::{
Broadcast, ChannelFetchTopic, ChannelInvite, ChannelJoin, ChannelKickUser, ChannelList,
ChannelMemberList, ChannelMessage, ChannelPart, ChannelUpdateTopic, FetchClientDetails,
@@ -569,7 +569,11 @@
Command::BOTSERV(_) => {}
Command::HOSTSERV(_) => {}
Command::MEMOSERV(_) => {}
Command::AUTHENTICATE(_) => {}
Command::AUTHENTICATE(_) => {
self.writer.write(
SaslAlreadyAuthenticated(self.connection.nick.to_string()).into_message(),
);
}
Command::ACCOUNT(_) => {}
Command::METADATA(_, _, _) => {}
Command::MONITOR(_, _) => {}
@@ -343,6 +343,26 @@
}
}
pub struct SaslAlreadyAuthenticated(pub String);
impl SaslAlreadyAuthenticated {
#[must_use]
pub fn into_message(self) -> Message {
Message {
tags: None,
prefix: None,
command: Command::Response(
Response::ERR_SASLALREADY,
vec![
self.0,
"You have already authenticated using SASL".to_string(),
],
),
}
}
}
pub struct SaslStrategyUnsupported(String);