deer-flow/backend/tests/test_image_result_url_safety.py
ZHOU YANG 6e0ab091e7
fix(infoquest): screen result URLs through the shared public-URL owner (#7031)
* fix(infoquest): screen result URLs through the shared public-URL owner

Three providers already delegate result-URL screening to
community/url_safety.safe_public_result_url; infoquest registers the
image_search tool too but imported the owner zero times, so organic,
news and image rows all handed raw provider URLs to the model. A row the
owner rejects is now dropped rather than raised, keeping the containment
rule #6932 established for this client.

tests: test_infoquest_result_url_safety.py (new, red on main),
test_image_result_url_safety.py (infoquest added to the pinned modules).

* fix(infoquest): reject unscreened search response fallbacks

---------

Co-authored-by: ZHOU YANG <236804849+Zhouyang66639@users.noreply.github.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-18 09:55:27 +08:00

46 lines
1.5 KiB
Python

"""The image providers enforce the same string-only result URL policy."""
import importlib
from unittest.mock import patch
import pytest
@pytest.fixture(params=["url_safety", "brave.tools", "serper.tools", "infoquest.infoquest_client"])
def screen(request):
module = importlib.import_module(f"deerflow.community.{request.param}")
return module.safe_public_result_url if request.param == "url_safety" else module._safe_public_url
@pytest.mark.parametrize(
"url",
[
"http://metadata.google.internal/image",
"http://[64:ff9b::7f00:1]/image",
"http://[::ffff:127.0.0.1]/image",
"http://[2002:7f00:1::]/image",
"http://[::10.0.0.1]/image",
"http://224.0.0.1/image",
"http://3758096385/image",
"http://[ff02::1]/image",
"http://[2002:e000:1::]/image",
"http://240.0.0.1/image",
"http://127.0.0.1/image",
"http://0x7f000001/image",
"http://0177.0.0.1/image",
"http://localhost./image",
"file:///etc/passwd",
],
)
def test_image_providers_reject_non_public_results(screen, url):
assert screen(url) == ""
@pytest.mark.parametrize(
"url",
["https://images.example/image", "http://8.8.8.8/image", "http://134744072/image", "http://[2606:4700:4700::1111]/image"],
)
def test_image_providers_keep_public_results_without_dns(screen, url):
with patch("socket.getaddrinfo", side_effect=AssertionError("Result screening must not perform DNS")):
assert screen(url) == url