src-tauri/ contained no HTTP mocking of any kind. Every test of the ~4,800-line
online adapter asserted on a constructed URL string; not one exercised a
response. So "works against both server generations" was not merely untested, it
was unfalsifiable.
Adds wiremock (a project dev-dependency, so no CI image change — the toolchain
rule is about system packages) and a FakeJellyfin fixture that reports a chosen
version. The repository it hands back resolves its capabilities from exactly that
string via the production path, so a test running against both generations is
running the real resolution rather than a stubbed one.
Eight cross-generation tests, each asserting on what the client actually put on
the wire or did with a response it actually received:
- every request carries Authorization: MediaBrowser and no X-Emby-Authorization
- a listing parses into domain items on both generations
- a type-filtered listing puts Recursive on the wire
- libraries resolve through the user-scoped route on both
- flipping user_scoped_item_routes really changes the request and still parses,
so the alternative shape is exercised rather than being untested code waiting
to be switched on
- favourites send Filters=IsFavorite and omit the type filter under All scope
- player-facing URLs carry ApiKey= and never api_key=
- capabilities come from the version the server reported
The auth test was verified to fail when the legacy header is reintroduced into
get_json_inner, so it is a guard rather than decoration.
HttpClient keeps https_only(true) in production; a #[cfg(test)] constructor
allows the plaintext loopback wiremock serves. Weakening the real one to make
testing possible would trade the thing that stops a downgrade putting a session
token in clear for the thing meant to protect it.
The rule this module states and follows: assert against a response from a mock
server, never against a mock that re-derives the thing under test. That is the
mistake the deleted online_integration_test.rs made, and it shipped a broken
download endpoint while staying green.
TRACES: UR-085 | DR-281 | IT-019, IT-020, IT-021, IT-022, IT-023, IT-024, IT-025, IT-026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
228 lines
8.2 KiB
Rust
228 lines
8.2 KiB
Rust
//! The online repository, exercised against a real HTTP server on both Jellyfin
|
|
//! generations.
|
|
//!
|
|
//! These are the tests DR-281 exists for: every assertion here is about what the
|
|
//! client actually put on the wire, or about what it did with a response it
|
|
//! actually received. Nothing here reimplements a URL builder.
|
|
//!
|
|
//! TRACES: UR-085 | DR-281
|
|
|
|
use super::server_fixture::{target, FakeJellyfin, BOTH_GENERATIONS, V10_11, V12};
|
|
use super::types::{GetItemsOptions, SearchScope};
|
|
use super::MediaRepository;
|
|
|
|
/// Jellyfin 12.0 disables `X-Emby-Authorization` by default — including on
|
|
/// upgraded servers, via a migration that flips `EnableLegacyAuthorization` to
|
|
/// false. `Authorization` with the same `MediaBrowser` scheme is ungated on both
|
|
/// generations, so there is one correct spelling rather than a branch.
|
|
///
|
|
/// This is the assertion that would have caught the breakage: it looks at the
|
|
/// header the server received, not at a string the client built.
|
|
///
|
|
/// TRACES: UR-085 | DR-287 | IT-019
|
|
#[tokio::test]
|
|
async fn every_request_authenticates_with_the_non_deprecated_header() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
let repo = fake.repository();
|
|
|
|
repo.get_libraries().await.expect("libraries");
|
|
|
|
let request = fake.only_request().await;
|
|
|
|
let auth = request
|
|
.headers
|
|
.get("authorization")
|
|
.unwrap_or_else(|| panic!("{version}: no Authorization header was sent"))
|
|
.to_str()
|
|
.expect("header is ascii");
|
|
|
|
assert!(
|
|
auth.starts_with("MediaBrowser "),
|
|
"{version}: Authorization must use the MediaBrowser scheme, got {auth:?}"
|
|
);
|
|
assert!(
|
|
auth.contains(r#"Token="token-abc""#),
|
|
"{version}: the token must reach the server, got {auth:?}"
|
|
);
|
|
assert!(
|
|
request.headers.get("x-emby-authorization").is_none(),
|
|
"{version}: X-Emby-Authorization is disabled by default on 12.0"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A listing must parse into domain items on both generations. `BaseItemDto` was
|
|
/// verified to be purely additive between 10.11.5 and 12.0, so one parse path is
|
|
/// correct for both — this is the test that would notice if that stopped holding.
|
|
///
|
|
/// TRACES: UR-007, UR-085 | DR-281 | IT-020
|
|
#[tokio::test]
|
|
async fn a_listing_parses_on_both_generations() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
let result = fake
|
|
.repository()
|
|
.get_items("lib-1", None)
|
|
.await
|
|
.unwrap_or_else(|e| panic!("{version}: listing failed: {e:?}"));
|
|
|
|
assert_eq!(result.items.len(), 1, "{version}");
|
|
assert_eq!(result.items[0].id, "item-1", "{version}");
|
|
assert_eq!(result.items[0].name, "A Film", "{version}");
|
|
}
|
|
}
|
|
|
|
/// Jellyfin 12.0 defaults `recursive` to true when the parent is a library
|
|
/// folder and `IncludeItemTypes` is set, where 10.11 listed immediate children —
|
|
/// the identical request, a different result set. The client must state it, so
|
|
/// that the two generations agree.
|
|
///
|
|
/// TRACES: UR-085 | DR-288 | IT-021
|
|
#[tokio::test]
|
|
async fn a_type_filtered_listing_states_recursive_on_the_wire() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
|
|
fake.repository()
|
|
.get_items(
|
|
"lib-1",
|
|
Some(GetItemsOptions {
|
|
include_item_types: Some(vec!["Movie".to_string()]),
|
|
..Default::default()
|
|
}),
|
|
)
|
|
.await
|
|
.expect("listing");
|
|
|
|
let sent = target(&fake.only_request().await);
|
|
assert!(
|
|
sent.contains("Recursive="),
|
|
"{version}: without an explicit Recursive the two generations disagree: {sent}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The library listing goes to the route the capabilities selected, and comes
|
|
/// back parsed. Both generations still serve the user-scoped family — only six
|
|
/// routes were removed in 12.0 and none of them are these.
|
|
///
|
|
/// TRACES: UR-007, UR-085 | DR-282 | IT-022
|
|
#[tokio::test]
|
|
async fn libraries_resolve_on_both_generations() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
let libraries = fake
|
|
.repository()
|
|
.get_libraries()
|
|
.await
|
|
.unwrap_or_else(|e| panic!("{version}: {e:?}"));
|
|
|
|
assert_eq!(libraries.len(), 1, "{version}");
|
|
assert_eq!(libraries[0].id, "lib-1", "{version}");
|
|
|
|
let sent = target(&fake.only_request().await);
|
|
assert!(sent.starts_with("/Users/user-1/Views"), "{version}: {sent}");
|
|
}
|
|
}
|
|
|
|
/// Flipping the user-scoped flag must actually change the wire request, and the
|
|
/// response must still parse. Nothing selects `false` today, so without this the
|
|
/// alternative route shape would be untested code waiting to be switched on.
|
|
///
|
|
/// TRACES: UR-085 | DR-282 | IT-023
|
|
#[tokio::test]
|
|
async fn the_alternative_route_shape_works_end_to_end() {
|
|
let fake = FakeJellyfin::start(V12).await;
|
|
|
|
let mut capabilities = super::capabilities::ServerCapabilities::from_reported(V12);
|
|
capabilities.user_scoped_item_routes = false;
|
|
let repo = fake.repository().with_capabilities(capabilities);
|
|
|
|
let result = repo.get_items("lib-1", None).await.expect("listing");
|
|
assert_eq!(result.items.len(), 1);
|
|
|
|
let sent = target(&fake.only_request().await);
|
|
assert!(sent.starts_with("/Items?"), "{sent}");
|
|
assert!(sent.contains("userId=user-1"), "{sent}");
|
|
assert!(!sent.contains("/Users/"), "{sent}");
|
|
}
|
|
|
|
/// Favourites carry the filter that makes them favourites, on both generations.
|
|
///
|
|
/// TRACES: UR-067, UR-085 | DR-281 | IT-024
|
|
#[tokio::test]
|
|
async fn favourites_filter_reaches_the_server() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
|
|
fake.repository()
|
|
.get_favorites(SearchScope::All, None)
|
|
.await
|
|
.expect("favourites");
|
|
|
|
let sent = target(&fake.only_request().await);
|
|
assert!(sent.contains("Filters=IsFavorite"), "{version}: {sent}");
|
|
assert!(
|
|
!sent.contains("IncludeItemTypes"),
|
|
"{version}: All scope must omit the type filter rather than send a \
|
|
union, which would drop every type nobody enumerated: {sent}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A stream URL is handed to mpv / ExoPlayer / an HTML5 `<video>`, none of which
|
|
/// can set a header — so its token must ride in the query string. `ApiKey` is
|
|
/// ungated on both generations and is what the server itself emits; `api_key` is
|
|
/// gated off by default on 12.0.
|
|
///
|
|
/// TRACES: UR-004, UR-085 | DR-287 | IT-025
|
|
#[tokio::test]
|
|
async fn player_facing_urls_carry_the_ungated_query_token() {
|
|
for version in BOTH_GENERATIONS {
|
|
let fake = FakeJellyfin::start(version).await;
|
|
let url = fake
|
|
.repository()
|
|
.get_audio_stream_url("track-1")
|
|
.await
|
|
.unwrap_or_else(|e| panic!("{version}: {e:?}"));
|
|
|
|
assert!(
|
|
url.contains("ApiKey=token-abc"),
|
|
"{version}: a player cannot send a header, so the token must be in \
|
|
the query — and spelled ApiKey: {url}"
|
|
);
|
|
assert!(
|
|
!url.contains("api_key="),
|
|
"{version}: api_key is disabled by default on 12.0: {url}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The capability resolution is driven by what the server reported, not by a
|
|
/// value a test poked in — this is what makes the other tests here meaningful.
|
|
///
|
|
/// TRACES: UR-085 | DR-280 | IT-026
|
|
#[tokio::test]
|
|
async fn capabilities_come_from_the_version_the_server_reported() {
|
|
use super::capabilities::ServerGeneration;
|
|
|
|
let old = FakeJellyfin::start(V10_11).await;
|
|
assert_eq!(
|
|
old.repository().capabilities().generation,
|
|
ServerGeneration::V10_11
|
|
);
|
|
|
|
let new = FakeJellyfin::start(V12).await;
|
|
assert_eq!(
|
|
new.repository().capabilities().generation,
|
|
ServerGeneration::V12Plus
|
|
);
|
|
assert!(
|
|
!new.repository()
|
|
.capabilities()
|
|
.supports_manifest_container_direct_play,
|
|
"12.0 makes manifest-container sources ineligible for direct play"
|
|
);
|
|
}
|