bind: Add forgotten test for attributes.

This commit is contained in:
Emmanuel Gil Peyrot 2018-12-18 16:00:25 +01:00
parent 7a204cd182
commit 090a16953b

View file

@ -55,9 +55,11 @@ impl TryFrom<Element> 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 = "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource attr='coucou'>resource</resource></bind>"
.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 = "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource><hello-world/>resource</resource></bind>"
.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.");
}
}