Tidy beta landing page and qBittorrent status
This commit is contained in:
@@ -23,7 +23,9 @@ class QBittorrentClient(ApiClient):
|
||||
headers={"Referer": self.base_url},
|
||||
)
|
||||
response.raise_for_status()
|
||||
if response.text.strip().lower() != "ok.":
|
||||
text = response.text.strip().lower()
|
||||
has_session_cookie = any(name.upper().startswith("QBT_SID") for name in client.cookies.keys())
|
||||
if text not in {"ok.", ""} or (text == "" and not has_session_cookie):
|
||||
raise RuntimeError("qBittorrent login failed")
|
||||
|
||||
async def _get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Optional[Any]:
|
||||
|
||||
@@ -3,6 +3,7 @@ import tempfile
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import httpx
|
||||
from fastapi import HTTPException
|
||||
from starlette.requests import Request
|
||||
|
||||
@@ -97,6 +98,19 @@ class NetworkSecurityTests(unittest.TestCase):
|
||||
|
||||
|
||||
class ServiceStatusTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_qbittorrent_login_accepts_modern_empty_response_with_session_cookie(self) -> None:
|
||||
class FakeClient:
|
||||
def __init__(self) -> None:
|
||||
self.cookies = httpx.Cookies()
|
||||
|
||||
async def post(self, *_args, **_kwargs) -> httpx.Response:
|
||||
self.cookies.set("QBT_SID_8080", "session")
|
||||
return httpx.Response(204, request=httpx.Request("POST", "http://10.0.0.2:8080/api/v2/auth/login"))
|
||||
|
||||
client = status_router.QBittorrentClient("http://10.0.0.2:8080", "admin", "secret")
|
||||
|
||||
await client._login(FakeClient())
|
||||
|
||||
async def test_qbittorrent_incomplete_credentials_report_degraded_when_reachable(self) -> None:
|
||||
client = status_router.QBittorrentClient("http://10.0.0.2:8080", "admin", None)
|
||||
with patch.object(client, "is_webui_reachable", new=AsyncMock(return_value=True)):
|
||||
|
||||
Reference in New Issue
Block a user