From 090a16953b2b09e1b815ee0b640d501151be4ee5 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 18 Dec 2018 16:00:25 +0100 Subject: [PATCH] bind: Add forgotten test for attributes. --- src/bind.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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."); + } }