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
+13 -23
View File
@@ -5,7 +5,6 @@ from types import SimpleNamespace
import pytest
from tests.remote.sessions import hold_session
from unshackle.core import remote_service
from unshackle.core.api import handlers
from unshackle.core.api.errors import APIError
@@ -214,30 +213,21 @@ def test_a_quiet_remote_login_shows_its_last_server_lines_as_a_notice(monkeypatc
shown = []
monkeypatch.setattr(remote_channel, "show_notice", lambda message, qr=None: shown.append(message))
monkeypatch.setattr(remote_channel, "AUTH_POLL_INTERVAL", 0)
logs = iter([["+ IP Region: CA"], ["+ Open URL: https://example.test/start\n+ Enter pair code: 9835-2503"], []])
statuses = iter(["authenticating", "authenticating", "authenticating", "authenticated"])
class Client:
def get(self, endpoint):
return {"status": next(statuses)}
def get_optional(self, endpoint):
batch = next(logs, [])
first = remote.seq + 1
remote.seq += len(batch)
records = [{"seq": first + i, "level": "INFO", "message": m} for i, m in enumerate(batch)]
return {"logs": records, "last_seq": remote.seq}
remote = object.__new__(remote_service.RemoteService)
remote.seq = 0
remote.client, remote.auth_notice, remote.auth_qr = Client(), None, None
hold_session(remote)
remote.auth_notice, remote.auth_qr, remote._input_bridge = None, None, None
remote.log = logging.getLogger("test")
monkeypatch.setattr(remote_service.RemoteService, "local_cdm", None)
messages = remote_channel.ServerMessages(remote)
lines = ["+ IP Region: CA", "+ Open URL: https://example.test/start\n+ Enter pair code: 9835-2503"]
remote_channel.PollingChannel(remote_channel.ServerMessages(remote)).wait_auth()
# silent while the remote was still logging; the pair code once it went quiet; cleared when done
for seq, line in enumerate(lines, 1):
seen = messages.log_seq
messages.show_logs([{"seq": seq, "level": "INFO", "message": line}])
messages.note_waiting(seen)
messages.note_waiting(messages.log_seq)
messages.note_waiting(messages.log_seq)
messages.login_done()
# silent while the remote was still logging; the pair code once, when it went quiet; cleared when done
assert shown == ["+ IP Region: CA\n+ Open URL: https://example.test/start\n+ Enter pair code: 9835-2503", None]
assert remote.auth_notice is None
@@ -280,7 +270,7 @@ async def test_a_remote_login_prompt_waits_for_its_owners_answer(monkeypatch):
)
)
asker.start()
while login.bridge.get_pending_prompt() is None:
while login.bridge.get_pending_ask() is None:
await asyncio.sleep(0.01)
listed = json.loads((await handlers.remote_logins_handler(None)).text)["logins"]
@@ -296,7 +286,7 @@ async def test_a_remote_login_prompt_waits_for_its_owners_answer(monkeypatch):
caller["key"] = "owner"
await handlers.remote_login_input_handler(login.id, {"response": "123456"}, None)
asker.join(2)
assert got == ["123456"] and login.bridge.get_pending_prompt() is None
assert got == ["123456"] and login.bridge.get_pending_ask() is None
with pytest.raises(APIError) as e:
await handlers.remote_login_input_handler(login.id, {"response": "again"}, None)
assert e.value.error_code == APIErrorCode.CONFLICT