From be1930c584cbb9dbbad3e3e05c0dfa7fa0652676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 24 Sep 2022 01:47:59 +0200 Subject: [PATCH] tests/iq: test_self_ping_answer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/tests/iq.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/tests/iq.rs b/src/tests/iq.rs index 4e2dcf7..3047a83 100644 --- a/src/tests/iq.rs +++ b/src/tests/iq.rs @@ -67,6 +67,64 @@ async fn test_iq_unimplemented() { handle_stanza(&mut component, &mut rooms).await.unwrap(); } +#[tokio::test] +async fn test_self_ping_answer() { + let realjid1 = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap()); + let roomjid = COMPONENT_JID.clone().with_node("room"); + let participant1 = Jid::Full(roomjid.clone().with_resource("nick1")); + + let join: Element = Presence::new(PresenceType::None) + .with_from(realjid1.clone()) + .with_to(participant1.clone()) + .with_payloads(vec![Muc::new().into()]) + .into(); + + let disco: Element = Iq { + from: Some(realjid1.clone()), + to: Some(participant1.clone()), + id: String::from("disco"), + payload: IqType::Get(DiscoInfoQuery { node: None }.into()), + } + .into(); + + let ping: Element = Iq { + from: Some(realjid1.clone()), + to: Some(participant1.clone()), + id: String::from("ping"), + payload: IqType::Get(Ping {}.into()), + } + .into(); + + let mut component = TestComponent::new(vec![join, disco, ping]); + let mut rooms: HashMap = HashMap::new(); + + component.expect_presence(|_| (), "Self-presence"); + component.expect_message(|_| (), "Subject"); + + component.expect_iq( + |iq| { + if let IqType::Result(Some(el)) = iq.payload { + if let Ok(result) = DiscoInfoResult::try_from(el) { + assert!(result.features.contains(&Feature { + var: String::from("http://jabber.org/protocol/muc#self-ping-optimization") + })); + } else { + panic!("Should be a disco result"); + } + } else { + panic!("Should be a disco result"); + } + }, + "Disco", + ); + + component.expect(Into::::into( + Iq::empty_result(realjid1.clone(), "ping").with_from(participant1.clone()), + )); + + handle_stanza(&mut component, &mut rooms).await.unwrap(); +} + #[tokio::test] async fn test_self_ping_participant_non_existing() { let realjid1 = Jid::Full(FullJid::from_str("foo@bar/qxx").unwrap());