fix(remote): map a cut-off answer to a recoverable error and stop trusting an empty optional answer

This commit is contained in:
imSp4rky
2026-11-28 21:03:54 -07:00
parent 74fa29b6f1
commit f5c8858e6e
12 changed files with 279 additions and 76 deletions
+20
View File
@@ -10,6 +10,7 @@ from types import SimpleNamespace
from typing import Any, cast
from unittest.mock import Mock
import click
import pytest
import requests
from aiohttp import WSMsgType, web
@@ -322,3 +323,22 @@ async def test_a_failed_login_status_shows_the_server_error_without_control_char
with pytest.raises(RemoteError) as caught:
channel.auth_step()
assert caught.value.message == "Remote auth failed: [2Jbadforged"
@pytest.mark.parametrize("answer", [{"license": None}, {}, {"license": "x"}, {"license": 5}])
def test_a_relayed_licence_with_no_licence_is_one_click_error(answer: dict[str, Any]) -> None:
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")
@pytest.mark.parametrize("chapters", [[{"name": "x"}], [{"timestamp": "not a time"}], [5]])
def test_malformed_chapters_from_the_server_are_one_remote_error(chapters: list[Any]) -> None:
service = RemoteService.__new__(RemoteService)
service._chapters_by_title = {"t": chapters}
with pytest.raises(RemoteError, match="malformed chapters"):
service.get_chapters(cast(Any, SimpleNamespace(id="t")))