parsers: fix tests with --features disable-validation and/or component

This disables a bunch of tests when the component feature is disabled,
because that feature changes the namespace of the <message/> element,
which causes the tests to fail.

Thanks to debacle for finding this.
This commit is contained in:
Jonas Schäfer 2026-02-22 12:09:09 +01:00
commit 65c1f5ab10
7 changed files with 16 additions and 4 deletions

View file

@ -24,6 +24,7 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
- ibr::LegacyQuery now implements Default, allowing users to more - ibr::LegacyQuery now implements Default, allowing users to more
easily construct it (!660) easily construct it (!660)
- jingle_rtp::Description gained a bandwidth child. - jingle_rtp::Description gained a bandwidth child.
- Fix cargo test for the disable-validation and component features.
Version 0.22.0: Version 0.22.0:
2025-10-28 pep <pep@bouah.net> 2025-10-28 pep <pep@bouah.net>

View file

@ -58,6 +58,7 @@ impl MessagePayload for Sent {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[cfg(not(feature = "component"))]
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::Element;
@ -94,6 +95,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn forwarded_elements() { fn forwarded_elements() {
let elem: Element = "<received xmlns='urn:xmpp:carbons:2'> let elem: Element = "<received xmlns='urn:xmpp:carbons:2'>
<forwarded xmlns='urn:xmpp:forward:0'> <forwarded xmlns='urn:xmpp:forward:0'>
@ -135,6 +137,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_serialize_received() { fn test_serialize_received() {
let reference: Element = "<received xmlns='urn:xmpp:carbons:2'><forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></received>" let reference: Element = "<received xmlns='urn:xmpp:carbons:2'><forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></received>"
.parse() .parse()
@ -154,6 +157,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_serialize_sent() { fn test_serialize_sent() {
let reference: Element = "<sent xmlns='urn:xmpp:carbons:2'><forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></sent>" let reference: Element = "<sent xmlns='urn:xmpp:carbons:2'><forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></sent>"
.parse() .parse()

View file

@ -485,6 +485,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "disable-validation"))]
fn test_wrong_child() { fn test_wrong_child() {
let elem: Element = "<x xmlns='jabber:x:data' type='cancel'><coucou/></x>" let elem: Element = "<x xmlns='jabber:x:data' type='cancel'><coucou/></x>"
.parse() .parse()

View file

@ -47,6 +47,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_simple() { fn test_simple() {
let elem: Element = let elem: Element =
"<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client'/></forwarded>" "<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client'/></forwarded>"
@ -56,6 +57,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
#[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")]
fn test_invalid_child() { fn test_invalid_child() {
let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client'/><coucou/></forwarded>" let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client'/><coucou/></forwarded>"
@ -70,6 +72,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_serialise() { fn test_serialise() {
let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' type='chat'/></forwarded>".parse().unwrap(); let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' type='chat'/></forwarded>".parse().unwrap();
let forwarded = Forwarded { let forwarded = Forwarded {
@ -81,6 +84,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_serialize_with_delay_and_stanza() { fn test_serialize_with_delay_and_stanza() {
let reference: Element = "<forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded>" let reference: Element = "<forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded>"
.parse() .parse()
@ -123,6 +127,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_invalid_duplicate_message() { fn test_invalid_duplicate_message() {
let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded>" let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded>"
.parse() .parse()

View file

@ -300,6 +300,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")]
fn test_invalid_child() { fn test_invalid_child() {
let elem: Element = "<query xmlns='urn:xmpp:mam:2'><coucou/></query>" let elem: Element = "<query xmlns='urn:xmpp:mam:2'><coucou/></query>"
.parse() .parse()
@ -350,6 +351,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(feature = "component"))] // feature = "component" changes <message/> namespace
fn test_serialize_result() { fn test_serialize_result() {
let reference: Element = "<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'><forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></result>" let reference: Element = "<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'><forwarded xmlns='urn:xmpp:forward:0'><delay xmlns='urn:xmpp:delay' stamp='2002-09-10T23:08:25+00:00'/><message xmlns='jabber:client' to='juliet@capulet.example/balcony' from='romeo@montague.example/home'/></forwarded></result>"
.parse() .parse()

View file

@ -130,6 +130,7 @@ mod tests {
} }
#[test] #[test]
#[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")]
fn test_invalid_child() { fn test_invalid_child() {
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'><coucou/></set>" let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'><coucou/></set>"
.parse() .parse()

View file

@ -140,10 +140,6 @@ fn empty_unexpected_attribute() {
} }
#[test] #[test]
#[cfg_attr(
feature = "disable-validation",
should_panic = "unexpected result: Ok("
)]
fn empty_ignores_xml_lang() { fn empty_ignores_xml_lang() {
#[allow(unused_imports)] #[allow(unused_imports)]
use core::{ use core::{
@ -1651,6 +1647,7 @@ fn element_catch_one_negative_none() {
} }
#[test] #[test]
#[cfg(not(feature = "disable-validation"))]
fn element_catch_one_negative_more_than_one_child() { fn element_catch_one_negative_more_than_one_child() {
#[allow(unused_imports)] #[allow(unused_imports)]
use core::{ use core::{
@ -1693,6 +1690,7 @@ fn element_catch_maybe_one_roundtrip_some() {
} }
#[test] #[test]
#[cfg(not(feature = "disable-validation"))]
fn element_catch_maybe_one_negative_more_than_one_child() { fn element_catch_maybe_one_negative_more_than_one_child() {
#[allow(unused_imports)] #[allow(unused_imports)]
use core::{ use core::{