mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-01 21:45:10 +00:00
fix(remote): end a remote session from before its create to after its DELETE
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
|
||||
from collections.abc import Callable
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
from typing import Any, NoReturn
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from unshackle.core.api import handlers, key_policy
|
||||
from unshackle.core.api.handlers import Launched, SessionLaunch
|
||||
from unshackle.core.api.input_bridge import InputBridge
|
||||
from unshackle.core.api.key_policy import KeyPolicy
|
||||
from unshackle.core.api.session_store import SessionEntry
|
||||
from unshackle.core.remote_lifetime import RemoteSessionLifetime
|
||||
from unshackle.core.remote_protocol import LicensingMode, Licensor
|
||||
from unshackle.core.remote_service import RemoteClient
|
||||
|
||||
|
||||
def session_entry(**fields: Any) -> SessionEntry:
|
||||
@@ -59,3 +62,17 @@ def stub_service_build(monkeypatch: pytest.MonkeyPatch, build: Callable[[], Any]
|
||||
monkeypatch.setattr(key_policy, "load_service_config", lambda tag: {})
|
||||
monkeypatch.setattr(handlers, "load_full_cdm", lambda *a: None)
|
||||
monkeypatch.setattr(handlers, "instantiate_service", lambda *a, **k: build())
|
||||
|
||||
|
||||
def hold_session(service: Any, session_id: str | None = "sess") -> None:
|
||||
"""Give a remote client built without its constructor a session lifetime, with *session_id* open in it."""
|
||||
|
||||
def unreachable(*args: Any, **kwargs: Any) -> NoReturn:
|
||||
raise requests.ConnectionError("EXAMPLE server is down")
|
||||
|
||||
client = getattr(service, "client", None)
|
||||
if not isinstance(client, RemoteClient):
|
||||
client = SimpleNamespace(send=unreachable, timeout=1, tunnel=None)
|
||||
service.lifetime = RemoteSessionLifetime(client, lambda cache: None) # type: ignore[arg-type]
|
||||
if session_id:
|
||||
service.lifetime.adopt(service.lifetime.name(), session_id)
|
||||
|
||||
Reference in New Issue
Block a user