From d6da40e4ffa1cff0941f45ca8711dc89ee660eda Mon Sep 17 00:00:00 2001 From: G1ng3r Date: Wed, 31 Jan 2024 23:40:58 +0300 Subject: [PATCH] remove fail message, fix test --- crates/projection-irc/tests/lib.rs | 6 +- crates/proto-irc/src/server.rs | 90 +----------------------------- 2 files changed, 4 insertions(+), 92 deletions(-) diff --git a/crates/projection-irc/tests/lib.rs b/crates/projection-irc/tests/lib.rs index 1a686a4..a0ee071 100644 --- a/crates/projection-irc/tests/lib.rs +++ b/crates/projection-irc/tests/lib.rs @@ -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?; diff --git a/crates/proto-irc/src/server.rs b/crates/proto-irc/src/server.rs index 4c1836c..bc7844d 100644 --- a/crates/proto-irc/src/server.rs +++ b/crates/proto-irc/src/server.rs @@ -52,12 +52,6 @@ pub enum ServerMessageBody { rest_targets: Vec, text: Str, }, - Fail { - command: Str, - code: Str, - params: Option, - 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 = 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()); - } }