mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-27 19:35:06 +00:00
refactor(vaults): give the server handlers vault operations
This commit is contained in:
@@ -472,14 +472,20 @@ async def test_health_vault_probe_tolerates_api_vault_rejecting_the_probe(aiohtt
|
||||
assert checks["vault:t"]["status"] == "ok", checks["vault:t"]
|
||||
|
||||
|
||||
def test_health_warns_without_a_sqlite_vault_to_store_flags(monkeypatch) -> None:
|
||||
def test_health_warns_without_a_sqlite_vault_to_store_flags(monkeypatch, tmp_path) -> None:
|
||||
from unshackle.core.api.handlers import run_health_checks
|
||||
|
||||
monkeypatch.setattr(config, "proxy_providers", {})
|
||||
monkeypatch.setattr(
|
||||
config, "key_vaults", [{"type": "API", "name": "shared", "uri": "http://127.0.0.1:9", "token": "t"}]
|
||||
)
|
||||
assert {c["id"]: c for c in run_health_checks()}["bad_keys"]["status"] == "warn"
|
||||
checks = {c["id"]: c for c in run_health_checks()}
|
||||
assert (checks["bad_keys"]["status"], checks["vault:shared"]["status"]) == ("warn", "fail")
|
||||
|
||||
monkeypatch.setattr(config, "key_vaults", [{"type": "SQLite", "name": "local", "path": str(tmp_path / "k.db")}])
|
||||
checks = {c["id"]: c for c in run_health_checks()}
|
||||
assert checks["bad_keys"]["status"] == "ok" and "local" in checks["bad_keys"]["detail"]
|
||||
assert checks["vault:local"]["status"] == "ok"
|
||||
|
||||
monkeypatch.setattr(config, "key_vaults", [])
|
||||
assert {c["id"]: c for c in run_health_checks()}["bad_keys"]["status"] == "ok"
|
||||
|
||||
@@ -13,6 +13,7 @@ from uuid import UUID
|
||||
import click
|
||||
import pytest
|
||||
|
||||
from tests.core.key_resolver import vaults_of
|
||||
from tests.remote.key_source import one_title, remote_keys
|
||||
from tests.remote.sessions import session_entry
|
||||
from unshackle.core.api import handlers
|
||||
@@ -58,6 +59,7 @@ def test_server_vault_flag_posts_only_the_pair():
|
||||
|
||||
class _Vault:
|
||||
local = True
|
||||
name = "local"
|
||||
|
||||
def __init__(self):
|
||||
self.flagged: list = []
|
||||
@@ -78,7 +80,7 @@ def session(monkeypatch):
|
||||
monkeypatch.setattr(handlers, "get_validated_session", validated)
|
||||
monkeypatch.setattr(handlers, "require_authenticated", lambda s: None)
|
||||
vault = _Vault()
|
||||
monkeypatch.setattr(handlers, "load_server_vaults", lambda name: SimpleNamespace(vaults=[vault], service="SVC"))
|
||||
monkeypatch.setattr(handlers, "load_server_vaults", lambda name: vaults_of(vault, service="SVC"))
|
||||
return entry, vault
|
||||
|
||||
|
||||
@@ -229,20 +231,6 @@ def test_the_server_reads_the_head_of_a_one_file_track_with_drm(drm, head):
|
||||
)
|
||||
|
||||
|
||||
async def test_server_tells_a_remote_vault_only_when_it_served_the_pair(monkeypatch, session):
|
||||
entry, local = session
|
||||
bystander, source = _Vault(), _Vault()
|
||||
bystander.local = source.local = False
|
||||
bystander.name, source.name = "other", "sqlite"
|
||||
monkeypatch.setattr(
|
||||
handlers, "load_server_vaults", lambda name: SimpleNamespace(vaults=[local, bystander, source], service="SVC")
|
||||
)
|
||||
await handlers.session_bad_key_handler({"kid": KID.hex, "key": "v"}, "sess")
|
||||
assert local.flagged == [("SVC", KID, "v", "sqlite")]
|
||||
assert source.flagged == [("SVC", KID, "v", "sqlite")]
|
||||
assert bystander.flagged == []
|
||||
|
||||
|
||||
def test_resolve_server_keys_does_not_warn_for_clear_tracks(monkeypatch):
|
||||
"""A requested track the server lists in clear_tracks carries no DRM, so its
|
||||
missing keys are expected and draw no warning."""
|
||||
|
||||
@@ -255,19 +255,12 @@ async def test_the_server_answers_before_the_remote_vaults_take_the_keys(server,
|
||||
assert server.remote.get_key(LICENSED, "EXAMPLE") == KEY
|
||||
|
||||
|
||||
async def test_a_local_vault_that_cannot_answer_counts_as_holding_the_kid(server, monkeypatch) -> None:
|
||||
real = server.local.get_key
|
||||
|
||||
def down(kid: Any, service: str) -> Any:
|
||||
if kid == LICENSED:
|
||||
raise OSError("EXAMPLE vault file locked")
|
||||
return real(kid, service)
|
||||
|
||||
monkeypatch.setattr(server.local, "get_key", down)
|
||||
await handlers.session_keys_handler({"track_id": "v2", "keys": {LICENSED.hex: KEY, LATE.hex: KEY}}, "sess")
|
||||
async def test_a_client_cannot_replace_a_content_key_a_local_vault_holds(server) -> None:
|
||||
server.local.add_key("EXAMPLE", LICENSED, OTHER_KEY)
|
||||
await handlers.session_keys_handler({"track_id": "v2", "keys": {LICENSED.hex: KEY}}, "sess")
|
||||
await settled()
|
||||
assert server.local.get_key(LICENSED, "EXAMPLE") == OTHER_KEY
|
||||
assert server.remote.get_key(LICENSED, "EXAMPLE") is None
|
||||
assert server.remote.get_key(LATE, "EXAMPLE") == KEY
|
||||
|
||||
|
||||
async def test_the_server_answers_empty_when_it_stores_nothing(server, caplog) -> None:
|
||||
|
||||
Reference in New Issue
Block a user