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
+11 -21
View File
@@ -85,6 +85,7 @@ def call_session_handler(handler, body, service, **entry_fields):
async def run():
store = store_mod.get_session_store()
entry = await store.create(service_tag="EXAMPLE", service_instance=service, session_id="s", owner_key=None)
entry.presence.attached()
for name, value in entry_fields.items():
setattr(entry, name, value)
try:
@@ -181,7 +182,6 @@ def test_remote_get_tracks_scopes_server_cookies():
service_tag="EXAMPLE",
log=logging.getLogger("test"),
client=SimpleNamespace(post=lambda path, body: {"session_cookie_jar": jar}, probe=lambda endpoint: {}),
drain_server_logs=lambda: None,
)
hold_session(service)
service.get_tracks(SimpleNamespace(id="t1"))
@@ -333,6 +333,7 @@ def _run_session(monkeypatch, tmp_path, data, answer, server_account=False, fail
import asyncio
import base64
import json
import uuid
import zlib
from unshackle.core.api import handlers
@@ -362,11 +363,13 @@ def _run_session(monkeypatch, tmp_path, data, answer, server_account=False, fail
data["cache"] = {"tokens_default": base64.b64encode(zlib.compress(b"{}")).decode("ascii")}
async def run():
resp = await handlers.session_create_handler({"service": "EXAMPLE", "title_id": "t", **data})
body = {"service": "EXAMPLE", "title_id": "t", "session_id": str(uuid.uuid4()), **data}
resp = await handlers.session_create_handler(body)
session = get_session_store().peek(json.loads(resp.body)["session_id"])
for _ in range(200):
if answer is not None and session.input_bridge.status == AuthStatus.PENDING_INPUT:
await handlers.session_prompt_post_handler({"response": answer}, session.session_id)
if answer is not None:
for ask in session.input_bridge.claim_for_channel():
session.input_bridge.answer(ask.id, answer)
if session.auth_status in (AuthStatus.AUTHENTICATED, AuthStatus.FAILED):
break
await asyncio.sleep(0.01)
@@ -399,27 +402,12 @@ def test_a_failed_login_reports_its_error(monkeypatch, tmp_path):
assert (session.auth_status, session.auth_error) == (AuthStatus.FAILED, "bad code")
def test_prompt_post_rejects_response_the_bridge_refused(monkeypatch):
import asyncio
from unshackle.core.api import handlers
from unshackle.core.remote_protocol import AuthStatus
bridge = SimpleNamespace(status=AuthStatus.PENDING_INPUT, submit_response=lambda text: False)
async def fake_get_session(session_id, request):
return SimpleNamespace(input_bridge=bridge)
monkeypatch.setattr(handlers, "get_validated_session", fake_get_session)
with pytest.raises(APIError):
asyncio.run(handlers.session_prompt_post_handler({"response": ""}, "sess"))
def test_login_that_outlives_its_session_leaves_no_cache(monkeypatch, tmp_path):
"""A login loop that finishes after DELETE must not leave its tokens on the server's disk."""
import asyncio
import json
import threading
import uuid
from unshackle.core.api import handlers
from unshackle.core.api.session_store import get_session_store
@@ -446,7 +434,9 @@ def test_login_that_outlives_its_session_leaves_no_cache(monkeypatch, tmp_path):
stub_service_build(monkeypatch, SlowPairingService)
async def run():
resp = await handlers.session_create_handler({"service": "EXAMPLE", "title_id": "t"})
resp = await handlers.session_create_handler(
{"service": "EXAMPLE", "title_id": "t", "session_id": str(uuid.uuid4())}
)
session = get_session_store().peek(json.loads(resp.body)["session_id"])
await get_session_store().delete(session.session_id)
paired.set()