fix(qbittorrent): recognize QBT_SID session cookie (newer qBittorrent)

Newer qBittorrent renamed its session cookie from "SID" to "QBT_SID" /
"QBT_SID_<port>" (the diagnostic revealed cookies=['QBT_SID_5080']). The
client only accepted "SID", so a valid login (cookie present in the jar) was
reported as "Unexpected response". Re-entering correct credentials never
helped because login was succeeding all along.

Treat any cookie named "SID" OR starting with "QBT_SID" as the session
cookie, checked in both the parsed jar and the raw Set-Cookie header.
qBittorrent only sets this cookie on a valid login, so it stays authoritative.
Diagnostic message updated to mention both names.

New regression test covers the QBT_SID_<port> case. 388/388 backend tests
pass; ruff clean.
This commit is contained in:
Developer
2026-07-12 11:09:10 +00:00
parent 7e53edfcc6
commit 39775a82ef
4 changed files with 32 additions and 14 deletions
+11
View File
@@ -181,6 +181,17 @@ class QbittorrentClientTests(unittest.TestCase):
self.assertTrue(self.client._logged_in)
def test_login_accepts_qbt_sid_cookie_newer_versions(self) -> None:
"""Newer qBittorrent names the session cookie QBT_SID_<port>; recognize it."""
resp = self._login_response("")
resp.status_code = 204
resp.cookies = {"QBT_SID_5080": "abc123"}
self.session.post.return_value = resp
self.client._login()
self.assertTrue(self.client._logged_in)
def test_login_empty_body_without_cookie_is_diagnostic(self) -> None:
"""Empty 200 body with no SID surfaces a URL/proxy diagnostic hint."""
resp = self._login_response("")