[domistream] RTSP server: session state machine, DESCRIBE writer, strict ANNOUNCE parser, response encoder and request framer; test fixes (escaped CRLF in alloc_caps, CSeq test state, clippy)
This commit is contained in:
@@ -62,23 +62,12 @@ fn lying_inputs() -> Vec<Case> {
|
||||
));
|
||||
v.push((
|
||||
"rtsp server",
|
||||
b"ANNOUNCE x RTSP/1.0
|
||||
CSeq: 1
|
||||
Content-Length: 4294967295
|
||||
|
||||
abc"
|
||||
.to_vec(),
|
||||
b"ANNOUNCE x RTSP/1.0\r\nCSeq: 1\r\nContent-Length: 4294967295\r\n\r\nabc".to_vec(),
|
||||
rtsp_server_answers,
|
||||
));
|
||||
// ANNOUNCE: numbers far past any range, a line that claims nothing but is long, many unknown attributes.
|
||||
let mut announce = b"a=x-nv-video[0].clientViewportWd:99999999999999999999999999999999
|
||||
"
|
||||
.to_vec();
|
||||
announce.extend_from_slice(
|
||||
&b"a=u:1
|
||||
"
|
||||
.repeat(600),
|
||||
);
|
||||
// ANNOUNCE: a number far past any range, then more unknown attributes than the cap allows.
|
||||
let mut announce = b"a=x-nv-video[0].clientViewportWd:99999999999999999999999999999999\n".to_vec();
|
||||
announce.extend_from_slice(&b"a=u:1\n".repeat(600));
|
||||
v.push(("announce", announce, |b| common::implemented(&domistream::rtsp::server::parse_announce(b))));
|
||||
v.push(("rtsp framer", rtsp, |b| {
|
||||
let mut f = domistream::rtsp::RtspFramer::new();
|
||||
|
||||
@@ -249,6 +249,9 @@ fn client_stops_when_server_refuses_the_codec() {
|
||||
|
||||
// ================================================================================================ scripted requests
|
||||
|
||||
/// One scripted request.
|
||||
type Step = fn(&mut Script, &mut RtspServer) -> ServerReply;
|
||||
|
||||
/// Sends hand-made requests with counting CSeq values and, once known, the session id.
|
||||
struct Script {
|
||||
cseq: u32,
|
||||
@@ -314,7 +317,7 @@ impl Script {
|
||||
|
||||
/// Valid requests until the server expects `state`.
|
||||
fn advance_to(&mut self, s: &mut RtspServer, state: RtspServerState) {
|
||||
let steps: [(RtspServerState, fn(&mut Self, &mut RtspServer) -> ServerReply); 7] = [
|
||||
let steps: [(RtspServerState, Step); 7] = [
|
||||
(RtspServerState::Options, Self::options),
|
||||
(RtspServerState::Describe, Self::describe),
|
||||
(RtspServerState::Setup, |sc, s| sc.setup(s, "audio")),
|
||||
@@ -384,7 +387,6 @@ fn session_timeout_is_configurable() {
|
||||
|
||||
#[test]
|
||||
fn order_violations_get_455_and_change_nothing() {
|
||||
type Step = fn(&mut Script, &mut RtspServer) -> ServerReply;
|
||||
let describe: Step = Script::describe;
|
||||
let setup: Step = |sc, s| sc.setup(s, "audio");
|
||||
let announce: Step = |sc, s| sc.announce(s, &write_announce(&host_config()));
|
||||
@@ -440,7 +442,8 @@ fn options_at_any_time_and_setup_once_each() {
|
||||
|
||||
#[test]
|
||||
fn setup_targets_and_transport() {
|
||||
let cases: [(&str, &[(&str, &str)], u16); 9] = [
|
||||
type Case<'a> = (&'a str, &'a [(&'a str, &'a str)], u16);
|
||||
let cases: [Case<'_>; 9] = [
|
||||
("streamid=video/0/0", &[("Transport", "x")], 200),
|
||||
("rtsp://192.0.2.10:48010/streamid=video/0/0", &[("Transport", "x")], 200),
|
||||
("streamid=video", &[("Transport", "x")], 200),
|
||||
@@ -553,7 +556,7 @@ fn cseq_is_echoed_and_required() {
|
||||
assert_refused(&reply, 400);
|
||||
assert!(matches!(reply.error, Some(Error::Malformed { .. })), "{bad:?}: {reply:?}");
|
||||
}
|
||||
assert_eq!(s.state(), RtspServerState::Options);
|
||||
assert_eq!(s.state(), RtspServerState::Describe, "the accepted OPTIONS moved it; the refusals did not");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -748,14 +751,15 @@ fn describe_follows_the_offer() {
|
||||
|
||||
#[test]
|
||||
fn describe_refuses_what_the_client_would_refuse() {
|
||||
let mut bad = Vec::new();
|
||||
bad.push(OpusConfig { channels: 0, streams: 1, coupled_streams: 0, mapping: vec![] });
|
||||
bad.push(OpusConfig { channels: 2, streams: 0, coupled_streams: 0, mapping: vec![0, 0] });
|
||||
bad.push(OpusConfig { channels: 2, streams: 1, coupled_streams: 2, mapping: vec![0, 1] });
|
||||
bad.push(OpusConfig { channels: 2, streams: 1, coupled_streams: 1, mapping: vec![0] });
|
||||
bad.push(OpusConfig { channels: 2, streams: 1, coupled_streams: 1, mapping: vec![0, 2] });
|
||||
bad.push(OpusConfig { channels: 8, streams: 10, coupled_streams: 0, mapping: vec![0; 8] });
|
||||
bad.push(OpusConfig { channels: 2, streams: 12, coupled_streams: 1, mapping: vec![0, 10] });
|
||||
let bad = [
|
||||
OpusConfig { channels: 0, streams: 1, coupled_streams: 0, mapping: vec![] },
|
||||
OpusConfig { channels: 2, streams: 0, coupled_streams: 0, mapping: vec![0, 0] },
|
||||
OpusConfig { channels: 2, streams: 1, coupled_streams: 2, mapping: vec![0, 1] },
|
||||
OpusConfig { channels: 2, streams: 1, coupled_streams: 1, mapping: vec![0] },
|
||||
OpusConfig { channels: 2, streams: 1, coupled_streams: 1, mapping: vec![0, 2] },
|
||||
OpusConfig { channels: 8, streams: 10, coupled_streams: 0, mapping: vec![0; 8] },
|
||||
OpusConfig { channels: 2, streams: 12, coupled_streams: 1, mapping: vec![0, 10] },
|
||||
];
|
||||
for c in bad {
|
||||
let o = HostOffer { opus_configs: vec![c.clone()], ..offer() };
|
||||
assert_err!(build_describe(&o), Error::Malformed { .. }, "{c:?}");
|
||||
@@ -1254,7 +1258,9 @@ proptest! {
|
||||
/// Random request sequences: every answer parses and echoes CSeq, the status is one of the documented ones, the
|
||||
/// state only moves forward, and the events come at most once each, in order.
|
||||
#[test]
|
||||
fn server_random_sequences(steps in proptest::collection::vec((0u8..7, 0u8..6, 0u8..3, 0u8..3, any::<u32>()), 0..24)) {
|
||||
fn server_random_sequences(
|
||||
steps in proptest::collection::vec((0u8..7, 0u8..6, 0u8..3, 0u8..3, any::<u32>()), 0..24),
|
||||
) {
|
||||
let mut s = server();
|
||||
let id = s.session_id().to_string();
|
||||
let good_announce = write_announce(&host_config());
|
||||
@@ -1263,9 +1269,14 @@ proptest! {
|
||||
for (m, t, sess, body, cseq) in steps {
|
||||
let target = ["rtsp://192.0.2.10:48010", "streamid=audio/0/0", "streamid=video/0/0",
|
||||
"streamid=control/13/0", "streamid=bogus/0/0", "*"][usize::from(t)];
|
||||
let session = match sess { 1 => format!("Session: {id}\r\n"), 2 => "Session: nope\r\n".into(), _ => String::new() };
|
||||
let session = match sess {
|
||||
1 => format!("Session: {id}\r\n"),
|
||||
2 => "Session: nope\r\n".into(),
|
||||
_ => String::new(),
|
||||
};
|
||||
let body: &[u8] = match body { 1 => &good_announce, 2 => b"v=0\r\nx\r\n", _ => b"" };
|
||||
let method = ["OPTIONS", "DESCRIBE", "SETUP", "ANNOUNCE", "PLAY", "TEARDOWN", "GARBAGE GARBAGE"][usize::from(m)];
|
||||
let methods = ["OPTIONS", "DESCRIBE", "SETUP", "ANNOUNCE", "PLAY", "TEARDOWN", "GARBAGE GARBAGE"];
|
||||
let method = methods[usize::from(m)];
|
||||
let mut req = format!("{method} {target} RTSP/1.0\r\nCSeq: {cseq}\r\n{session}Transport: x\r\n");
|
||||
if !body.is_empty() {
|
||||
req.push_str(&format!("Content-Length: {}\r\n", body.len()));
|
||||
|
||||
Reference in New Issue
Block a user