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() {
|
||||
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);
|
||||
Ok(Replace { id })
|
||||
}
|
||||
|
@ -36,7 +41,7 @@ impl Into<Element> for Replace {
|
|||
fn into(self) -> Element {
|
||||
Element::builder("replace")
|
||||
.ns(ns::MESSAGE_CORRECT)
|
||||
.attr("id", self.id.clone())
|
||||
.attr("id", self.id)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +56,17 @@ mod tests {
|
|||
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]
|
||||
fn test_invalid_child() {
|
||||
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'><coucou/></replace>".parse().unwrap();
|
||||
|
|
Loading…
Reference in a new issue