diff --git a/shelfmark/release_sources/jackett/handler.py b/shelfmark/release_sources/jackett/handler.py index 943c0db1..12c72d25 100644 --- a/shelfmark/release_sources/jackett/handler.py +++ b/shelfmark/release_sources/jackett/handler.py @@ -86,7 +86,8 @@ class JackettHandler(ExternalClientHandler): source_id = normalize_optional_text(release_data.get("source_id")) result = get_release(source_id) if source_id else None if result is None: - return {} + # Never fall back to the URL the client sent along with the request. + return {"retry_download_url": None, "retry_download_protocol": None} protocol = get_protocol(result) return { diff --git a/shelfmark/release_sources/newznab/handler.py b/shelfmark/release_sources/newznab/handler.py index adae2609..9c386685 100644 --- a/shelfmark/release_sources/newznab/handler.py +++ b/shelfmark/release_sources/newznab/handler.py @@ -93,12 +93,10 @@ class NewznabHandler(ExternalClientHandler): def build_retry_resolution_fields(self, release_data: dict) -> dict: source_id = normalize_optional_text(release_data.get("source_id")) - if source_id is None: - return {} - - result = get_release(source_id) + result = get_release(source_id) if source_id else None if result is None: - return {} + # Never fall back to the URL the client sent along with the request. + return {"retry_download_url": None, "retry_download_protocol": None} protocol = _get_protocol(result) return { diff --git a/tests/download/test_orchestrator_retry_url.py b/tests/download/test_orchestrator_retry_url.py new file mode 100644 index 00000000..c0c6006c --- /dev/null +++ b/tests/download/test_orchestrator_retry_url.py @@ -0,0 +1,31 @@ +"""The retry URL comes from server data, never from the queue request.""" + +import pytest + +from shelfmark.download import orchestrator + + +@pytest.mark.parametrize("source", ["newznab", "jackett"]) +def test_cache_miss_drops_client_supplied_download_url(source): + fields = orchestrator._build_retry_resolution_fields( + { + "source": source, + "source_id": "not-in-the-cache", + "download_url": "http://169.254.169.254/latest/meta-data/", + "protocol": "torrent", + "title": "Some Book", + } + ) + + assert fields["retry_download_url"] is None + assert fields["retry_download_protocol"] is None + + +@pytest.mark.parametrize("source", ["newznab", "jackett"]) +def test_missing_source_id_drops_client_supplied_download_url(source): + fields = orchestrator._build_retry_resolution_fields( + {"source": source, "download_url": "http://10.0.0.1/x", "protocol": "usenet"} + ) + + assert fields["retry_download_url"] is None + assert fields["retry_download_protocol"] is None