forked from lavina/lavina
1
0
Fork 0

remove fail message, fix test

This commit is contained in:
G1ng3r 2024-01-31 23:40:58 +03:00
parent 7f220c620f
commit d6da40e4ff
2 changed files with 4 additions and 92 deletions

View File

@ -238,11 +238,11 @@ async fn scenario_cap_sasl_fail() -> Result<()> {
s.send("CAP REQ :sasl").await?;
s.expect(":testserver CAP tester ACK :sasl").await?;
s.send("AUTHENTICATE SHA256").await?;
s.expect(":testserver 904").await?;
s.expect(":testserver 904 tester :Unsupported mechanism").await?;
s.send("AUTHENTICATE PLAIN").await?;
s.expect(":testserver AUTHENTICATE +").await?;
s.send("AUTHENTICATE wrong_password").await?;
s.expect(":testserver 904").await?;
s.send("AUTHENTICATE dGVzdGVyAHRlc3RlcgBwYXNzd29yZDE=").await?;
s.expect(":testserver 904 tester :Bad credentials").await?;
s.send("AUTHENTICATE dGVzdGVyAHRlc3RlcgBwYXNzd29yZA==").await?; // base64-encoded 'tester\x00tester\x00password'
s.expect(":testserver 900 tester tester tester :You are now logged in as tester").await?;
s.expect(":testserver 903 tester :SASL authentication successful").await?;

View File

@ -52,12 +52,6 @@ pub enum ServerMessageBody {
rest_targets: Vec<Str>,
text: Str,
},
Fail {
command: Str,
code: Str,
params: Option<Str>,
text: Str
},
Ping {
token: Str,
},
@ -180,21 +174,6 @@ impl ServerMessageBody {
writer.write_all(b" :").await?;
writer.write_all(text.as_bytes()).await?;
}
ServerMessageBody::Fail { command, code, params, text } =>
{
writer.write_all(b"FAIL ").await?;
writer.write_all(command.as_bytes()).await?;
writer.write_all(b" ").await?;
writer.write_all(code.as_bytes()).await?;
if let Some(p) = params.clone() {
writer.write_all(b" ").await?;
writer.write_all(p.as_bytes()).await?;
} else {
();
}
writer.write_all(b" :").await?;
writer.write_all(text.as_bytes()).await?;
}
ServerMessageBody::Ping { token } => {
writer.write_all(b"PING ").await?;
writer.write_all(token.as_bytes()).await?;
@ -425,8 +404,7 @@ fn server_message_body(input: &str) -> IResult<&str, ServerMessageBody> {
server_message_body_notice,
server_message_body_ping,
server_message_body_pong,
server_message_body_cap,
server_message_body_fail,
server_message_body_cap
))(input)
}
@ -448,28 +426,6 @@ fn server_message_body_notice(input: &str) -> IResult<&str, ServerMessageBody> {
))
}
fn server_message_body_fail(input: &str) -> IResult<&str, ServerMessageBody> {
let (input, _) = tag("FAIL ")(input)?;
let (input, command) = receiver(input)?;
let (input, _) = tag(" ")(input)?;
let (input, code) = receiver(input)?;
let (input, _) = tag(" ")(input)?;
let (input, params) = params(input)?;
let (input, _) = tag(":")(input)?;
let (input, text) = token(input)?;
let command = command.into();
let code = code.into();
let params: Arc<str> = params.trim().into();
let params = if params.is_empty() { None } else { Some(params) };
let text = text.into();
Ok((
input,
ServerMessageBody::Fail { command, code, params, text }
))
}
fn server_message_body_ping(input: &str) -> IResult<&str, ServerMessageBody> {
let (input, _) = tag("PING ")(input)?;
let (input, token) = token(input)?;
@ -574,48 +530,4 @@ mod test {
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
assert_eq!(bytes, input.as_bytes());
}
#[test]
fn test_server_message_fail() {
let input = "FAIL BOX BOXES_INVALID STACK CLOCKWISE :Given boxes are not supported\r\n";
let expected = ServerMessage {
tags: vec![],
sender: None,
body: ServerMessageBody::Fail {
command: "BOX".into(),
code: "BOXES_INVALID".into(),
params: Some("STACK CLOCKWISE".into()),
text: "Given boxes are not supported".into(),
},
};
let result = server_message(input);
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
let mut bytes = vec![];
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
assert_eq!(bytes, input.as_bytes());
}
#[test]
fn test_server_short_message_fail() {
let input = "FAIL REHASH CONFIG_BAD :Could not reload config from disk\r\n";
let expected = ServerMessage {
tags: vec![],
sender: None,
body: ServerMessageBody::Fail {
command: "REHASH".into(),
code: "CONFIG_BAD".into(),
params: None,
text: "Could not reload config from disk".into(),
},
};
let result = server_message(input);
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
let mut bytes = vec![];
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
assert_eq!(bytes, input.as_bytes());
}
}