mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
88 lines
3.5 KiB
Python
88 lines
3.5 KiB
Python
"""The CDM catalogue: a device name's DRM system read from config, and what each built CDM object says it is.
|
|
|
|
The config peek, the loader and the CDM classes read one rule, so a device is the same system before
|
|
and after it loads.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from unshackle.core.api import server_keys
|
|
from unshackle.core.cdm.detect import is_playready_cdm, is_remote_cdm, is_widevine_cdm
|
|
from unshackle.core.cdm.loader import device_system, load_cdm
|
|
from unshackle.core.config import config
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
ENTRIES = [
|
|
({"type": "decrypt_labs", "secret": "s", "device_name": "SL2"}, "playready"),
|
|
({"type": "decrypt_labs", "secret": "s", "device_name": "ChromeCDM", "device_type": "PLAYREADY"}, "playready"),
|
|
({"type": "decrypt_labs", "secret": "s", "device_name": "L1"}, "widevine"),
|
|
({"type": "custom_api", "host": "http://h.invalid", "device": {"type": "PLAYREADY", "name": "pr"}}, "playready"),
|
|
({"type": "custom_api", "host": "http://h.invalid", "device": {"name": "SL3000"}}, "playready"),
|
|
({"type": "custom_api", "host": "http://h.invalid", "device": {"name": "ChromeCDM"}}, "widevine"),
|
|
({"Device Type": "PLAYREADY", "host": "http://h.invalid", "secret": "s", "device_name": "d"}, "playready"),
|
|
(
|
|
{
|
|
"device_type": "ANDROID",
|
|
"system_id": 1,
|
|
"security_level": 3,
|
|
"host": "http://h.invalid",
|
|
"secret": "s",
|
|
"device_name": "SLOT",
|
|
},
|
|
"widevine",
|
|
),
|
|
]
|
|
|
|
|
|
def app_config(tmp_path, entries=(), cdm=None):
|
|
"""A config view with ``entries`` as its remote_cdm and ``tmp_path`` as both device folders."""
|
|
folders = SimpleNamespace(prds=tmp_path / "prd", wvds=tmp_path / "wvd")
|
|
folders.prds.mkdir(exist_ok=True)
|
|
folders.wvds.mkdir(exist_ok=True)
|
|
return SimpleNamespace(remote_cdm=list(entries), directories=folders, cdm=cdm or {})
|
|
|
|
|
|
def test_the_server_settles_a_service_on_its_remote_device_system(tmp_path):
|
|
entry = {"name": "x", "type": "decrypt_labs", "secret": "s", "device_name": "SL3000"}
|
|
assert (
|
|
server_keys.detect_cdm_type_for_service("EXAMPLE", app_config(tmp_path, [entry], {"EXAMPLE": "x"}))
|
|
== "playready"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("folder", "suffix", "system"),
|
|
[("prd", "prd", "playready"), ("wvd", "prd", "playready"), ("wvd", "wvd", "widevine")],
|
|
)
|
|
def test_a_local_file_names_its_system(folder, suffix, system, tmp_path):
|
|
view = app_config(tmp_path)
|
|
(tmp_path / folder / f"x.{suffix}").write_bytes(b"")
|
|
assert device_system("x", view) == system
|
|
|
|
|
|
def test_an_unknown_name_is_no_device(tmp_path, monkeypatch):
|
|
view = app_config(tmp_path)
|
|
assert device_system("x", view) is None
|
|
monkeypatch.setattr(config, "remote_cdm", [])
|
|
monkeypatch.setattr(config, "directories", view.directories)
|
|
with pytest.raises(ValueError, match="does not exist"):
|
|
load_cdm("x")
|
|
|
|
|
|
def test_library_cdms_are_known_by_class():
|
|
from pyplayready.cdm import Cdm as PlayReadyCdm
|
|
from pyplayready.remote.remotecdm import RemoteCdm as PlayReadyRemoteCdm
|
|
from pywidevine.cdm import Cdm as WidevineCdm
|
|
from pywidevine.remotecdm import RemoteCdm as WidevineRemoteCdm
|
|
|
|
local_pr, remote_wv = object.__new__(PlayReadyCdm), object.__new__(WidevineRemoteCdm)
|
|
assert is_playready_cdm(local_pr) and not is_remote_cdm(local_pr)
|
|
assert is_widevine_cdm(object.__new__(WidevineCdm))
|
|
assert is_widevine_cdm(remote_wv) and is_remote_cdm(remote_wv)
|
|
assert is_remote_cdm(object.__new__(PlayReadyRemoteCdm))
|