diff --git a/src/bind.rs b/src/bind.rs index ddda0392..fe9472b2 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -55,9 +55,11 @@ impl TryFrom for Bind { return Err(Error::ParseError("Bind can only have one child.")); } if child.is("resource", ns::BIND) { + check_no_attributes!(child, "resource"); check_no_children!(child, "resource"); bind = Bind::Resource(child.text()); } else if child.is("jid", ns::BIND) { + check_no_attributes!(child, "jid"); check_no_children!(child, "jid"); bind = Bind::Jid(Jid::from_str(&child.text())?); } else { @@ -109,4 +111,27 @@ mod tests { let bind = Bind::try_from(elem).unwrap(); assert_eq!(bind, Bind::None); } + + #[test] + fn test_invalid_resource() { + let elem: Element = "resource" + .parse() + .unwrap(); + let error = Bind::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in resource element."); + + let elem: Element = "resource" + .parse() + .unwrap(); + let error = Bind::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown child in resource element."); + } }