xso: reject duplicate children

This was an oversight. Even though we apparently don't have tests for
this anywhere, it is what the old functional macros do.
This commit is contained in:
Jonas Schäfer 2024-08-03 13:28:07 +02:00 • committed by Link Mauve
commit 6440209f95
5 changed files with 92 additions and 1 deletions

View file

@ -39,3 +39,26 @@ pub struct Query {
impl IqSetPayload for Query {}
impl IqGetPayload for Query {}
impl IqResultPayload for Query {}
#[cfg(test)]
mod tests {
use super::*;
use minidom::Element;
use xso::error::{Error, FromElementError};
#[test]
fn test_invalid_duplicate_child() {
let elem: Element = "<query xmlns='jabber:iq:private'><storage xmlns='storage:bookmarks'/><storage xmlns='storage:bookmarks'/></query>"
.parse()
.unwrap();
let error = Query::try_from(elem).unwrap_err();
let message = match error {
FromElementError::Invalid(Error::Other(string)) => string,
_ => panic!(),
};
assert_eq!(
message,
"Query element must not have more than one child in field 'storage'."
);
}
}