fix(qbittorrent): stop mislabeling gateway/URL errors as auth failures
The credential tester always reported "Authentication failed — qBittorrent rejected the credentials" for the qBittorrent service, even when credentials were correct. test_connection classified any RuntimeError whose message contained "login failed" as an auth failure — and the gateway-timeout error (502/503/504 from the reverse proxy) and the wrong-URL diagnostic both started with "qBittorrent login failed:", so a proxy timeout was reported as a credentials rejection. That sent users down the wrong path (re-entering correct passwords to fix a 504). - QbittorrentClient._login: gateway and URL/routing errors no longer contain "login failed"; only a genuine "Fails." body carries the "invalid username or password" signal. - integrations/qbittorrent.test_connection: key the auth message off "invalid username or password" specifically; all other login errors flow through translate_connection_error so the real reason (proxy timeout, wrong URL, empty body) is surfaced. After this, a failing test reports the actual cause (e.g. "qBittorrent is unreachable: reverse proxy returned HTTP 504 ...") instead of accusing the credentials. New regression test asserts a gateway error is NOT reported as "Authentication failed". 386/386 backend tests pass; ruff clean.
This commit is contained in:
@@ -68,7 +68,7 @@ class QbittorrentClient:
|
||||
# than as a bare HTTPError.
|
||||
if resp.status_code in (502, 503, 504):
|
||||
raise RuntimeError(
|
||||
f"qBittorrent login failed: reverse proxy returned HTTP {resp.status_code} "
|
||||
f"qBittorrent is unreachable: reverse proxy returned HTTP {resp.status_code} "
|
||||
f"for {resp.url}. qBittorrent may be down, starting up, or unable to "
|
||||
"answer within the proxy's forwarding timeout."
|
||||
)
|
||||
@@ -85,9 +85,9 @@ class QbittorrentClient:
|
||||
if body == "Fails.":
|
||||
raise RuntimeError(f"qBittorrent login failed (HTTP {resp.status_code}): invalid username or password")
|
||||
raise RuntimeError(
|
||||
f"qBittorrent login failed (HTTP {resp.status_code}, body={body!r}). "
|
||||
"Expected the text 'Ok.' from /api/v2/auth/login — this usually means "
|
||||
"base_url does not reach the qBittorrent Web API (check the URL, path, "
|
||||
f"Unexpected response from qBittorrent login endpoint (HTTP {resp.status_code}, "
|
||||
f"body={body!r}). Expected the text 'Ok.' from /api/v2/auth/login — this usually "
|
||||
"means base_url does not reach the qBittorrent Web API (check the URL, path, "
|
||||
"and any reverse proxy in front of qBittorrent)."
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user