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 -39
View File
@@ -28,10 +28,8 @@ from tests.remote.unit.test_process_exit import ( # noqa: F401
logins,
posix,
run,
saved,
sessions,
settings,
store_cache,
wait_line,
)
from tests.remote.unit.test_remote_loopback import StubService, count, forget, server # noqa: F401
@@ -42,13 +40,10 @@ from unshackle.core.constants import RunCancel
from unshackle.core.proxies.controld import relay
from unshackle.core.remote_channel import ServerMessages
from unshackle.core.remote_protocol import (
LOGS_ROUTE,
PROMPT_ROUTE,
SESSION_CREATE_ROUTE,
SESSION_ROUTE,
TITLES_ROUTE,
TRACKS_ROUTE,
AuthStatus,
)
from unshackle.core.tracks import Audio, Tracks
@@ -79,9 +74,6 @@ service = make_client(sys.argv[1])
keys = resolver()
if phase == "push":
remote_service.KEYS_TIMEOUT = 60
if "polling" in sys.argv[4:]:
remote_channel.WebSocketChannel.open = lambda self, timeout=0: False
def say(line):
print(line, flush=True)
@@ -95,12 +87,12 @@ def hold(line):
while not RunCancel.pressed:
Event().wait(0.01)
def drain_logs(real=service.drain_server_logs):
real()
def open_session(credential, real=service.open_session):
real(credential)
if phase == "login-done" and service._tracks_by_title:
hold("login done")
service.drain_server_logs = drain_logs
service.open_session = open_session
def login_material(profile, real=service.client_login):
if phase == "login-material" and service._titles:
@@ -383,29 +375,18 @@ def hold_login(monkeypatch: pytest.MonkeyPatch) -> SimpleNamespace:
return login
@pytest.mark.parametrize("channel", ["socket", "polling"])
def test_a_ctrl_c_in_the_login_of_a_reopen_deletes_the_new_session(
server: SimpleNamespace, # noqa: F811
client: Callable[..., Any],
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
channel: str,
) -> None:
"""The client of the polling channel does not know yet that its login succeeded, so the DELETE returns a cache."""
process = client("pool", channel)
process = client("pool")
login = hold_login(monkeypatch)
forget(server, sessions()[0].session_id)
polls = count(server, "GET", PROMPT_ROUTE)
go(process)
try:
assert login.started.wait(DEADLINE)
if channel == "socket":
assert wait_until(lambda: sessions()[0].channel.attached, DEADLINE)
else:
assert wait_until(lambda: count(server, "GET", PROMPT_ROUTE) > polls, DEADLINE)
login.release.set()
assert wait_until(lambda: sessions()[0].auth_status == AuthStatus.AUTHENTICATED, DEADLINE)
store_cache()
assert wait_until(lambda: sessions()[0].channel.attached, DEADLINE)
created, (entry,) = count(server, "POST", SESSION_CREATE_ROUTE), sessions()
output = press(process)
finally:
@@ -414,7 +395,6 @@ def test_a_ctrl_c_in_the_login_of_a_reopen_deletes_the_new_session(
assert "Download Cancelled" in output and "called" not in output and "error" not in output.lower()
assert sessions() == [] and count(server, "POST", SESSION_CREATE_ROUTE) == created
assert count(server, "DELETE", SESSION_ROUTE, entry.session_id) == 1
assert channel == "socket" or saved(tmp_path / "client")
def test_a_failed_track_does_not_stop_the_reopen_of_the_others(
@@ -500,20 +480,6 @@ def test_a_track_whose_wait_was_cancelled_did_not_fail(
assert sorted(lines) == ["Download Cancelled", "DownloadCancelled", "cancelled", "vault writes done"]
def test_a_cancelled_call_of_the_polling_channel_fetches_no_server_log(
server: SimpleNamespace, # noqa: F811
client: Callable[..., Any],
monkeypatch: pytest.MonkeyPatch,
) -> None:
limit(monkeypatch, "session_segments_handler")
process = client("url", "polling")
fetched = count(server, "GET", LOGS_ROUTE)
go(process)
wait_line(process, LIMITED)
press(process)
assert count(server, "GET", LOGS_ROUTE) == fetched > 0
@pytest.mark.parametrize("cancelled", [False, True])
def test_a_cancelled_login_shows_no_notice(monkeypatch: pytest.MonkeyPatch, cancelled: bool) -> None:
shown: list[Any] = []