mirror of
https://github.com/valmojr/armatak.git
synced 2026-08-18 16:02:58 +00:00
Cover video CoT serialization helpers
This commit is contained in:
@@ -50,3 +50,80 @@ pub fn video_detail_xml(video_url: &str, uid: &str, callsign: &str) -> String {
|
||||
escape_xml_attribute(callsign),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{escape_xml_attribute, parse_video_url, video_detail_xml};
|
||||
|
||||
#[test]
|
||||
fn escapes_xml_attribute_characters() {
|
||||
assert_eq!(
|
||||
escape_xml_attribute("A&B\"<C>'"),
|
||||
"A&B"<C>'"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_video_url_with_credentials_and_path() {
|
||||
assert_eq!(
|
||||
parse_video_url(" RTSP://user:pass@video.example.test:8554/live/main "),
|
||||
Some((
|
||||
"rtsp".to_string(),
|
||||
"video.example.test".to_string(),
|
||||
"8554".to_string(),
|
||||
"/live/main".to_string(),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_video_url_without_path() {
|
||||
assert_eq!(
|
||||
parse_video_url("udp://239.1.1.1:1234"),
|
||||
Some((
|
||||
"udp".to_string(),
|
||||
"239.1.1.1".to_string(),
|
||||
"1234".to_string(),
|
||||
String::new(),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_malformed_video_urls() {
|
||||
assert!(parse_video_url("video.example.test:8554/live").is_none());
|
||||
assert!(parse_video_url("rtsp://video.example.test/live").is_none());
|
||||
assert!(parse_video_url("://video.example.test:8554/live").is_none());
|
||||
assert!(parse_video_url("rtsp://:8554/live").is_none());
|
||||
assert!(parse_video_url("rtsp://video.example.test:/live").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emits_empty_video_detail_for_blank_url() {
|
||||
assert_eq!(video_detail_xml(" ", "uid", "callsign"), "<__video></__video>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn falls_back_to_escaped_url_for_unstructured_input() {
|
||||
assert_eq!(
|
||||
video_detail_xml("custom&stream\"", "uid", "callsign"),
|
||||
"<__video url=\"custom&stream"\"/>"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emits_connection_entry_for_structured_video_url() {
|
||||
let xml = video_detail_xml(
|
||||
"RTSP://user:pass@video.example.test:8554/live?a=1&b=2",
|
||||
"uas<&\"'",
|
||||
"Falcon<&\"'",
|
||||
);
|
||||
|
||||
assert!(xml.contains("protocol=\"rtsp\""));
|
||||
assert!(xml.contains("address=\"video.example.test\""));
|
||||
assert!(xml.contains("port=\"8554\""));
|
||||
assert!(xml.contains("path=\"/live?a=1&b=2\""));
|
||||
assert!(xml.contains("uid=\"uas<&"'\""));
|
||||
assert!(xml.contains("alias=\"Falcon<&"'\""));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user