forked from lavina/lavina
Check for missing namespace and test
This commit is contained in:
parent
fdb48f3c47
commit
99be4fca68
|
@ -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<Self> {
|
||||
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#"<iq from='juliet@example.com/balcony' id='bv1bs71f' type='get'><query/></iq>"#;
|
||||
|
||||
assert!(parse::<Iq<RosterQuery>>(input).is_err());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue