From 1e85abd10cca63a7426eec56d1ed9d639c96437e Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 20 Dec 2018 20:58:13 +0100 Subject: [PATCH 1/7] sasl: Add test failure_with_non_prefixed_text_lang. --- src/sasl.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sasl.rs b/src/sasl.rs index 05dd250a..86e10760 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -288,4 +288,20 @@ mod tests { String::from("Call 212-555-1212 for assistance.") ); } + + #[test] + fn failure_with_non_prefixed_text_lang() { + let elem: Element = " + + Invalid username or password + " + .parse() + .unwrap(); + let failure = Failure::try_from(elem).unwrap(); + assert_eq!(failure.defined_condition, DefinedCondition::NotAuthorized); + assert_eq!( + failure.texts["en"], + String::from("Invalid username or password") + ); + } } From 95f4ade4ba6d8d86ffa84cd49bd4021dad7f2bf3 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 30 Dec 2018 00:36:29 +0100 Subject: [PATCH 2/7] compat mode that relaxes some of the check_* macros --- Cargo.toml | 2 ++ src/attention.rs | 3 +++ src/bind.rs | 1 + src/blocking.rs | 18 ++++++++++------ src/caps.rs | 1 + src/chatstates.rs | 2 ++ src/jingle_ft.rs | 49 +++++++++++++++++++++++++----------------- src/macros.rs | 3 +++ src/message_correct.rs | 1 + src/muc/muc.rs | 1 + src/muc/user.rs | 5 +++++ src/nick.rs | 3 +++ src/ping.rs | 3 +++ src/presence.rs | 2 ++ src/pubsub/event.rs | 1 + src/roster.rs | 1 + src/sasl.rs | 5 +---- 17 files changed, 70 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d3122cb..65935bab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,5 @@ try_from = "0.3.2" [features] # Build xmpp-parsers to make components instead of clients. component = [] +# Compatibility mode +compat = [] diff --git a/src/attention.rs b/src/attention.rs index be33bb3b..c786f313 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -18,6 +18,7 @@ impl MessagePayload for Attention {} #[cfg(test)] mod tests { use super::*; + #[cfg(not(feature = "compat"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -33,6 +34,7 @@ mod tests { Attention::try_from(elem).unwrap(); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_child() { let elem: Element = "" @@ -46,6 +48,7 @@ mod tests { assert_eq!(message, "Unknown child in attention element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/bind.rs b/src/bind.rs index fe9472b2..bd09d4f3 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -112,6 +112,7 @@ mod tests { assert_eq!(bind, Bind::None); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_resource() { let elem: Element = "resource" diff --git a/src/blocking.rs b/src/blocking.rs index d34fee3d..b2fe70df 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -155,13 +155,16 @@ mod tests { }, ]; - let request_elem = elem.clone(); - let error = BlocklistRequest::try_from(request_elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown child in blocklist element."); + #[cfg(not(feature = "compat"))] + { + let request_elem = elem.clone(); + let error = BlocklistRequest::try_from(request_elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown child in blocklist element."); + } let result_elem = elem.clone(); let result = BlocklistResult::try_from(result_elem).unwrap(); @@ -176,6 +179,7 @@ mod tests { assert_eq!(unblock.items, two_items); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid() { let elem: Element = "" diff --git a/src/caps.rs b/src/caps.rs index 72b04263..3befdc9b 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -233,6 +233,7 @@ mod tests { ); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_child() { let elem: Element = "K1Njy3HZBThlo4moOD5gBGhn0U0oK7/CbfLlIUDi6o4=".parse().unwrap(); diff --git a/src/chatstates.rs b/src/chatstates.rs index 75d64d91..9a972aa7 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -63,6 +63,7 @@ mod tests { assert_eq!(message, "This is not a chatstate element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_child() { let elem: Element = "" @@ -76,6 +77,7 @@ mod tests { assert_eq!(message, "Unknown child in chatstate element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index 381eb21f..359cd8b0 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -510,13 +510,16 @@ mod tests { }; assert_eq!(message, "Unknown child in received element."); - let elem: Element = "".parse().unwrap(); - let error = Received::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in received element."); + #[cfg(not(feature = "compat"))] + { + let elem: Element = "".parse().unwrap(); + let error = Received::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in received element."); + } let elem: Element = "" @@ -575,13 +578,16 @@ mod tests { }; assert_eq!(message, "This is not a file element."); - let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); - let error = Checksum::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in checksum element."); + #[cfg(not(feature = "compat"))] + { + let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); + let error = Checksum::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in checksum element."); + } let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); let error = Checksum::try_from(elem).unwrap_err(); @@ -631,11 +637,14 @@ mod tests { let elem: Element = "" .parse() .unwrap(); - let error = Range::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in range element."); + #[cfg(not(feature = "compat"))] + { + let error = Range::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in range element."); + } } } diff --git a/src/macros.rs b/src/macros.rs index 62c59736..daccec5c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -248,6 +248,7 @@ macro_rules! check_ns_only { macro_rules! check_no_children { ($elem:ident, $name:tt) => { + #[cfg(not(feature = "compat"))] for _ in $elem.children() { return Err(crate::error::Error::ParseError(concat!( "Unknown child in ", @@ -260,6 +261,7 @@ macro_rules! check_no_children { macro_rules! check_no_attributes { ($elem:ident, $name:tt) => { + #[cfg(not(feature = "compat"))] for _ in $elem.attrs() { return Err(crate::error::Error::ParseError(concat!( "Unknown attribute in ", @@ -272,6 +274,7 @@ macro_rules! check_no_attributes { macro_rules! check_no_unknown_attributes { ($elem:ident, $name:tt, [$($attr:tt),*]) => ( + #[cfg(not(feature = "compat"))] for (_attr, _) in $elem.attrs() { $( if _attr == $attr { diff --git a/src/message_correct.rs b/src/message_correct.rs index 9e7a08f7..e0d22d62 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -45,6 +45,7 @@ mod tests { Replace::try_from(elem).unwrap(); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/muc/muc.rs b/src/muc/muc.rs index 32df468d..40528383 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -142,6 +142,7 @@ mod tests { assert_eq!(elem, elem2); } + #[cfg(not(feature = "compat"))] #[test] fn test_muc_invalid_attribute() { let elem: Element = "" diff --git a/src/muc/user.rs b/src/muc/user.rs index 2c1a6926..a104e319 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -303,6 +303,7 @@ mod tests { assert!(elem.compare_to(&elem2)); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = " @@ -343,6 +344,7 @@ mod tests { assert_eq!(message, "Required attribute 'code' missing."); } + #[cfg(not(feature = "compat"))] #[test] fn test_status_invalid_child() { let elem: Element = " @@ -513,6 +515,7 @@ mod tests { assert_eq!(reason.0, "Reason".to_owned()); } + #[cfg(not(feature = "compat"))] #[test] fn test_reason_invalid_attribute() { let elem: Element = " @@ -528,6 +531,7 @@ mod tests { assert_eq!(message, "Unknown attribute in reason element.".to_owned()); } + #[cfg(not(feature = "compat"))] #[test] fn test_reason_invalid() { let elem: Element = " @@ -545,6 +549,7 @@ mod tests { assert_eq!(message, "Unknown child in reason element.".to_owned()); } + #[cfg(not(feature = "compat"))] #[test] fn test_item_invalid_attr() { let elem: Element = " diff --git a/src/nick.rs b/src/nick.rs index edf8dcac..67a45ff9 100644 --- a/src/nick.rs +++ b/src/nick.rs @@ -14,6 +14,7 @@ generate_elem_id!( #[cfg(test)] mod tests { use super::*; + #[cfg(not(feature = "compat"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -48,6 +49,7 @@ mod tests { assert_eq!(elem1, elem2); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid() { let elem: Element = "" @@ -61,6 +63,7 @@ mod tests { assert_eq!(message, "Unknown child in nick element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/ping.rs b/src/ping.rs index 4cb25f64..6f48dd55 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -20,6 +20,7 @@ impl IqGetPayload for Ping {} #[cfg(test)] mod tests { use super::*; + #[cfg(not(feature = "compat"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -42,6 +43,7 @@ mod tests { assert_eq!(elem1, elem2); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid() { let elem: Element = "" @@ -55,6 +57,7 @@ mod tests { assert_eq!(message, "Unknown child in ping element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "".parse().unwrap(); diff --git a/src/presence.rs b/src/presence.rs index 1f9846c2..20d63e87 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -570,6 +570,7 @@ mod tests { assert!(payload.is("test", "invalid")); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_status_child() { #[cfg(not(feature = "component"))] @@ -589,6 +590,7 @@ mod tests { assert_eq!(message, "Unknown child in status element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { #[cfg(not(feature = "component"))] diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index fac8e2fe..0cad1cc0 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -420,6 +420,7 @@ mod tests { assert_eq!(message, "Unknown child in event element."); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/roster.rs b/src/roster.rs index 40cc7a25..c0d869d1 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -245,6 +245,7 @@ mod tests { assert_eq!(roster.items[0].subscription, Subscription::Remove); } + #[cfg(not(feature = "compat"))] #[test] fn test_invalid() { let elem: Element = "" diff --git a/src/sasl.rs b/src/sasl.rs index 86e10760..21e58572 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -289,6 +289,7 @@ mod tests { ); } + #[cfg(feature = "compat")] #[test] fn failure_with_non_prefixed_text_lang() { let elem: Element = " @@ -299,9 +300,5 @@ mod tests { .unwrap(); let failure = Failure::try_from(elem).unwrap(); assert_eq!(failure.defined_condition, DefinedCondition::NotAuthorized); - assert_eq!( - failure.texts["en"], - String::from("Invalid username or password") - ); } } From 047649dbc839b4253df17bc01d357a7f731b48fe Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 30 Dec 2018 00:49:57 +0100 Subject: [PATCH 3/7] .gitlab-ci.yml: add a compat-rust-latest stage --- .gitlab-ci.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0b4e77f0..ba174224 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,29 @@ stages: - build +variables: + FEATURES: "" + rust-latest: stage: build image: rust:latest script: - - cargo build --verbose - - cargo test --verbose + - cargo build --verbose --no-default-features --features=$FEATURES + - cargo test --verbose --no-default-features --features=$FEATURES rust-nightly: stage: build image: rustlang/rust:nightly script: - - cargo build --verbose - - cargo test --verbose + - cargo build --verbose --no-default-features --features=$FEATURES + - cargo test --verbose --no-default-features --features=$FEATURES + +"rust-latest with features=compat": + extends: rust-latest + variables: + FEATURES: "compat" + +"rust-nightly with features=compat": + extends: rust-nightly + variables: + FEATURES: "compat" From ee511e653aa17a646391a991f7aef0af281080ba Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 12 Jan 2019 20:41:12 +0100 Subject: [PATCH 4/7] sasl: Add back the assert, with the correct @xml:lang this time. --- src/sasl.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sasl.rs b/src/sasl.rs index 21e58572..6f922901 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -300,5 +300,9 @@ mod tests { .unwrap(); let failure = Failure::try_from(elem).unwrap(); assert_eq!(failure.defined_condition, DefinedCondition::NotAuthorized); + assert_eq!( + failure.texts[""], + String::from("Invalid username or password") + ); } } From 8b15728bb2c9b686506affb0442697660625ee67 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 12 Jan 2019 20:41:40 +0100 Subject: [PATCH 5/7] blocking, jingle_ft: Split #[cfg] sections into their own tests. --- src/blocking.rs | 23 +++++++++-------- src/jingle_ft.rs | 65 +++++++++++++++++++++++++----------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/blocking.rs b/src/blocking.rs index b2fe70df..e12e7e49 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -155,17 +155,6 @@ mod tests { }, ]; - #[cfg(not(feature = "compat"))] - { - let request_elem = elem.clone(); - let error = BlocklistRequest::try_from(request_elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown child in blocklist element."); - } - let result_elem = elem.clone(); let result = BlocklistResult::try_from(result_elem).unwrap(); assert_eq!(result.items, two_items); @@ -221,4 +210,16 @@ mod tests { }; assert_eq!(message, "Unknown attribute in unblock element."); } + + #[cfg(not(feature = "compat"))] + #[test] + fn test_non_empty_blocklist_request() { + let elem: Element = "".parse().unwrap(); + let error = BlocklistRequest::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown child in blocklist element."); + } } diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index 359cd8b0..d9a73b29 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -510,17 +510,6 @@ mod tests { }; assert_eq!(message, "Unknown child in received element."); - #[cfg(not(feature = "compat"))] - { - let elem: Element = "".parse().unwrap(); - let error = Received::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in received element."); - } - let elem: Element = "" .parse() @@ -541,6 +530,18 @@ mod tests { assert_eq!(message, "Unknown value for 'creator' attribute."); } + #[cfg(not(feature = "compat"))] + #[test] + fn test_invalid_received() { + let elem: Element = "".parse().unwrap(); + let error = Received::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in received element."); + } + #[test] fn test_checksum() { let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); @@ -578,17 +579,6 @@ mod tests { }; assert_eq!(message, "This is not a file element."); - #[cfg(not(feature = "compat"))] - { - let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); - let error = Checksum::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in checksum element."); - } - let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); let error = Checksum::try_from(elem).unwrap_err(); let message = match error { @@ -606,6 +596,18 @@ mod tests { assert_eq!(message, "Unknown value for 'creator' attribute."); } + #[cfg(not(feature = "compat"))] + #[test] + fn test_invalid_checksum() { + let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); + let error = Checksum::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in checksum element."); + } + #[test] fn test_range() { let elem: Element = "" @@ -633,18 +635,19 @@ mod tests { assert_eq!(range2.offset, 2048); assert_eq!(range2.length, Some(1024)); assert_eq!(range2.hashes, hashes); + } + #[cfg(not(feature = "compat"))] + #[test] + fn test_invalid_range() { let elem: Element = "" .parse() .unwrap(); - #[cfg(not(feature = "compat"))] - { - let error = Range::try_from(elem).unwrap_err(); - let message = match error { - Error::ParseError(string) => string, - _ => panic!(), - }; - assert_eq!(message, "Unknown attribute in range element."); - } + let error = Range::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in range element."); } } From c2b7e193788ca42f1ce07ab4a1bb404a799597ea Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 12 Jan 2019 22:00:46 +0100 Subject: [PATCH 6/7] Rename "compat" into "disable-validation", to insist on it breaking some guarantees. --- .gitlab-ci.yml | 8 ++++---- Cargo.toml | 4 ++-- src/attention.rs | 6 +++--- src/bind.rs | 2 +- src/blocking.rs | 4 ++-- src/caps.rs | 2 +- src/chatstates.rs | 4 ++-- src/jingle_ft.rs | 6 +++--- src/macros.rs | 6 +++--- src/message_correct.rs | 2 +- src/muc/muc.rs | 2 +- src/muc/user.rs | 10 +++++----- src/nick.rs | 6 +++--- src/ping.rs | 6 +++--- src/presence.rs | 4 ++-- src/pubsub/event.rs | 2 +- src/roster.rs | 2 +- src/sasl.rs | 2 +- 18 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba174224..3f233d21 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,12 +18,12 @@ rust-nightly: - cargo build --verbose --no-default-features --features=$FEATURES - cargo test --verbose --no-default-features --features=$FEATURES -"rust-latest with features=compat": +"rust-latest with features=disable-validation": extends: rust-latest variables: - FEATURES: "compat" + FEATURES: "disable-validation" -"rust-nightly with features=compat": +"rust-nightly with features=disable-validation": extends: rust-nightly variables: - FEATURES: "compat" + FEATURES: "disable-validation" diff --git a/Cargo.toml b/Cargo.toml index 65935bab..0e3b9a36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,5 +28,5 @@ try_from = "0.3.2" [features] # Build xmpp-parsers to make components instead of clients. component = [] -# Compatibility mode -compat = [] +# Disable validation of unknown attributes. +disable-validation = [] diff --git a/src/attention.rs b/src/attention.rs index c786f313..bd4c7a15 100644 --- a/src/attention.rs +++ b/src/attention.rs @@ -18,7 +18,7 @@ impl MessagePayload for Attention {} #[cfg(test)] mod tests { use super::*; - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -34,7 +34,7 @@ mod tests { Attention::try_from(elem).unwrap(); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_child() { let elem: Element = "" @@ -48,7 +48,7 @@ mod tests { assert_eq!(message, "Unknown child in attention element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/bind.rs b/src/bind.rs index bd09d4f3..9d3a894f 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -112,7 +112,7 @@ mod tests { assert_eq!(bind, Bind::None); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_resource() { let elem: Element = "resource" diff --git a/src/blocking.rs b/src/blocking.rs index e12e7e49..53417f7f 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -168,7 +168,7 @@ mod tests { assert_eq!(unblock.items, two_items); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid() { let elem: Element = "" @@ -211,7 +211,7 @@ mod tests { assert_eq!(message, "Unknown attribute in unblock element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_non_empty_blocklist_request() { let elem: Element = "".parse().unwrap(); diff --git a/src/caps.rs b/src/caps.rs index 3befdc9b..74042be3 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -233,7 +233,7 @@ mod tests { ); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_child() { let elem: Element = "K1Njy3HZBThlo4moOD5gBGhn0U0oK7/CbfLlIUDi6o4=".parse().unwrap(); diff --git a/src/chatstates.rs b/src/chatstates.rs index 9a972aa7..4eb173f1 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -63,7 +63,7 @@ mod tests { assert_eq!(message, "This is not a chatstate element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_child() { let elem: Element = "" @@ -77,7 +77,7 @@ mod tests { assert_eq!(message, "Unknown child in chatstate element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/jingle_ft.rs b/src/jingle_ft.rs index d9a73b29..32dd41f6 100644 --- a/src/jingle_ft.rs +++ b/src/jingle_ft.rs @@ -530,7 +530,7 @@ mod tests { assert_eq!(message, "Unknown value for 'creator' attribute."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_received() { let elem: Element = "".parse().unwrap(); @@ -596,7 +596,7 @@ mod tests { assert_eq!(message, "Unknown value for 'creator' attribute."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_checksum() { let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); @@ -637,7 +637,7 @@ mod tests { assert_eq!(range2.hashes, hashes); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_range() { let elem: Element = "" diff --git a/src/macros.rs b/src/macros.rs index daccec5c..aa89a45c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -248,7 +248,7 @@ macro_rules! check_ns_only { macro_rules! check_no_children { ($elem:ident, $name:tt) => { - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] for _ in $elem.children() { return Err(crate::error::Error::ParseError(concat!( "Unknown child in ", @@ -261,7 +261,7 @@ macro_rules! check_no_children { macro_rules! check_no_attributes { ($elem:ident, $name:tt) => { - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] for _ in $elem.attrs() { return Err(crate::error::Error::ParseError(concat!( "Unknown attribute in ", @@ -274,7 +274,7 @@ macro_rules! check_no_attributes { macro_rules! check_no_unknown_attributes { ($elem:ident, $name:tt, [$($attr:tt),*]) => ( - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] for (_attr, _) in $elem.attrs() { $( if _attr == $attr { diff --git a/src/message_correct.rs b/src/message_correct.rs index e0d22d62..3bba10e7 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -45,7 +45,7 @@ mod tests { Replace::try_from(elem).unwrap(); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/muc/muc.rs b/src/muc/muc.rs index 40528383..fc596fa9 100644 --- a/src/muc/muc.rs +++ b/src/muc/muc.rs @@ -142,7 +142,7 @@ mod tests { assert_eq!(elem, elem2); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_muc_invalid_attribute() { let elem: Element = "" diff --git a/src/muc/user.rs b/src/muc/user.rs index a104e319..56c111e8 100644 --- a/src/muc/user.rs +++ b/src/muc/user.rs @@ -303,7 +303,7 @@ mod tests { assert!(elem.compare_to(&elem2)); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = " @@ -344,7 +344,7 @@ mod tests { assert_eq!(message, "Required attribute 'code' missing."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_status_invalid_child() { let elem: Element = " @@ -515,7 +515,7 @@ mod tests { assert_eq!(reason.0, "Reason".to_owned()); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_reason_invalid_attribute() { let elem: Element = " @@ -531,7 +531,7 @@ mod tests { assert_eq!(message, "Unknown attribute in reason element.".to_owned()); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_reason_invalid() { let elem: Element = " @@ -549,7 +549,7 @@ mod tests { assert_eq!(message, "Unknown child in reason element.".to_owned()); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_item_invalid_attr() { let elem: Element = " diff --git a/src/nick.rs b/src/nick.rs index 67a45ff9..03f544aa 100644 --- a/src/nick.rs +++ b/src/nick.rs @@ -14,7 +14,7 @@ generate_elem_id!( #[cfg(test)] mod tests { use super::*; - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -49,7 +49,7 @@ mod tests { assert_eq!(elem1, elem2); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid() { let elem: Element = "" @@ -63,7 +63,7 @@ mod tests { assert_eq!(message, "Unknown child in nick element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/ping.rs b/src/ping.rs index 6f48dd55..01853120 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -20,7 +20,7 @@ impl IqGetPayload for Ping {} #[cfg(test)] mod tests { use super::*; - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] use crate::error::Error; use minidom::Element; use try_from::TryFrom; @@ -43,7 +43,7 @@ mod tests { assert_eq!(elem1, elem2); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid() { let elem: Element = "" @@ -57,7 +57,7 @@ mod tests { assert_eq!(message, "Unknown child in ping element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "".parse().unwrap(); diff --git a/src/presence.rs b/src/presence.rs index 20d63e87..7e3e8aa8 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -570,7 +570,7 @@ mod tests { assert!(payload.is("test", "invalid")); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_status_child() { #[cfg(not(feature = "component"))] @@ -590,7 +590,7 @@ mod tests { assert_eq!(message, "Unknown child in status element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { #[cfg(not(feature = "component"))] diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index 0cad1cc0..0cef2c39 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -420,7 +420,7 @@ mod tests { assert_eq!(message, "Unknown child in event element."); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/src/roster.rs b/src/roster.rs index c0d869d1..c13b0f59 100644 --- a/src/roster.rs +++ b/src/roster.rs @@ -245,7 +245,7 @@ mod tests { assert_eq!(roster.items[0].subscription, Subscription::Remove); } - #[cfg(not(feature = "compat"))] + #[cfg(not(feature = "disable-validation"))] #[test] fn test_invalid() { let elem: Element = "" diff --git a/src/sasl.rs b/src/sasl.rs index 6f922901..45a56653 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -289,7 +289,7 @@ mod tests { ); } - #[cfg(feature = "compat")] + #[cfg(feature = "disable-validation")] #[test] fn failure_with_non_prefixed_text_lang() { let elem: Element = " From 635e8633a85075660a7e00750b715ffccb33c2f6 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 13 Jan 2019 11:56:40 +0100 Subject: [PATCH 7/7] sasl: Document the reason for the unprefixed @lang test. --- src/sasl.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sasl.rs b/src/sasl.rs index 45a56653..db9b17e6 100644 --- a/src/sasl.rs +++ b/src/sasl.rs @@ -289,9 +289,11 @@ mod tests { ); } + /// Some servers apparently use a non-namespaced 'lang' attribute, which is invalid as not part + /// of the schema. This tests whether we can parse it when disabling validation. #[cfg(feature = "disable-validation")] #[test] - fn failure_with_non_prefixed_text_lang() { + fn invalid_failure_with_non_prefixed_text_lang() { let elem: Element = " Invalid username or password