fix: route searx and alert SearXNG traffic through SOCKS5 proxy
Both plugins called urllib.request.urlopen directly, bypassing the proxy. Switch to derp.http.urlopen and update the SearXNG endpoint to the public domain (searx.mymx.me). Update test mocks to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -120,7 +120,7 @@ class TestTruncate:
|
||||
|
||||
class TestSearch:
|
||||
def test_success(self):
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(SEARX_RESPONSE)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(SEARX_RESPONSE)):
|
||||
results = _search("test query")
|
||||
assert len(results) == 5
|
||||
assert results[0]["title"] == "Result One"
|
||||
@@ -128,14 +128,14 @@ class TestSearch:
|
||||
assert results[0]["snippet"] == "First snippet"
|
||||
|
||||
def test_empty_results(self):
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(SEARX_EMPTY)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(SEARX_EMPTY)):
|
||||
results = _search("nothing")
|
||||
assert results == []
|
||||
|
||||
def test_http_error_propagates(self):
|
||||
import pytest
|
||||
|
||||
with patch("urllib.request.urlopen", side_effect=ConnectionError("down")):
|
||||
with patch.object(_mod, "_urlopen", side_effect=ConnectionError("down")):
|
||||
with pytest.raises(ConnectionError):
|
||||
_search("test")
|
||||
|
||||
@@ -144,7 +144,7 @@ class TestSearch:
|
||||
data = {"results": [
|
||||
{"title": "T", "url": "http://x.com", "snippet": "fallback"},
|
||||
]}
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(data)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(data)):
|
||||
results = _search("test")
|
||||
assert results[0]["snippet"] == "fallback"
|
||||
|
||||
@@ -158,7 +158,7 @@ class TestCmdSearx:
|
||||
bot = _FakeBot()
|
||||
|
||||
async def inner():
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(SEARX_RESPONSE)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(SEARX_RESPONSE)):
|
||||
await cmd_searx(bot, _msg("!searx test query"))
|
||||
assert len(bot.replied) == _MAX_RESULTS
|
||||
assert "Result One" in bot.replied[0]
|
||||
@@ -171,7 +171,7 @@ class TestCmdSearx:
|
||||
bot = _FakeBot()
|
||||
|
||||
async def inner():
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(SEARX_EMPTY)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(SEARX_EMPTY)):
|
||||
await cmd_searx(bot, _msg("!searx nothing"))
|
||||
assert len(bot.replied) == 1
|
||||
assert "No results for:" in bot.replied[0]
|
||||
@@ -182,7 +182,7 @@ class TestCmdSearx:
|
||||
bot = _FakeBot()
|
||||
|
||||
async def inner():
|
||||
with patch("urllib.request.urlopen", side_effect=ConnectionError("fail")):
|
||||
with patch.object(_mod, "_urlopen", side_effect=ConnectionError("fail")):
|
||||
await cmd_searx(bot, _msg("!searx broken"))
|
||||
assert len(bot.replied) == 1
|
||||
assert "Search failed:" in bot.replied[0]
|
||||
@@ -219,7 +219,7 @@ class TestCmdSearx:
|
||||
bot = _FakeBot()
|
||||
|
||||
async def inner():
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(data)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(data)):
|
||||
await cmd_searx(bot, _msg("!searx test"))
|
||||
assert len(bot.replied) == 1
|
||||
title_part = bot.replied[0].split(" -- ")[0]
|
||||
@@ -236,7 +236,7 @@ class TestCmdSearx:
|
||||
bot = _FakeBot()
|
||||
|
||||
async def inner():
|
||||
with patch("urllib.request.urlopen", return_value=_FakeResp(data)):
|
||||
with patch.object(_mod, "_urlopen", return_value=_FakeResp(data)):
|
||||
await cmd_searx(bot, _msg("!searx test"))
|
||||
assert "(no title)" in bot.replied[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user