mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
fix(remote): map a cut-off answer to a recoverable error and stop trusting an empty optional answer
This commit is contained in:
@@ -6,6 +6,7 @@ import json
|
||||
import logging
|
||||
from threading import Lock
|
||||
|
||||
import click
|
||||
import pytest
|
||||
import requests
|
||||
import responses
|
||||
@@ -85,11 +86,20 @@ def test_a_lost_session_reopens_and_replays_the_call_under_the_new_ids(monkeypat
|
||||
assert service._title_alias == {"ep3-aaaa": "ep3-bbbb"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"broken",
|
||||
[
|
||||
requests.ConnectionError("reset"),
|
||||
requests.exceptions.ChunkedEncodingError("cut"),
|
||||
requests.exceptions.ContentDecodingError("cut"),
|
||||
],
|
||||
ids=["reset", "cut-body", "cut-gzip"],
|
||||
)
|
||||
@responses.activate
|
||||
def test_a_connect_error_on_a_live_session_runs_again_on_the_same_session():
|
||||
def test_a_connect_error_on_a_live_session_runs_again_on_the_same_session(broken):
|
||||
service = make_service()
|
||||
url = f"{SERVER}/api/session/s1/license"
|
||||
responses.add(responses.POST, url, body=requests.ConnectionError("reset"))
|
||||
responses.add(responses.POST, url, body=broken)
|
||||
responses.add(responses.POST, url, json={"license": "AA=="})
|
||||
responses.add(responses.GET, f"{SERVER}/api/health", json={"status": "ok"})
|
||||
responses.add(responses.GET, f"{SERVER}/api/session/s1", json={"valid": True})
|
||||
@@ -151,3 +161,23 @@ def test_closing_a_session_the_server_lost_logs_no_error(caplog):
|
||||
|
||||
assert service._session_id is None
|
||||
assert not [r for r in caplog.records if r.levelname in ("WARNING", "ERROR")]
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_a_certificate_the_server_fails_to_fetch_is_no_certificate():
|
||||
service = make_service()
|
||||
error = {"status": "error", "error_code": "SERVICE_ERROR", "message": "no certificate"}
|
||||
responses.add(responses.POST, f"{SERVER}/api/session/s1/license", json=error, status=422)
|
||||
|
||||
track = audio("a1")
|
||||
assert service.get_widevine_service_certificate(challenge=b"c", title=None, track=track) is None
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_a_certificate_call_whose_session_is_gone_is_one_click_error(monkeypatch):
|
||||
service = make_service()
|
||||
monkeypatch.setattr(service, "recover", lambda session_id, kind: False)
|
||||
responses.add(responses.POST, f"{SERVER}/api/session/s1/license", json=GONE, status=404)
|
||||
|
||||
with pytest.raises(click.ClickException, match="Remote session not found"):
|
||||
service.get_widevine_service_certificate(challenge=b"c", title=None, track=audio("a1"))
|
||||
|
||||
Reference in New Issue
Block a user