test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
+1 -140
View File
@@ -3,8 +3,6 @@
from __future__ import annotations
import json
import threading
import time
from types import SimpleNamespace
from typing import Any
from uuid import UUID
@@ -15,15 +13,11 @@ from pywidevine import DeviceTypes
from pywidevine.pssh import PSSH
from tests.remote.sessions import hold_session, launch_session, session_entry
from tests.remote.unit.test_tunnel import wait_until
from unshackle.core.api import handlers, key_policy, server_keys
from unshackle.core.api.errors import APIError
from unshackle.core.api.input_bridge import InputBridge
from unshackle.core.cdm.client_relay import ClientDeviceCdm, answer_cdm_call
from unshackle.core.launch import served_context
from unshackle.core.remote_protocol import APIErrorCode, AuthStatus, LicensingMode, Licensor
from unshackle.core.run_plan import served_plan
from unshackle.core.utils.click_types import ContextData
from unshackle.core.remote_protocol import APIErrorCode, LicensingMode, Licensor
pytestmark = pytest.mark.unit
@@ -107,47 +101,6 @@ def test_the_client_refuses_a_challenge_for_the_other_drm_system() -> None:
assert "not a playready device" in answer["error"]
def attached_channel(bridge: InputBridge) -> list[Any]:
"""Attach a session channel that takes every ask; the asks it took."""
offered: list[Any] = []
bridge.channel = SimpleNamespace(attached=True, offer=lambda ask: offered.append(ask) or True) # type: ignore[assignment]
return offered
def wait_offered(offered: list[Any]) -> Any:
assert wait_until(lambda: offered, 5), "the bridge offered no ask to the channel"
return offered[0]
def test_a_cdm_call_after_authentication_leaves_the_status_alone() -> None:
bridge = InputBridge()
bridge.login_status = AuthStatus.AUTHENTICATED
offered = attached_channel(bridge)
result: list[dict] = []
worker = threading.Thread(target=lambda: result.append(bridge.request_cdm({"op": "challenge"}, timeout=5)))
worker.start()
ask = wait_offered(offered)
assert ask.cdm_call == {"op": "challenge"}
assert bridge.answer(ask.id, json.dumps({"session": "s", "challenge": "Yw=="}))
worker.join(timeout=2)
assert result == [{"session": "s", "challenge": "Yw=="}]
assert bridge.login_status is AuthStatus.AUTHENTICATED
assert bridge.get_pending_ask() is None
@pytest.mark.parametrize(
("answer", "message"),
[("not json", "update unshackle"), (json.dumps({"error": "no local CDM is loaded"}), "no local CDM")],
)
def test_a_bad_or_refused_answer_stops_the_service(answer: str, message: str) -> None:
bridge = InputBridge()
threading.Timer(0.1, lambda: bridge.submit_response(answer)).start()
with pytest.raises(RuntimeError, match=message):
bridge.request_cdm({"op": "keys"}, timeout=5)
def test_the_overlay_keeps_only_the_client_identity() -> None:
server = {"esn": "SERVER", "Kpe": "server-kpe", "esn_map": {7000: "server-template"}, "endpoints": {"a": "b"}}
merged, identity = handlers.client_config_overlay(
@@ -214,45 +167,6 @@ def test_a_relaying_client_gets_a_stand_in_with_its_device_facts(monkeypatch: py
assert built["params"]["client_identity"] is True
def test_an_answered_call_is_no_longer_pending_before_the_service_wakes(monkeypatch: pytest.MonkeyPatch) -> None:
bridge = InputBridge()
release = threading.Event()
real_open = bridge._open
def open_slowly(prompt: str, cdm_call: Any = None) -> Any:
ask = real_open(prompt, cdm_call)
real_wait = ask.answered.wait
def slow_wait(timeout: float) -> bool:
release.wait(5) # hold the service thread asleep after the answer arrives
return real_wait(timeout)
ask.answered.wait = slow_wait # type: ignore[method-assign]
return ask
monkeypatch.setattr(bridge, "_open", open_slowly)
worker = threading.Thread(target=lambda: bridge.request_cdm({"op": "challenge"}, timeout=5))
worker.start()
for _ in range(100):
if bridge.get_pending_ask():
break
time.sleep(0.01)
assert bridge.submit_response(json.dumps({"session": "s", "challenge": "Yw=="}))
assert bridge.get_pending_ask() is None
assert bridge.submit_response("{}") is False
release.set()
worker.join(timeout=2)
def test_a_lent_server_device_marks_the_stand_in() -> None:
server = object()
cdm = ClientDeviceCdm(DirectBridge(FakeWidevineCdm()), is_playready=True, server_device=lambda: server)
assert cdm.lent is False
assert cdm.lend_server_device() is server
assert cdm.lent is True
def test_a_lent_device_session_never_licenses_live() -> None:
refusal = server_keys.live_licence_refusal(session_entry(licensing=LicensingMode(Licensor.LENT_DEVICE)), object())
assert refusal is not None
@@ -399,13 +313,6 @@ def test_a_server_device_option_takes_the_first_listed_device_of_a_dual_entry(
assert devices == [loaded]
@pytest.mark.parametrize(
("value", "requested"), [(True, True), ("false", False), ("0", False), ("yes", True), (False, False)]
)
def test_a_server_device_option_counts_as_the_service_casts_it(value: Any, requested: bool) -> None:
assert handlers.server_device_requested(ServerSideService, {"service_params": {"server_side": value}}) is requested
@pytest.mark.parametrize(("server_side", "cdm_type"), [(True, None), (False, "widevine")])
def test_a_track_listing_with_a_server_device_option_ignores_the_client_system(
monkeypatch: pytest.MonkeyPatch, server_side: bool, cdm_type: str | None
@@ -426,13 +333,6 @@ def test_a_track_listing_with_a_server_device_option_ignores_the_client_system(
assert loaded == [cdm_type]
def test_a_client_map_entry_replaces_the_server_entry_of_the_same_number() -> None:
merged, _ = handlers.client_config_overlay(
{"esn_map": {4464: "server-template", 7000: "other"}}, ("esn_map",), {"esn_map": {"4464": "client-template"}}
)
assert merged["esn_map"] == {7000: "other", "4464": "client-template"}
def lent_device_session() -> Any:
return session_entry(
licensing=LicensingMode(Licensor.LENT_DEVICE),
@@ -495,45 +395,6 @@ def test_a_lent_device_without_the_vault_grant_asks_the_server_for_no_key() -> N
svc.license_track(track, None)
@pytest.mark.parametrize("params", [{}, {"quality": None}])
def test_every_service_context_defaults_quality_to_a_list(params: Any) -> None:
parent = served_context(ContextData(config={}, cdm=None, proxy_providers=[]), served_plan(params), {})
assert parent.params["quality"] == []
def test_a_call_no_client_fetches_fails_fast_and_restores_the_status() -> None:
bridge = InputBridge()
bridge.login_status = AuthStatus.AUTHENTICATED
started = time.monotonic()
with pytest.raises(TimeoutError, match="none is listening"):
bridge.request_cdm({"op": "challenge"}, timeout=30, pickup=0.2)
assert time.monotonic() - started < 5
assert bridge.login_status is AuthStatus.AUTHENTICATED
assert bridge.get_pending_ask() is None
def test_a_call_the_channel_took_gets_the_full_answer_window() -> None:
bridge = InputBridge()
offered = attached_channel(bridge)
result: list[dict] = []
worker = threading.Thread(target=lambda: result.append(bridge.request_cdm({"op": "keys"}, timeout=5, pickup=0.3)))
worker.start()
ask = wait_offered(offered)
time.sleep(0.6) # past the pickup window: a call the channel took must still wait for its answer
assert bridge.answer(ask.id, json.dumps({"keys": []}))
worker.join(timeout=2)
assert result == [{"keys": []}]
def test_cancel_wakes_a_call_waiting_for_a_client() -> None:
bridge = InputBridge()
threading.Timer(0.1, bridge.cancel).start()
started = time.monotonic()
with pytest.raises(RuntimeError, match="cancelled"):
bridge.request_cdm({"op": "challenge"}, timeout=30, pickup=20)
assert time.monotonic() - started < 5
@pytest.mark.parametrize(
("fields", "forbidden"),
[