diff --git a/crates/projection-xmpp/src/iq.rs b/crates/projection-xmpp/src/iq.rs index acd9f74..fd0f98b 100644 --- a/crates/projection-xmpp/src/iq.rs +++ b/crates/projection-xmpp/src/iq.rs @@ -88,7 +88,15 @@ impl<'a> XmppConnection<'a> { req.serialize(output); } IqClientBody::MessageArchiveRequest(request) => { - // let response = self.mam().await?; + let response = self.mam().await; + // let req = Iq { + // from: iq.to, + // id: iq.id, + // to: None, + // r#type: IqType::Result, + // body: response, + // }; + response.serialize(output); } _ => { let req = Iq { @@ -224,9 +232,9 @@ impl<'a> XmppConnection<'a> { ItemQuery { item } } - async fn mam(&self) -> Result, ()> { + async fn mam(&self) -> Message<()> { // return Ok(()); - Ok(Message:: { + Message::<()> { from: None, id: Some("aacea".to_string()), to: Some(Jid { @@ -238,7 +246,7 @@ impl<'a> XmppConnection<'a> { lang: None, subject: Some("daa".into()), body: "bbb".into(), - custom: vec![Ignore], - }) + custom: vec![], + } } } diff --git a/crates/projection-xmpp/tests/lib.rs b/crates/projection-xmpp/tests/lib.rs index 2318fd0..790ee5e 100644 --- a/crates/projection-xmpp/tests/lib.rs +++ b/crates/projection-xmpp/tests/lib.rs @@ -102,7 +102,7 @@ impl<'a> TestScopeTls<'a> { assert_matches!(self.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "features")); assert_matches!(self.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "mechanisms")); assert_matches!(self.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "mechanism")); - assert_matches!(self.next_xml_event().await?, Event::Text(b) => assert_eq!(&*b, "PLAIN")); + assert_matches!(self.next_xml_event().await?, Event::Text(b) => assert_eq!(&*b, b"PLAIN")); assert_matches!(self.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "mechanism")); assert_matches!(self.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "mechanisms")); assert_matches!(self.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "features")); @@ -233,7 +233,7 @@ async fn scenario_basic() -> Result<()> { assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "iq")); assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "bind")); assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "jid")); - assert_matches!(s.next_xml_event().await?, Event::Text(b) => assert_eq!(&*b, "tester@localhost/tester")); + assert_matches!(s.next_xml_event().await?, Event::Text(b) => assert_eq!(&*b, b"tester@localhost/tester")); assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "jid")); assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "bind")); assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "iq")); @@ -395,7 +395,7 @@ async fn test_message_archive_request() -> Result<()> { // test scenario server.storage.create_user("tester").await?; - server.storage.set_password("tester", "password").await?; + Authenticator::new(&server.storage).set_password("tester", "password").await?; let mut stream = TcpStream::connect(server.server.addr).await?; let mut s = TestScope::new(&mut stream); @@ -405,11 +405,7 @@ async fn test_message_archive_request() -> Result<()> { s.send(r#""#).await?; assert_matches!(s.next_xml_event().await?, Event::Decl(_) => {}); assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "stream")); - assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "features")); - assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "starttls")); - assert_matches!(s.next_xml_event().await?, Event::Empty(b) => assert_eq!(element_name(&b.local_name()), "required")); - assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "starttls")); - assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "features")); + s.expect_starttls_required().await?; s.send(r#""#).await?; assert_matches!(s.next_xml_event().await?, Event::Empty(b) => assert_eq!(element_name(&b.local_name()), "proceed")); let buffer = s.buffer; @@ -431,40 +427,36 @@ async fn test_message_archive_request() -> Result<()> { s.send(r#""#).await?; assert_matches!(s.next_xml_event().await?, Event::Decl(_) => {}); assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "stream")); + s.expect_auth_mechanisms().await?; - assert_matches!(s.next_xml_event().await?, Event::Start(b) => { - assert_eq!(element_name(&b.local_name()), "features") - }); - assert_matches!(s.next_xml_event().await?, Event::Start(b) => { - assert_eq!(element_name(&b.local_name()), "mechanisms") - }); - assert_matches!(s.next_xml_event().await?, Event::Start(b) => { - assert_eq!(element_name(&b.local_name()), "mechanism") - }); - assert_matches!(s.next_xml_event().await?, Event::Text(b) => { - // b. - // let local_name: &str = from_utf8(element_name(&b.local_name())).unwrap(); - // assert_eq!(local_name, "mechanism") - }); - assert_matches!(s.next_xml_event().await?, Event::End(b) => { - // let local_name: &str = from_utf8(element_name(&b.local_name())).unwrap(); - // assert_eq!(local_name, "mechanism") - }); - assert_matches!(s.next_xml_event().await?, Event::End(b) => { - assert_eq!(element_name(&b.local_name()), "mechanisms") - }); - assert_matches!(s.next_xml_event().await?, Event::End(b) => { - assert_eq!(element_name(&b.local_name()), "features") - }); - // s.send(r#""#).await?; + // base64-encoded "\x00tester\x00password" + s.send(r#"AHRlc3RlcgBwYXNzd29yZA=="#) + .await?; + assert_matches!(s.next_xml_event().await?, Event::Empty(b) => assert_eq!(element_name(&b.local_name()), "success")); + s.send(r#""#).await?; + s.send(r#""#).await?; + assert_matches!(s.next_xml_event().await?, Event::Decl(_) => {}); + assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "stream")); + s.expect_bind_feature().await?; + s.send(r#"kek"#).await?; + assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "iq")); + assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "bind")); + assert_matches!(s.next_xml_event().await?, Event::Start(b) => assert_eq!(element_name(&b.local_name()), "jid")); + assert_matches!(s.next_xml_event().await?, Event::Text(b) => assert_eq!(&*b, b"tester@localhost/tester")); + assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "jid")); + assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "bind")); + assert_matches!(s.next_xml_event().await?, Event::End(b) => assert_eq!(element_name(&b.local_name()), "iq")); + + s.send(r#""#).await?; assert_matches!(s.next_xml_event().await?, Event::Start(b) => { assert_eq!(element_name(&b.local_name()), "message") }); + s.send(r#"Logged out"#).await?; stream.shutdown().await?; // wrap up - server.server.terminate().await?; + server.shutdown().await?; Ok(()) }