refactor(remote): hold who licenses a remote session as one licensing mode

This commit is contained in:
imSp4rky
2026-11-29 10:16:08 -07:00
parent d4af4c77f4
commit efd8ca65c7
18 changed files with 458 additions and 160 deletions
+37 -1
View File
@@ -13,7 +13,7 @@ from unshackle.core.api.errors import APIError
from unshackle.core.api.key_policy import KeyPolicy
from unshackle.core.api.session_store import get_session_store
from unshackle.core.config import config
from unshackle.core.remote_protocol import AuthStatus
from unshackle.core.remote_protocol import AuthStatus, LicensingMode, Licensor
@pytest.fixture
@@ -163,6 +163,42 @@ def test_a_session_keeps_identity_keys_from_the_client_unless_the_identity_is_th
assert sent_back == returned
def test_a_service_on_the_lent_device_makes_a_lent_device_session(server, monkeypatch):
class Service(_Service):
_input_bridge = log = cache = None
ctx = SimpleNamespace(obj=SimpleNamespace(cdm=SimpleNamespace(lent=True)))
def authenticate(self, cookies, credential):
self.cache.get("keys/device1").set("identity")
monkeypatch.setattr(handlers, "validate_service", lambda service, request=None: service)
monkeypatch.setattr(handlers, "resolve_handler_proxy", lambda *args: (None, []))
monkeypatch.setattr(handlers, "server_account_for", lambda *args: False)
monkeypatch.setattr(handlers, "request_policy", lambda request: KeyPolicy({"server_vault": True}))
monkeypatch.setattr(handlers, "choose_session_cdm", lambda *args: (False, None))
monkeypatch.setattr(handlers.Services, "load", lambda service: Service)
monkeypatch.setattr(handlers, "create_service_instance", lambda *args, **kwargs: (Service(), "x", None))
async def run():
data = {"service": "EXAMPLE", "title_id": "t", "cookies": "x", "cdm_type": "widevine", "cdm_relay": True}
reply = json.loads((await handlers.session_create_handler(data)).body)
session = get_session_store().peek(reply["session_id"])
try:
for _ in range(250):
if session.auth_status != AuthStatus.AUTHENTICATING:
break
await asyncio.sleep(0.02)
return reply, session, set(handlers.collect_cache_files(session.cache_tag))
finally:
await get_session_store().delete(session.session_id)
reply, session, cache = asyncio.run(run())
assert session.licensing == LicensingMode(Licensor.LENT_DEVICE, server_vault=True)
assert (reply["server_cdm"], reply["server_device"], reply["server_vault"]) == (False, True, True)
assert "keys/device1" not in cache
def test_a_reload_checks_key_devices_against_the_new_config(server, monkeypatch):
monkeypatch.setattr(handlers.Services, "get_tags", staticmethod(lambda: ["EXAMPLE"]))
fresh = SimpleNamespace(remote_cdm=[{"name": "new_remote", "device_type": "PLAYREADY"}])