diff --git a/.github/workflows/test-crates.yml b/.github/workflows/test-crates.yml index c914b6594..9d0e18b92 100644 --- a/.github/workflows/test-crates.yml +++ b/.github/workflows/test-crates.yml @@ -13,7 +13,10 @@ # proto3-zero cursor, manual skip/loop/shuffle/autoplay and # consecutive-log repetition regression checks, plus SACD # 2048/2064-sector TOC/frame/seek equivalence and scanner import/ -# failed-read preservation. ~5 min cold. +# failed-read preservation, plus the DLNA device-description +# tolerance suite (empty and relative SCPDURL/controlURL must +# still parse — the guard on qbz-cast's http =1.4.0 pin, #745). +# ~5 min cold. # qt-gate — the Qt frontend: the five static QML audits, `cargo test -p # qbz-qt`, the Slint-free dep-graph gate, and an OFFSCREEN BOOT of # debug AND release binaries (including process liveness). diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 14a203420..5d6494e52 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -2115,9 +2115,9 @@ dependencies = [ [[package]] name = "http" -version = "1.5.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" dependencies = [ "bytes", "itoa", @@ -4128,6 +4128,7 @@ version = "0.1.0" dependencies = [ "futures-util", "getrandom 0.4.3", + "http", "log", "mdns-sd", "rupnp", diff --git a/crates/qbz-cast/Cargo.toml b/crates/qbz-cast/Cargo.toml index 1d9ed8a35..c8d2798c9 100644 --- a/crates/qbz-cast/Cargo.toml +++ b/crates/qbz-cast/Cargo.toml @@ -18,6 +18,19 @@ tiny_http = "0.12" rupnp = { version = "3", features = ["full_device_spec"] } futures-util = "0.3" +# PINNED, do not bump without reading this (#745, 2.1.0 regression): +# rupnp parses a device description's SCPDURL / controlURL / eventSubURL as +# `http::uri::PathAndQuery`. http 1.5.0 rewrote that parser and now REJECTS +# two shapes 1.4.0 accepted -- an empty element (ErrorKind::Empty, printed as +# "empty string") and any relative URL without a leading slash +# (PathDoesNotStartWithSlash). Both are common in old UPnP firmware, so the +# bump made rupnp drop those renderers entirely: a KEF LSX gen 1 that worked +# in 2.0.2 (http 1.4.0) reported "Visible Renderers: 0" in 2.1.0. The pin is +# workspace-wide by unification and is guarded by +# tests/dlna_description_tolerance.rs -- if that suite fails, this pin was +# lifted. Drop it only once rupnp stops using PathAndQuery for relative URLs. +http = "=1.4.0" + # Serialization serde = { version = "1", features = ["derive"] } serde_json = "1" @@ -33,3 +46,6 @@ getrandom = "0.4" # Async runtime (for DLNA) tokio = { version = "1", features = ["rt", "sync"] } + +[dev-dependencies] +tokio = { version = "1", features = ["rt", "macros"] } diff --git a/crates/qbz-cast/src/dlna/device.rs b/crates/qbz-cast/src/dlna/device.rs index 886ac3cfa..fde5fed97 100644 --- a/crates/qbz-cast/src/dlna/device.rs +++ b/crates/qbz-cast/src/dlna/device.rs @@ -1,6 +1,6 @@ //! DLNA device connection and playback via AVTransport SOAP -use rupnp::http::Uri; +use http::Uri; use rupnp::{Device, Service}; use serde::{Deserialize, Serialize}; diff --git a/crates/qbz-cast/tests/dlna_description_tolerance.rs b/crates/qbz-cast/tests/dlna_description_tolerance.rs new file mode 100644 index 000000000..2d400948f --- /dev/null +++ b/crates/qbz-cast/tests/dlna_description_tolerance.rs @@ -0,0 +1,134 @@ +//! Regression gate for #745 — DLNA renderers vanished in 2.1.0. +//! +//! A KEF LSX (gen 1) answered the SSDP M-SEARCH but was dropped with +//! `Invalid response: empty string` while fetching its device description. +//! The cause is not the network: `rupnp` parses `SCPDURL` / `controlURL` / +//! `eventSubURL` as `http::uri::PathAndQuery`, and `http` 1.5.0 started +//! rejecting inputs that 1.4.0 accepted — an empty element, and any relative +//! URL without a leading slash. Both shapes are common in old UPnP firmware. +//! +//! These tests serve a description locally and assert the device still parses. +//! They fail with `http` 1.5.0 and pass with 1.4.0. + +use std::net::SocketAddr; +use std::thread::JoinHandle; + +/// Renderer description whose services carry EMPTY sub-URLs. +const EMPTY_SERVICE_URLS: &str = r#" + + 10 + + urn:schemas-upnp-org:device:MediaRenderer:1 + KEF LSX + KEF + LSX + uuid:00000000-0000-0000-0000-000000000745 + + + urn:schemas-upnp-org:service:AVTransport:1 + urn:upnp-org:serviceId:AVTransport + + /AVTransport/control + /AVTransport/event + + + urn:schemas-upnp-org:service:RenderingControl:1 + urn:upnp-org:serviceId:RenderingControl + + /RenderingControl/control + /RenderingControl/event + + + + +"#; + +/// Renderer description whose services carry RELATIVE sub-URLs (no leading +/// slash) — the other shape `http` 1.5.0 turned into a hard error. +const RELATIVE_SERVICE_URLS: &str = r#" + + 10 + + urn:schemas-upnp-org:device:MediaRenderer:1 + Legacy Renderer + Acme + Streamer + uuid:00000000-0000-0000-0000-000000000733 + + + urn:schemas-upnp-org:service:AVTransport:1 + urn:upnp-org:serviceId:AVTransport + MediaRenderer/AVTransport/desc.xml + MediaRenderer/AVTransport/control + MediaRenderer/AVTransport/event + + + urn:schemas-upnp-org:service:RenderingControl:1 + urn:upnp-org:serviceId:RenderingControl + MediaRenderer/RenderingControl/desc.xml + MediaRenderer/RenderingControl/control + MediaRenderer/RenderingControl/event + + + + +"#; + +/// Serve `body` once on an ephemeral loopback port, like the renderer would. +fn serve_once(body: &'static str) -> (SocketAddr, JoinHandle<()>) { + let server = tiny_http::Server::http("127.0.0.1:0").expect("bind loopback"); + let addr = server + .server_addr() + .to_ip() + .expect("loopback listener has an ip"); + + let handle = std::thread::spawn(move || { + if let Ok(request) = server.recv() { + let response = tiny_http::Response::from_string(body).with_header( + tiny_http::Header::from_bytes(&b"Content-Type"[..], &b"text/xml"[..]) + .expect("static header"), + ); + let _ = request.respond(response); + } + }); + + (addr, handle) +} + +async fn parse_description(body: &'static str) -> rupnp::Device { + let (addr, handle) = serve_once(body); + let url: http::Uri = format!("http://{addr}/description.xml") + .parse() + .expect("loopback url"); + + let device = rupnp::Device::from_url(url) + .await + .expect("a MediaRenderer description must parse"); + + handle.join().expect("description server thread"); + device +} + +fn has_service(device: &rupnp::Device, needle: &str) -> bool { + device + .services_iter() + .any(|service| service.service_type().to_string().contains(needle)) +} + +#[tokio::test] +async fn description_with_empty_service_urls_still_parses() { + let device = parse_description(EMPTY_SERVICE_URLS).await; + + assert_eq!(device.friendly_name(), "KEF LSX"); + assert!(has_service(&device, ":service:AVTransport:")); + assert!(has_service(&device, ":service:RenderingControl:")); +} + +#[tokio::test] +async fn description_with_relative_service_urls_still_parses() { + let device = parse_description(RELATIVE_SERVICE_URLS).await; + + assert_eq!(device.friendly_name(), "Legacy Renderer"); + assert!(has_service(&device, ":service:AVTransport:")); + assert!(has_service(&device, ":service:RenderingControl:")); +} diff --git a/scripts/cargo-test.sh b/scripts/cargo-test.sh index 1ab93a95f..24c365baf 100755 --- a/scripts/cargo-test.sh +++ b/scripts/cargo-test.sh @@ -15,6 +15,9 @@ # and pass (schema migration, accumulator: paused/seek/stall deltas add # nothing, natural/skip/stop/shutdown closes, orphan close on reopen, # paused writes nothing, clear + VACUUM, is_play/is_skip bounds). +# + the DLNA device-description tolerance suite (qbz-cast): a renderer whose +# SCPDURL/controlURL/eventSubURL is empty or relative must still parse. +# It is the guard on qbz-cast's `http = "=1.4.0"` pin (#745). # --workspace today = the 42 members of crates/Cargo.toml minus qbz-qt: the # audio/player/cache/DSD/disc/rip core, qbz-app/core/models/theme/i18n, # the Qobuz client and the source seam, Plex/Jellyfin/Subsonic + media @@ -130,6 +133,17 @@ cargo test --manifest-path crates/Cargo.toml -p qconnect-app --lib -- queue_reso cargo test --manifest-path crates/Cargo.toml -p qconnect-protocol --lib -- decoder::tests::controller_ cargo test --manifest-path crates/Cargo.toml -p qbz-log --lib -- repeat::tests:: +say "gate: DLNA device-description tolerance present and green (#745)" +# rupnp parses SCPDURL/controlURL/eventSubURL as http::uri::PathAndQuery, and +# http 1.5.0 started rejecting empty and non-slash-prefixed values that 1.4.0 +# accepted -- which silently dropped every renderer with that firmware shape +# (KEF LSX gen 1, "Visible Renderers: 0" in 2.1.0). qbz-cast pins http to +# =1.4.0; this suite is the guard that notices if the pin is ever lifted. +n=$(cargo test --manifest-path crates/Cargo.toml -p qbz-cast --test dlna_description_tolerance -- --list 2>/dev/null \ + | grep -c ': test$' || true) +(( n >= 2 )) || { echo "DLNA description tolerance suite has $n tests (expected >= 2)"; exit 1; } +cargo test --manifest-path crates/Cargo.toml -p qbz-cast --test dlna_description_tolerance + say "gate: qbzd resolves no Slint crate" hits=$(cargo tree --manifest-path crates/Cargo.toml -p qbzd -e normal \ | grep -E '\b(slint|qbz-ui|qbz-slint-common|qbz-dac-wizard) v' || true)