[domistream] Tests: rustfmt
This commit is contained in:
@@ -106,7 +106,11 @@ fn response_lying_content_length() {
|
||||
// Under: more bytes than it claims.
|
||||
assert_err!(parse_response(&response("200 OK", &[("Content-Length", "2")], b"12345")), Error::Malformed { .. });
|
||||
for cl in ["abc", "-1", "+5", "5 5", "0x5", "", "5;"] {
|
||||
assert_err!(parse_response(&response("200 OK", &[("Content-Length", cl)], b"12345")), Error::Malformed { .. }, "{cl:?}");
|
||||
assert_err!(
|
||||
parse_response(&response("200 OK", &[("Content-Length", cl)], b"12345")),
|
||||
Error::Malformed { .. },
|
||||
"{cl:?}"
|
||||
);
|
||||
}
|
||||
// Two different lengths.
|
||||
assert_err!(
|
||||
@@ -125,7 +129,10 @@ fn response_lying_content_length() {
|
||||
fn response_header_flood() {
|
||||
let names: Vec<String> = (0..=MAX_RTSP_HEADERS).map(|i| format!("X-H{i}")).collect();
|
||||
let headers = |n: usize| names[..n].iter().map(|n| (n.as_str(), "v")).collect::<Vec<_>>();
|
||||
assert_eq!(parse_response(&response("200 OK", &headers(MAX_RTSP_HEADERS), b"")).unwrap().headers.len(), MAX_RTSP_HEADERS);
|
||||
assert_eq!(
|
||||
parse_response(&response("200 OK", &headers(MAX_RTSP_HEADERS), b"")).unwrap().headers.len(),
|
||||
MAX_RTSP_HEADERS
|
||||
);
|
||||
assert_cap!(parse_response(&response("200 OK", &headers(MAX_RTSP_HEADERS + 1), b"")), MAX_RTSP_HEADERS);
|
||||
// A flood of empty-valued headers in under 64 KiB.
|
||||
let flood: Vec<(String, &str)> = (0..5000).map(|i| (format!("F{i}"), "")).collect();
|
||||
@@ -139,7 +146,10 @@ fn response_line_cap() {
|
||||
let value = |line: usize| "v".repeat(line - 3);
|
||||
let ok = value(MAX_RTSP_LINE_BYTES);
|
||||
assert_eq!(parse_response(&response("200 OK", &[("X", &ok)], b"")).unwrap().header("x"), Some(ok.as_str()));
|
||||
assert_cap!(parse_response(&response("200 OK", &[("X", &value(MAX_RTSP_LINE_BYTES + 1))], b"")), MAX_RTSP_LINE_BYTES);
|
||||
assert_cap!(
|
||||
parse_response(&response("200 OK", &[("X", &value(MAX_RTSP_LINE_BYTES + 1))], b"")),
|
||||
MAX_RTSP_LINE_BYTES
|
||||
);
|
||||
let reason = "r".repeat(MAX_RTSP_LINE_BYTES);
|
||||
assert_cap!(parse_response(&response(&format!("200 {reason}"), &[], b"")), MAX_RTSP_LINE_BYTES);
|
||||
}
|
||||
@@ -150,7 +160,11 @@ fn response_size_boundaries() {
|
||||
let r = parse_response(&response_of_size(len)).unwrap_or_else(|e| panic!("{len}: {e:?}"));
|
||||
assert_eq!(r.status, 200);
|
||||
}
|
||||
assert_too_large!(parse_response(&response_of_size(MAX_RTSP_MESSAGE_BYTES + 1)), MAX_RTSP_MESSAGE_BYTES, MAX_RTSP_MESSAGE_BYTES + 1);
|
||||
assert_too_large!(
|
||||
parse_response(&response_of_size(MAX_RTSP_MESSAGE_BYTES + 1)),
|
||||
MAX_RTSP_MESSAGE_BYTES,
|
||||
MAX_RTSP_MESSAGE_BYTES + 1
|
||||
);
|
||||
assert_too_large!(parse_response(&vec![b'R'; 1 << 24]), MAX_RTSP_MESSAGE_BYTES, 1 << 24);
|
||||
}
|
||||
|
||||
@@ -183,7 +197,8 @@ fn request_parse_and_encode() {
|
||||
(Method::Announce, "ANNOUNCE"),
|
||||
(Method::Play, "PLAY"),
|
||||
] {
|
||||
let req = RtspRequest { method: m, target: "x".into(), headers: vec![("CSeq".into(), "1".into())], body: vec![] };
|
||||
let req =
|
||||
RtspRequest { method: m, target: "x".into(), headers: vec![("CSeq".into(), "1".into())], body: vec![] };
|
||||
assert!(req.encode().unwrap().starts_with(format!("{name} x RTSP/1.0\r\n").as_bytes()));
|
||||
}
|
||||
}
|
||||
@@ -194,15 +209,26 @@ fn request_refuses_unknown_methods_and_bad_lines() {
|
||||
let raw = format!("{m} rtsp://h:1 RTSP/1.0\r\nCSeq: 1\r\n\r\n");
|
||||
assert_err!(parse_request(raw.as_bytes()), Error::UnexpectedValue { .. }, "{m}");
|
||||
}
|
||||
for bad in [&b""[..], b"O", b"OPTIONS\r\n\r\n", b"OPTIONS rtsp://h:1\r\n\r\n", b"OPTIONS rtsp://h:1 RTSP/9.9\r\n\r\n"] {
|
||||
for bad in
|
||||
[&b""[..], b"O", b"OPTIONS\r\n\r\n", b"OPTIONS rtsp://h:1\r\n\r\n", b"OPTIONS rtsp://h:1 RTSP/9.9\r\n\r\n"]
|
||||
{
|
||||
assert_err!(parse_request(bad), Error::Malformed { .. }, "{:?}", String::from_utf8_lossy(bad));
|
||||
}
|
||||
assert_too_large!(parse_request(&vec![b'O'; MAX_RTSP_MESSAGE_BYTES + 1]), MAX_RTSP_MESSAGE_BYTES, MAX_RTSP_MESSAGE_BYTES + 1);
|
||||
assert_too_large!(
|
||||
parse_request(&vec![b'O'; MAX_RTSP_MESSAGE_BYTES + 1]),
|
||||
MAX_RTSP_MESSAGE_BYTES,
|
||||
MAX_RTSP_MESSAGE_BYTES + 1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_refuses_header_injection() {
|
||||
let base = || RtspRequest { method: Method::Setup, target: "streamid=video/0/0".into(), headers: vec![("CSeq".into(), "4".into())], body: vec![] };
|
||||
let base = || RtspRequest {
|
||||
method: Method::Setup,
|
||||
target: "streamid=video/0/0".into(),
|
||||
headers: vec![("CSeq".into(), "4".into())],
|
||||
body: vec![],
|
||||
};
|
||||
let mut cases = Vec::new();
|
||||
for evil in ["a\r\nX: y", "a\ny", "a\rb"] {
|
||||
cases.push(RtspRequest { target: evil.into(), ..base() });
|
||||
@@ -220,7 +246,13 @@ fn encode_refuses_header_injection() {
|
||||
}
|
||||
|
||||
fn method() -> impl Strategy<Value = Method> {
|
||||
prop_oneof![Just(Method::Options), Just(Method::Describe), Just(Method::Setup), Just(Method::Announce), Just(Method::Play)]
|
||||
prop_oneof![
|
||||
Just(Method::Options),
|
||||
Just(Method::Describe),
|
||||
Just(Method::Setup),
|
||||
Just(Method::Announce),
|
||||
Just(Method::Play)
|
||||
]
|
||||
}
|
||||
|
||||
proptest! {
|
||||
@@ -331,7 +363,11 @@ fn framer_cap_64k_plus_one() {
|
||||
|
||||
// One push over the cap.
|
||||
let mut f = RtspFramer::new();
|
||||
assert_too_large!(f.push(&vec![b'a'; MAX_RTSP_MESSAGE_BYTES + 1]), MAX_RTSP_MESSAGE_BYTES, MAX_RTSP_MESSAGE_BYTES + 1);
|
||||
assert_too_large!(
|
||||
f.push(&vec![b'a'; MAX_RTSP_MESSAGE_BYTES + 1]),
|
||||
MAX_RTSP_MESSAGE_BYTES,
|
||||
MAX_RTSP_MESSAGE_BYTES + 1
|
||||
);
|
||||
|
||||
// A whole message of exactly the cap is fine.
|
||||
let mut f = RtspFramer::new();
|
||||
@@ -355,10 +391,17 @@ fn framer_refuses_lying_content_length_early() {
|
||||
assert!(matches!(r, Err(Error::TooLarge { .. } | Error::Malformed { .. })), "{cl}: {r:?}");
|
||||
}
|
||||
let mut f = RtspFramer::new();
|
||||
assert_cap!(push_then_next(&mut f, &response("200 OK", &[("Content-Length", "65537")], b"")), MAX_RTSP_MESSAGE_BYTES);
|
||||
assert_cap!(
|
||||
push_then_next(&mut f, &response("200 OK", &[("Content-Length", "65537")], b"")),
|
||||
MAX_RTSP_MESSAGE_BYTES
|
||||
);
|
||||
for cl in ["abc", "-1", "1 2"] {
|
||||
let mut f = RtspFramer::new();
|
||||
assert_err!(push_then_next(&mut f, &response("200 OK", &[("Content-Length", cl)], b"")), Error::Malformed { .. }, "{cl}");
|
||||
assert_err!(
|
||||
push_then_next(&mut f, &response("200 OK", &[("Content-Length", cl)], b"")),
|
||||
Error::Malformed { .. },
|
||||
"{cl}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,7 +552,10 @@ fn host_capabilities() {
|
||||
let many = "a=fmtp:97 surround-params=21101\n".repeat(MAX_OPUS_CONFIGS + 1);
|
||||
assert_cap!(HostCapabilities::from_sdp(&sdp::parse_sdp(many.as_bytes()).unwrap()), MAX_OPUS_CONFIGS);
|
||||
let max = "a=fmtp:97 surround-params=21101\n".repeat(MAX_OPUS_CONFIGS);
|
||||
assert_eq!(HostCapabilities::from_sdp(&sdp::parse_sdp(max.as_bytes()).unwrap()).unwrap().opus_configs.len(), MAX_OPUS_CONFIGS);
|
||||
assert_eq!(
|
||||
HostCapabilities::from_sdp(&sdp::parse_sdp(max.as_bytes()).unwrap()).unwrap().opus_configs.len(),
|
||||
MAX_OPUS_CONFIGS
|
||||
);
|
||||
}
|
||||
|
||||
fn config() -> StreamConfig {
|
||||
@@ -557,7 +603,10 @@ fn announce_refuses_what_the_host_lacks() {
|
||||
assert_err!(sdp::build_announce(&config(), &no_v2), Error::Unsupported { .. });
|
||||
let mut no_av1 = host.clone();
|
||||
no_av1.av1 = false;
|
||||
assert_err!(sdp::build_announce(&StreamConfig { codec: VideoCodec::Av1, ..config() }, &no_av1), Error::Unsupported { .. });
|
||||
assert_err!(
|
||||
sdp::build_announce(&StreamConfig { codec: VideoCodec::Av1, ..config() }, &no_av1),
|
||||
Error::Unsupported { .. }
|
||||
);
|
||||
assert!(sdp::build_announce(&StreamConfig { codec: VideoCodec::Av1, ..config() }, &host).is_ok());
|
||||
}
|
||||
|
||||
@@ -572,7 +621,11 @@ fn describe_answer(cseq: u32, sdp: &str) -> Vec<u8> {
|
||||
fn setup_answer(cseq: u32, port: &str) -> Vec<u8> {
|
||||
response(
|
||||
"200 OK",
|
||||
&[("CSeq", &cseq.to_string()), ("Session", "DEADBEEFCAFE;timeout = 90"), ("Transport", &format!("server_port={port}"))],
|
||||
&[
|
||||
("CSeq", &cseq.to_string()),
|
||||
("Session", "DEADBEEFCAFE;timeout = 90"),
|
||||
("Transport", &format!("server_port={port}")),
|
||||
],
|
||||
b"",
|
||||
)
|
||||
}
|
||||
@@ -676,7 +729,10 @@ fn client_refuses_hostile_answers() {
|
||||
assert!(matches!(e, Error::Malformed { .. }), "CSeq mismatch: {e:?}");
|
||||
assert_eq!(s, RtspClientState::Failed);
|
||||
|
||||
let (e, s) = run_until_error(|i, n| if i == 1 { response("404 Not Found", &[("CSeq", &n.to_string())], b"") } else { good(i, n) });
|
||||
let (e, s) =
|
||||
run_until_error(
|
||||
|i, n| if i == 1 { response("404 Not Found", &[("CSeq", &n.to_string())], b"") } else { good(i, n) },
|
||||
);
|
||||
assert_eq!(e, Error::HostStatus { code: 404 });
|
||||
assert_eq!(s, RtspClientState::Failed);
|
||||
|
||||
@@ -712,7 +768,9 @@ fn client_answer_without_request() {
|
||||
|
||||
#[test]
|
||||
fn client_refuses_bad_setup() {
|
||||
for url in ["http://192.0.2.10:48010", "rtsp://192.0.2.10", "rtsp://:48010", "", "rtsp://h:99999", "rtsp://h:1\r\nX: y"] {
|
||||
for url in
|
||||
["http://192.0.2.10:48010", "rtsp://192.0.2.10", "rtsp://:48010", "", "rtsp://h:99999", "rtsp://h:1\r\nX: y"]
|
||||
{
|
||||
assert_err!(RtspClient::new(url, config()), Error::Malformed { .. }, "{url:?}");
|
||||
}
|
||||
for broken in [
|
||||
|
||||
Reference in New Issue
Block a user