use super::{As4SendPolicyBuilder, ParsedAs4UserMessage};
pub const TEST_SERVICE_URI: &str =
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/service";
pub const TEST_ACTION_URI: &str =
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/test";
pub fn is_test_service_message(msg: &ParsedAs4UserMessage) -> bool {
msg.action == TEST_ACTION_URI && msg.service.as_deref() == Some(TEST_SERVICE_URI)
}
pub fn test_service_send_policy() -> As4SendPolicyBuilder {
As4SendPolicyBuilder::new()
.service(TEST_SERVICE_URI, "")
.action(TEST_ACTION_URI)
}
#[cfg(test)]
mod ping_detection_tests {
use super::*;
use crate::as4::ParsedAs4UserMessage;
fn user_message(service: Option<&str>, action: &str) -> ParsedAs4UserMessage {
ParsedAs4UserMessage {
message_id: "m1".into(),
action: action.into(),
from_party_ids: vec!["a".into()],
to_party_ids: vec!["b".into()],
mpc: None,
conversation_id: None,
has_ws_security_header: false,
service: service.map(str::to_string),
ref_to_message_id: None,
original_sender: None,
final_recipient: None,
tracking_identifier: None,
timestamp: None,
wsa_headers: None,
}
}
#[test]
fn a_test_service_message_is_detected() {
assert!(is_test_service_message(&user_message(
Some(TEST_SERVICE_URI),
TEST_ACTION_URI
)));
}
#[test]
fn one_matching_uri_is_not_a_ping() {
assert!(!is_test_service_message(&user_message(
Some(TEST_SERVICE_URI),
"urn:example:action"
)));
assert!(!is_test_service_message(&user_message(
Some("urn:example:service"),
TEST_ACTION_URI
)));
assert!(!is_test_service_message(&user_message(
Some("urn:example:service"),
"urn:example:action"
)));
assert!(!is_test_service_message(&user_message(
None,
TEST_ACTION_URI
)));
}
#[test]
fn the_reserved_uris_match_the_specification() {
assert_eq!(
TEST_SERVICE_URI,
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/service"
);
assert_eq!(
TEST_ACTION_URI,
"http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/test"
);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::as4::ParsedAs4UserMessage;
fn make_msg(action: &str, service: Option<&str>) -> ParsedAs4UserMessage {
ParsedAs4UserMessage {
message_id: "test-id".into(),
action: action.into(),
from_party_ids: vec!["a".into()],
to_party_ids: vec!["b".into()],
mpc: None,
conversation_id: None,
has_ws_security_header: false,
service: service.map(|s| s.into()),
ref_to_message_id: None,
original_sender: None,
final_recipient: None,
tracking_identifier: None,
timestamp: None,
wsa_headers: None,
}
}
#[test]
fn test_service_detection_matches_both_uris() {
let msg = make_msg(TEST_ACTION_URI, Some(TEST_SERVICE_URI));
assert!(is_test_service_message(&msg));
}
#[test]
fn test_service_detection_rejects_wrong_action() {
let msg = make_msg("urn:other:action", Some(TEST_SERVICE_URI));
assert!(!is_test_service_message(&msg));
}
#[test]
fn test_service_detection_rejects_wrong_service() {
let msg = make_msg(TEST_ACTION_URI, Some("http://example.org/other"));
assert!(!is_test_service_message(&msg));
}
#[test]
fn test_service_detection_rejects_missing_service() {
let msg = make_msg(TEST_ACTION_URI, None);
assert!(!is_test_service_message(&msg));
}
#[cfg(feature = "interop-relaxed")]
#[test]
fn test_service_send_policy_sets_correct_uris() {
let (policy, _) = test_service_send_policy()
.interop(crate::core::InteropMode::Relaxed)
.sign(false)
.build()
.expect("build");
assert_eq!(policy.service, TEST_SERVICE_URI);
assert_eq!(policy.action, TEST_ACTION_URI);
assert_eq!(policy.service_type, "");
}
}