attention: Add missing unknown attribute check.

This commit is contained in:
Emmanuel Gil Peyrot 2017-07-20 20:11:00 +01:00
parent 1f43cd934b
commit 5ec921fa6f

View file

@ -25,6 +25,9 @@ impl TryFrom<Element> for Attention {
for _ in elem.children() { for _ in elem.children() {
return Err(Error::ParseError("Unknown child in attention element.")); return Err(Error::ParseError("Unknown child in attention element."));
} }
for _ in elem.attrs() {
return Err(Error::ParseError("Unknown attribute in attention element."));
}
Ok(Attention) Ok(Attention)
} }
} }
@ -61,6 +64,17 @@ mod tests {
assert_eq!(message, "Unknown child in attention element."); assert_eq!(message, "Unknown child in attention element.");
} }
#[test]
fn test_invalid_attribute() {
let elem: Element = "<attention xmlns='urn:xmpp:attention:0' coucou=''/>".parse().unwrap();
let error = Attention::try_from(elem).unwrap_err();
let message = match error {
Error::ParseError(string) => string,
_ => panic!(),
};
assert_eq!(message, "Unknown attribute in attention element.");
}
#[test] #[test]
fn test_serialise() { fn test_serialise() {
let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap(); let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();