message_correct: Check for unwanted attributes.
This commit is contained in:
parent
453a3635fd
commit
6952f3adfc
1 changed files with 17 additions and 1 deletions
|
@ -27,6 +27,11 @@ impl TryFrom<Element> for Replace {
|
||||||
for _ in elem.children() {
|
for _ in elem.children() {
|
||||||
return Err(Error::ParseError("Unknown child in replace element."));
|
return Err(Error::ParseError("Unknown child in replace element."));
|
||||||
}
|
}
|
||||||
|
for (attr, _) in elem.attrs() {
|
||||||
|
if attr != "id" {
|
||||||
|
return Err(Error::ParseError("Unknown attribute in replace element."));
|
||||||
|
}
|
||||||
|
}
|
||||||
let id = get_attr!(elem, "id", required);
|
let id = get_attr!(elem, "id", required);
|
||||||
Ok(Replace { id })
|
Ok(Replace { id })
|
||||||
}
|
}
|
||||||
|
@ -36,7 +41,7 @@ impl Into<Element> for Replace {
|
||||||
fn into(self) -> Element {
|
fn into(self) -> Element {
|
||||||
Element::builder("replace")
|
Element::builder("replace")
|
||||||
.ns(ns::MESSAGE_CORRECT)
|
.ns(ns::MESSAGE_CORRECT)
|
||||||
.attr("id", self.id.clone())
|
.attr("id", self.id)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +56,17 @@ mod tests {
|
||||||
Replace::try_from(elem).unwrap();
|
Replace::try_from(elem).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_attribute() {
|
||||||
|
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0' coucou=''/>".parse().unwrap();
|
||||||
|
let error = Replace::try_from(elem).unwrap_err();
|
||||||
|
let message = match error {
|
||||||
|
Error::ParseError(string) => string,
|
||||||
|
_ => panic!(),
|
||||||
|
};
|
||||||
|
assert_eq!(message, "Unknown attribute in replace element.");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_child() {
|
fn test_invalid_child() {
|
||||||
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'><coucou/></replace>".parse().unwrap();
|
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'><coucou/></replace>".parse().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue