mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
Allow known nettest redirects
This commit is contained in:
@@ -141,7 +141,10 @@ def _build_nettest_rules() -> list[dict[str, Any]]:
|
|||||||
"icon": "telegram",
|
"icon": "telegram",
|
||||||
"url": "https://api.telegram.org",
|
"url": "https://api.telegram.org",
|
||||||
"proxy": True,
|
"proxy": True,
|
||||||
"allowed_redirect_prefixes": ["https://api.telegram.org/"],
|
"allowed_redirect_prefixes": [
|
||||||
|
"https://api.telegram.org/",
|
||||||
|
"https://core.telegram.org/",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "wechat_api",
|
"id": "wechat_api",
|
||||||
@@ -157,7 +160,10 @@ def _build_nettest_rules() -> list[dict[str, Any]]:
|
|||||||
"icon": "douban",
|
"icon": "douban",
|
||||||
"url": "https://frodo.douban.com",
|
"url": "https://frodo.douban.com",
|
||||||
"proxy": False,
|
"proxy": False,
|
||||||
"allowed_redirect_prefixes": ["https://frodo.douban.com/"],
|
"allowed_redirect_prefixes": [
|
||||||
|
"https://frodo.douban.com/",
|
||||||
|
"https://www.douban.com/doubanapp/frodo",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "slack_api",
|
"id": "slack_api",
|
||||||
@@ -214,7 +220,10 @@ def _build_nettest_rules() -> list[dict[str, Any]]:
|
|||||||
"icon": "github",
|
"icon": "github",
|
||||||
"url": "https://codeload.github.com",
|
"url": "https://codeload.github.com",
|
||||||
"proxy": True,
|
"proxy": True,
|
||||||
"allowed_redirect_prefixes": ["https://codeload.github.com/"],
|
"allowed_redirect_prefixes": [
|
||||||
|
"https://codeload.github.com/",
|
||||||
|
"https://github.com/",
|
||||||
|
],
|
||||||
"headers": settings.GITHUB_HEADERS,
|
"headers": settings.GITHUB_HEADERS,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -123,6 +123,50 @@ class NettestSecurityTest(unittest.TestCase):
|
|||||||
self.assertIn("跳转", resp.message)
|
self.assertIn("跳转", resp.message)
|
||||||
self.assertEqual(captured["calls"], 1)
|
self.assertEqual(captured["calls"], 1)
|
||||||
|
|
||||||
|
def test_nettest_allows_known_external_redirects(self):
|
||||||
|
cases = {
|
||||||
|
"telegram_api": "https://core.telegram.org/bots",
|
||||||
|
"douban_api": "https://www.douban.com/doubanapp/frodo?wechat=0&os=Other",
|
||||||
|
"github_codeload": "https://github.com/",
|
||||||
|
}
|
||||||
|
|
||||||
|
for target_id, redirect_url in cases.items():
|
||||||
|
call_urls = []
|
||||||
|
|
||||||
|
class FakeResponse:
|
||||||
|
def __init__(self, status_code, headers=None, text=""):
|
||||||
|
self.status_code = status_code
|
||||||
|
self.headers = headers or {}
|
||||||
|
self.text = text
|
||||||
|
|
||||||
|
async def aclose(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
class FakeAsyncRequestUtils:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def get_res(self, url, allow_redirects=True):
|
||||||
|
call_urls.append(url)
|
||||||
|
if len(call_urls) == 1:
|
||||||
|
return FakeResponse(302, headers={"location": redirect_url})
|
||||||
|
return FakeResponse(200, text="ok")
|
||||||
|
|
||||||
|
with self.subTest(target_id=target_id), patch.object(
|
||||||
|
system_endpoint,
|
||||||
|
"AsyncRequestUtils",
|
||||||
|
FakeAsyncRequestUtils,
|
||||||
|
):
|
||||||
|
resp = asyncio.run(
|
||||||
|
system_endpoint.nettest(
|
||||||
|
target_id=target_id,
|
||||||
|
_="token",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(resp.success)
|
||||||
|
self.assertEqual(len(call_urls), 2)
|
||||||
|
|
||||||
def test_nettest_uses_safe_http_options_and_server_side_content_check(self):
|
def test_nettest_uses_safe_http_options_and_server_side_content_check(self):
|
||||||
captured = {}
|
captured = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user