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
+2 -111
View File
@@ -1,5 +1,4 @@
import logging
import threading
from pathlib import Path
from types import SimpleNamespace
from uuid import UUID
@@ -10,9 +9,9 @@ from tests.core.key_resolver import MemoryVault, key_table, resolver, vaults_of
from unshackle.core.drm import key_resolution
from unshackle.core.drm.key_resolution import ContentKeyResolver
from unshackle.core.title_source import HeldKeys, KeyBatch
from unshackle.core.vault import RateLimited, vault_session
from unshackle.core.vault import RateLimited
from unshackle.core.vaults import Vaults
from unshackle.vaults.API import API, Exceptions
from unshackle.vaults.API import API
from unshackle.vaults.HTTP import HTTP
from unshackle.vaults.SQLite import SQLite
@@ -189,22 +188,6 @@ def test_segment_decrypted_track_flags_and_raises(tmp_path: Path, monkeypatch: p
assert local.is_bad_key(KID, BAD)
def test_downloaders_route_through_the_hook(monkeypatch: pytest.MonkeyPatch) -> None:
"""Every real decrypt site calls decrypt_track, so the dl hook sees it."""
import inspect
from unshackle.core.manifests import dash, hls, ism, segment_pipeline, url
from unshackle.core.tracks import track
for module in (segment_pipeline, hls):
assert "decrypt_track(" in inspect.getsource(module), module.__name__
for module in (dash, hls, ism, url):
assert "complete_track(" in inspect.getsource(module), module.__name__
for module in (dash, hls, ism, segment_pipeline, track, url):
src = inspect.getsource(module)
assert "drm.decrypt(save_path)" not in src and "drm.decrypt(merged_path)" not in src, module.__name__
def test_every_poisoned_vault_is_burned_then_the_cdm_answers(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
local = SQLite("local", tmp_path / "local.db")
poisoned = [Remote(f"poisoned{i}", tmp_path / f"p{i}.db") for i in range(3)]
@@ -253,45 +236,6 @@ def test_kv_copy_never_moves_the_flag_table(tmp_path: Path) -> None:
assert list(dst.get_keys("SVC")) == [(KID.hex, GOOD)]
def test_retry_takes_the_next_parallel_answer_without_a_new_request(tmp_path: Path) -> None:
from tests.core.test_vaults_lookup import FakeVault
started, release = threading.Event(), threading.Event()
class Fast(FakeVault):
def get_key(self, kid: UUID | str, service: str) -> str | None:
# answer only once the slow query runs, or the pool shutdown cancels it before it starts
started.wait(5)
return super().get_key(kid, service)
class Slow(FakeVault):
def get_key(self, kid: UUID | str, service: str) -> str | None:
started.set()
release.wait(5)
return super().get_key(kid, service)
local = SQLite("local", tmp_path / "local.db")
fast, slow = Fast("fast", BAD), Slow("slow", GOOD)
vaults = Vaults("SVC")
vaults.vaults = [local, fast, slow]
landed = threading.Event()
offer = vaults.offer
def offered(kid: UUID | str, key: str, source: object) -> None:
offer(kid, key, source) # type: ignore[arg-type]
if source is slow:
landed.set()
vaults.offer = offered # type: ignore[method-assign]
assert vaults.get_key(KID) == (BAD, fast)
vaults.flag_bad_key(KID, BAD)
release.set()
assert landed.wait(5)
assert vaults.get_key(KID) == (GOOD, slow)
assert fast.calls == 1 and slow.calls == 1
@pytest.mark.parametrize("replace", [False, True])
def test_cdm_returning_the_flagged_key_clears_the_flag(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture, replace: bool
@@ -461,16 +405,6 @@ def test_an_unkeyed_kid_the_file_uses_is_licensed_before_the_decrypt(
assert drm.decrypted_with == [{KID: GOOD}]
def test_drm_without_content_keys_still_decrypts(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""HLS AES-128 ClearKey has no KID:KEY map; the hook must pass it straight through."""
keys = make_resolver(monkeypatch, Vaults("SVC"))
path = tmp_path / "video.ts"
path.write_bytes(b"cipher")
calls: list[Path] = []
keys.decrypt_verified(SimpleNamespace(decrypt=calls.append), path)
assert calls == [path]
def test_flag_on_a_read_only_vault_keeps_its_rows(tmp_path: Path) -> None:
ro = SQLite("ro", tmp_path / "ro.db", no_push=True)
ro.add_key("SVC", KID, BAD)
@@ -812,19 +746,6 @@ def test_a_clear_file_judges_and_copies_no_vault_key(tmp_path: Path, monkeypatch
assert not local.is_bad_key(KID, BAD)
def test_flagged_pair_warns_once_per_vault(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
local = SQLite("local", tmp_path / "local.db")
poisoned = Remote("poisoned", tmp_path / "poisoned.db")
poisoned.add_key("SVC", KID, BAD)
local.flag_bad_key("SVC", KID, BAD, "poisoned")
vaults = Vaults("SVC")
vaults.vaults = [local, poisoned]
with caplog.at_level(logging.WARNING, logger="unshackle.core.vaults"):
for _ in range(3):
assert vaults.get_key(KID) == (None, None)
assert sum("flagged bad, skipping" in r.getMessage() for r in caplog.records) == 1
def test_add_key_refuses_a_flagged_pair_with_a_dashed_kid(tmp_path: Path) -> None:
local = SQLite("local", tmp_path / "local.db")
local.flag_bad_key("SVC", KID, BAD, "poisoned")
@@ -942,18 +863,6 @@ def test_cache_resolved_keys_skips_a_key_a_local_vault_holds(tmp_path: Path, cap
assert [r.getMessage() for r in caplog.records if r.name == "download"] == ["Cached 1 Key to 1/1 Vaults"]
def test_api_vault_does_not_shrink_the_batch_on_429(monkeypatch: pytest.MonkeyPatch) -> None:
api = API("vault", "https://vault.example/", "tok")
posts: list[str] = []
limited = SimpleNamespace(status_code=429)
monkeypatch.setattr(api.session, "post", lambda url, **kw: posts.append(url) or limited)
with pytest.raises(Exceptions.TooManyRequests):
api.add_keys("SVC", {KID: GOOD})
assert len(posts) == 1
def test_http_vault_does_not_fall_back_to_single_inserts_on_429(monkeypatch: pytest.MonkeyPatch) -> None:
vault = HTTP("vault", "https://vault.example/", password="tok", api_mode="json")
posts: list[str] = []
@@ -966,12 +875,6 @@ def test_http_vault_does_not_fall_back_to_single_inserts_on_429(monkeypatch: pyt
assert len(posts) == 1
def test_vault_session_retries_429_but_not_a_dead_vault() -> None:
retry = vault_session(10).get_adapter("https://vault.example").max_retries
assert retry.status_forcelist == [429]
assert (retry.connect, retry.read, retry.other) == (0, 0, 0)
def test_an_unreachable_vault_costs_one_attempt_per_run(monkeypatch: pytest.MonkeyPatch) -> None:
import requests
@@ -996,15 +899,3 @@ def test_an_unreachable_vault_costs_one_attempt_per_run(monkeypatch: pytest.Monk
assert vaults.get_key(SIBLING) == (None, None)
assert vaults.add_keys({KID: GOOD}) == 0
assert calls == ["https://api.example/svc/" + KID.hex]
def test_a_vault_still_rate_limited_is_not_used_again(monkeypatch: pytest.MonkeyPatch) -> None:
calls: list[str] = []
api = API("api", "https://api.example/", "tok")
monkeypatch.setattr(api.session, "get", lambda url, **kw: calls.append(url) or SimpleNamespace(status_code=429))
vaults = Vaults("SVC")
vaults.vaults = [api]
assert vaults.get_key(KID) == (None, None)
assert vaults.get_key(SIBLING) == (None, None)
assert calls == ["https://api.example/svc/" + KID.hex]