fix(remote): stop at the licence step when a licence fails, falling back only to the service's cdm entry

This commit is contained in:
imSp4rky
2026-12-04 16:31:28 -07:00
parent dd524f2cb2
commit 3bdca22bc7
10 changed files with 355 additions and 48 deletions
@@ -17,7 +17,6 @@ from tests.remote.key_source import remote_keys
from tests.remote.sessions import hold_session
from unshackle.core.api.errors import categorize_exception
from unshackle.core.remote_protocol import APIErrorCode, LicensingMode, Licensor
from unshackle.core.title_source import HeldKeys
pytestmark = pytest.mark.unit
@@ -123,7 +122,7 @@ def test_a_refused_relayed_licence_raises_a_click_exception_with_the_server_mess
assert not [r for r in caplog.records if r.levelname == "ERROR"]
def test_a_refused_server_cdm_licence_logs_one_warning(caplog):
def test_a_refused_server_cdm_licence_is_one_drm_error_line(caplog):
from unshackle.core.remote_service import RemoteError
svc = _service("widevine", {})
@@ -134,8 +133,12 @@ def test_a_refused_server_cdm_licence_logs_one_warning(caplog):
svc.client.post = refuse
track = SimpleNamespace(id="vid", drm=[_Widevine()])
assert svc.license_track(track, None) == HeldKeys()
assert [r.levelname for r in caplog.records if r.levelname in ("WARNING", "ERROR")] == ["WARNING"]
with pytest.raises(click.ClickException) as raised:
svc.license_track(track, None)
assert str(raised.value) == "The server CDM licence for track vid failed: Server error [SERVICE_ERROR]: refused"
assert raised.value.error_code == APIErrorCode.DRM_ERROR # type: ignore[attr-defined]
assert not [r for r in caplog.records if r.levelname in ("WARNING", "ERROR")]
def test_the_kid_dl_needs_goes_to_the_server():
@@ -148,7 +151,7 @@ def test_the_kid_dl_needs_goes_to_the_server():
def test_the_header_of_the_drm_dl_licenses_goes_before_the_tracks():
svc = _service("widevine", {"keys": {}})
svc = _service("widevine", {"keys": {KID.hex: "k"}})
later = _Widevine()
later.pssh = SimpleNamespace(dumps=lambda: "LATER")
@@ -157,11 +160,14 @@ def test_the_header_of_the_drm_dl_licenses_goes_before_the_tracks():
assert svc.client.posts[0]["pssh"] == "LATER"
def test_a_track_with_no_header_sends_nothing_and_gets_no_keys():
def test_a_track_with_no_header_sends_nothing_and_is_a_drm_error():
svc = _service("widevine", {})
track = SimpleNamespace(id="vid", drm=[])
assert svc.license_track(track, None) == HeldKeys()
with pytest.raises(click.ClickException, match="^Track vid has no PSSH to send to the server CDM$") as raised:
svc.license_track(track, None)
assert raised.value.error_code == APIErrorCode.DRM_ERROR # type: ignore[attr-defined]
assert svc.client.posts == []