feat(remote)!: make remote serve WebSocket-only and refuse older clients with CLIENT_OUTDATED

This commit is contained in:
imSp4rky
2026-12-05 09:47:22 -07:00
parent 641623590d
commit 00ad15527c
62 changed files with 657 additions and 2098 deletions
+5 -26
View File
@@ -16,13 +16,12 @@ import requests
from aiohttp import WSMsgType, web
from click.testing import CliRunner
from tests.remote.sessions import hold_session
from tests.remote.unit.test_session_reopen import make_service
from unshackle.core import remote_service
from unshackle.core.api import handlers
from unshackle.core.api.errors import APIError, APIErrorCode
from unshackle.core.api.routes import setup_routes
from unshackle.core.remote_channel import PollingChannel, ServerMessages, WebSocketChannel
from unshackle.core.remote_channel import ServerMessages, WebSocketChannel
from unshackle.core.remote_protocol import AuthStatus
from unshackle.core.remote_service import RemoteClient, RemoteError, RemoteService
@@ -111,7 +110,6 @@ def test_malformed_titles_from_the_server_are_one_remote_error(answer: dict[str,
service.service_tag = "EXAMPLE"
service.title_id = "t"
service.session_call = lambda call: answer # type: ignore[method-assign]
service.drain_server_logs = lambda: None # type: ignore[method-assign]
with pytest.raises(RemoteError):
service.get_titles()
@@ -125,7 +123,6 @@ def test_malformed_tracks_from_the_server_are_one_remote_error(answer: dict[str,
service._title_alias = {}
service.server_draining = lambda: False # type: ignore[method-assign]
service.session_call = lambda call: answer # type: ignore[method-assign]
service.drain_server_logs = lambda: None # type: ignore[method-assign]
with pytest.raises(RemoteError):
service.get_tracks(Movie(id_="title-1", service=RemoteService, name="Name"))
@@ -239,18 +236,6 @@ def test_server_text_loses_its_control_characters() -> None:
assert "\x1b" not in error.message and "\n" not in error.message and "\r" not in error.message
def test_relayed_server_logs_lose_their_control_characters(monkeypatch: pytest.MonkeyPatch) -> None:
service = RemoteService.__new__(RemoteService)
hold_session(service, "sid")
seen: list[str] = []
service.log = SimpleNamespace(log=lambda level, message: seen.append(message)) # type: ignore[assignment]
service.client = SimpleNamespace(
get_optional=lambda _: {"logs": [{"seq": 1, "level": "INFO", "message": "a\x1b[2Jb\nc"}], "last_seq": 1}
)
PollingChannel(ServerMessages(service)).drain_logs()
assert seen == ["a[2Jb\nc"]
def test_a_relayed_login_prompt_loses_its_control_characters() -> None:
service = RemoteService.__new__(RemoteService)
asked: list[tuple[str, str | None]] = []
@@ -286,7 +271,7 @@ def channel_logging_to(seen: list[str]) -> WebSocketChannel:
service = make_service()
service.log = SimpleNamespace(log=lambda level, message: seen.append(message)) # type: ignore[assignment]
messages = ServerMessages(service)
return WebSocketChannel(messages, PollingChannel(messages))
return WebSocketChannel(messages)
@pytest.mark.parametrize("seq", ["x", "2", None, [1], {"a": 1}, float("inf")])
@@ -298,15 +283,10 @@ async def test_a_log_record_with_a_malformed_seq_is_skipped(seq: Any) -> None:
assert channel.messages.log_seq == 1
@pytest.mark.parametrize(
("logs", "shown"), [(["x", {"seq": 1, "message": "good"}], ["good"]), (None, []), (5, []), ("ab", [])]
)
def test_a_malformed_polled_log_reply_is_skipped(logs: Any, shown: list[str]) -> None:
async def test_relayed_server_logs_lose_their_control_characters() -> None:
seen: list[str] = []
channel = channel_logging_to(seen)
channel.service.client = SimpleNamespace(get_optional=lambda _: {"logs": logs}) # type: ignore[assignment]
channel.fallback.drain_logs()
assert seen == shown
await feed(channel_logging_to(seen), {"type": "log", "seq": 1, "level": "INFO", "message": "a\x1b[2Jb\nc"})
assert seen == ["a[2Jb\nc"]
async def test_a_channel_message_that_fails_is_skipped(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -331,7 +311,6 @@ def test_a_relayed_licence_with_no_licence_is_one_click_error(answer: dict[str,
service = RemoteService.__new__(RemoteService)
service._track_alias = {}
service.session_call = lambda call: answer # type: ignore[method-assign]
service.drain_server_logs = lambda: None # type: ignore[method-assign]
track = SimpleNamespace(id="v1", drm=[])
with pytest.raises(click.ClickException, match="no valid licence for track v1"):
service.proxy_license(b"challenge", cast(Any, track), "widevine")