mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 23:45:07 +00:00
feat(remote)!: make remote serve WebSocket-only and refuse older clients with CLIENT_OUTDATED
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import json
|
||||
from collections.abc import Callable
|
||||
from threading import Event, Thread
|
||||
from threading import Thread
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
@@ -13,8 +13,8 @@ import pytest
|
||||
import responses
|
||||
|
||||
from tests.remote.unit.test_session_reopen import SERVER, make_service
|
||||
from unshackle.core import remote_channel, remote_service
|
||||
from unshackle.core.remote_channel import PollingChannel, ServerMessages, WebSocketChannel
|
||||
from unshackle.core import remote_service
|
||||
from unshackle.core.remote_channel import ServerMessages, WebSocketChannel
|
||||
from unshackle.core.remote_protocol import ClientErrorKind
|
||||
from unshackle.core.remote_service import RemoteClient
|
||||
from unshackle.core.tunnel import TunnelClient, run_loop
|
||||
@@ -61,52 +61,6 @@ def test_recover_moves_to_the_next_auth_header() -> None:
|
||||
assert service._session_id == "s1"
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_server_draining_moves_to_the_next_auth_header() -> None:
|
||||
service = make_service()
|
||||
service.lifetime.channel = PollingChannel(ServerMessages(service))
|
||||
responses.add_callback(responses.GET, f"{SERVER}/api/session/s1", callback=second_header_only({"draining": True}))
|
||||
|
||||
assert service.server_draining()
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_keepalive_moves_to_the_next_auth_header(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(remote_channel, "KEEPALIVE_MIN_INTERVAL", 0.01)
|
||||
polling = PollingChannel(ServerMessages(make_service()))
|
||||
pinged = Event()
|
||||
info = {"valid": True, "expires_in": 0.03}
|
||||
responses.add_callback(responses.GET, f"{SERVER}/api/session/s1", callback=second_header_only(info, pinged.set))
|
||||
|
||||
polling.keep_alive()
|
||||
try:
|
||||
assert pinged.wait(5)
|
||||
finally:
|
||||
polling.stop_keepalive()
|
||||
assert [c.response.status_code for c in responses.calls[:2]] == [401, 200]
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_cdm_poller_moves_to_the_next_auth_header(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
polling = PollingChannel(ServerMessages(make_service()))
|
||||
stop = Event()
|
||||
answered: list[dict] = []
|
||||
monkeypatch.setattr(polling.messages, "answer_cdm", lambda call: (answered.append(call), stop.set()))
|
||||
monkeypatch.setattr(polling, "answer", lambda response: None)
|
||||
call = {"id": "c1", "op": "open"}
|
||||
reply = {"status": "pending_input", "cdm_call": call}
|
||||
responses.add_callback(responses.GET, f"{SERVER}/api/session/s1/prompt", callback=second_header_only(reply))
|
||||
|
||||
poller = Thread(target=polling.poll_cdm_calls, args=(stop, 0.01), daemon=True)
|
||||
poller.start()
|
||||
try:
|
||||
assert stop.wait(5)
|
||||
finally:
|
||||
stop.set()
|
||||
poller.join(5)
|
||||
assert answered == [call]
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_recover_waits_out_a_429_instead_of_reopening(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
waits: list[int] = []
|
||||
@@ -147,7 +101,7 @@ def test_a_channel_closes_after_its_loop_has_closed() -> None:
|
||||
service = make_service()
|
||||
service.ctx = SimpleNamespace(obj=None)
|
||||
messages = ServerMessages(service)
|
||||
channel = WebSocketChannel(messages, PollingChannel(messages))
|
||||
channel = WebSocketChannel(messages)
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.close()
|
||||
channel.loop, channel.task = loop, SimpleNamespace(cancel=lambda: None)
|
||||
@@ -175,7 +129,7 @@ def test_a_channel_loop_ends_without_starting_a_thread(monkeypatch: pytest.Monke
|
||||
service = make_service()
|
||||
service.ctx = SimpleNamespace(obj=None)
|
||||
messages = ServerMessages(service)
|
||||
channel = WebSocketChannel(messages, PollingChannel(messages))
|
||||
channel = WebSocketChannel(messages)
|
||||
|
||||
channel.thread.run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user