fix: 代理探测只看学习站,手填地址只允许公网

This commit is contained in:
2026-11-16 09:29:45 +08:00
parent 89d9452967
commit 990b80c017
7 changed files with 152 additions and 42 deletions
+11 -9
View File
@@ -9,7 +9,7 @@ from euniv.db import SessionLocal
from euniv.models import Account, ProxyNode
from euniv.proxy import apply as apply_proxy
from euniv.proxy import bind_url, is_proxy_failure, view_of
from euniv.proxy_pool import PROBE_URLS, acquire, mark_failed, page, probe, refresh_once, release
from euniv.proxy_pool import PROBE_URL, acquire, mark_failed, page, probe, refresh_once, release
from euniv.proxy_pool import _holds
INITIAL_PASSWORD = os.environ["EUNIV_ADMIN_PASSWORD"]
@@ -127,13 +127,13 @@ def test_bind_url_uses_pool_or_manual() -> None:
manual_user = db.get(Account, "manual-user")
assert pool_user is not None and manual_user is not None
apply_proxy(pool_user, "pool")
apply_proxy(manual_user, "http", "127.0.0.1", 7890)
apply_proxy(manual_user, "http", "1.1.1.1", 7890)
db.commit()
db.refresh(pool_user)
db.refresh(manual_user)
assert view_of(pool_user)["scheme"] == "pool"
assert bind_url(pool_user) == "http://10.0.0.4:8004"
assert bind_url(manual_user) == "http://127.0.0.1:7890"
assert bind_url(manual_user) == "http://1.1.1.1:7890"
apply_proxy(pool_user, "off")
db.commit()
db.refresh(pool_user)
@@ -147,6 +147,7 @@ def test_refresh_marks_slow_and_keeps_fast(monkeypatch) -> None:
lambda: [
ProxyCandidate("http", "1.1.1.1", 80, "cn", "elite", "proxyhub"),
ProxyCandidate("http", "2.2.2.2", 80, "cn", "elite", "proxyhub"),
ProxyCandidate("http", "4.4.4.4", 80, "cn", "elite", "proxyhub"),
ProxyCandidate("http", "3.3.3.3", 80, "us", "elite", "proxyhub"),
],
)
@@ -159,7 +160,8 @@ def test_refresh_marks_slow_and_keeps_fast(monkeypatch) -> None:
monkeypatch.setattr("euniv.proxy_pool.probe", fake_probe)
payload = refresh_once()
assert payload["alive"] == 1
assert payload["dead"] == 1
assert payload["dead"] == 2
assert payload["message"] == ""
with SessionLocal() as db:
listed = page(db)
hosts = {item["host"]: item for item in listed["items"]}
@@ -240,13 +242,13 @@ def test_probe_averages_euniv_related_sites(monkeypatch) -> None:
seen.append(url)
return FakeResponse()
ticks = iter([0.0, 0.12, 0.12, 0.34, 0.34, 0.64])
ticks = iter([0.0, 0.12])
monkeypatch.setattr("euniv.proxy_pool.sync_httpx_client", FakeClient)
monkeypatch.setattr("euniv.proxy_pool.time.perf_counter", lambda: next(ticks))
ok, latency, reason = probe("http", "10.0.0.9", 8080)
assert seen == list(PROBE_URLS)
ok, latency, reason = probe("http", "1.1.1.1", 8080)
assert seen == [PROBE_URL]
assert ok is True
assert latency == 213
assert latency == 120
assert reason == ""
@@ -264,7 +266,7 @@ def test_probe_instant_connect_error_keeps_elapsed_latency(monkeypatch) -> None:
def get(self, _url: str):
raise httpx.ConnectError("boom")
ticks = iter([0.0, 0.012, 0.012, 0.018, 0.018, 0.025])
ticks = iter([0.0, 0.008])
monkeypatch.setattr("euniv.proxy_pool.sync_httpx_client", FakeClient)
monkeypatch.setattr("euniv.proxy_pool.time.perf_counter", lambda: next(ticks))
ok, latency, reason = probe("socks4", "10.0.0.9", 1080)