From 847cb4867b7e1456605ed20487b36849b7644080 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 22 Apr 2024 21:47:32 +0200 Subject: [PATCH] Check for missing namespace and test --- crates/proto-xmpp/src/roster.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/proto-xmpp/src/roster.rs b/crates/proto-xmpp/src/roster.rs index 835cf94..7eb97d1 100644 --- a/crates/proto-xmpp/src/roster.rs +++ b/crates/proto-xmpp/src/roster.rs @@ -2,7 +2,7 @@ use quick_xml::events::{BytesStart, Event}; use crate::xml::*; use anyhow::{anyhow, Result}; -use quick_xml::name::ResolveResult; +use quick_xml::name::{Namespace, ResolveResult}; pub const XMLNS: &'static str = "jabber:iq:roster"; @@ -14,6 +14,9 @@ impl FromXml for RosterQuery { fn parse() -> Self::P { |(mut namespace, mut event): (ResolveResult<'static>, &'static Event<'static>)| -> Result { + let ResolveResult::Bound(Namespace(ns)) = namespace else { + return Err(anyhow!("No namespace provided")); + }; match event { Event::Start(_) => (), Event::Empty(_) => return Ok(RosterQuery), @@ -57,7 +60,7 @@ mod tests { from: Option::from(Jid { name: Option::from(Name("juliet".into())), server: Server("example.com".into()), - resource: Option::from(Resource("balcony".into())) + resource: Option::from(Resource("balcony".into())), }), id: "bv1bs71f".to_string(), to: None, @@ -66,4 +69,11 @@ mod tests { } ) } + + #[test] + fn test_missing_namespace() { + let input = r#""#; + + assert!(parse::>(input).is_err()); + } }