mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 14:01:16 -07:00
Enhancement: support qBittorrent apikey (#6791)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -9,12 +9,18 @@ async function login(widget) {
|
||||
logger.debug("qBittorrent is rejecting the request, logging in.");
|
||||
const loginUrl = new URL(`${widget.url}/api/v2/auth/login`).toString();
|
||||
const loginBody = `username=${encodeURIComponent(widget.username)}&password=${encodeURIComponent(widget.password)}`;
|
||||
const loginKey = `${widget.key}`;
|
||||
const loginParams = {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: loginBody,
|
||||
};
|
||||
|
||||
if (widget.key) {
|
||||
loginParams.headers.Authorization = `Bearer ${loginKey}`;
|
||||
} else if (widget.username && widget.password) {
|
||||
loginParams.body = loginBody;
|
||||
}
|
||||
|
||||
const [status, contentType, data] = await httpProxy(loginUrl, loginParams);
|
||||
return [status, data];
|
||||
}
|
||||
|
||||
@@ -83,4 +83,24 @@ describe("widgets/qbittorrent/proxy", () => {
|
||||
expect(res.statusCode).toBe(401);
|
||||
expect(res.body).toEqual(Buffer.from("Denied"));
|
||||
});
|
||||
|
||||
it("supports API keys by including them in the Authorization header and not the body", async () => {
|
||||
getServiceWidget.mockResolvedValue({ url: "http://qb", key: "abc123" });
|
||||
|
||||
httpProxy
|
||||
.mockResolvedValueOnce([403, "application/json", Buffer.from("nope")])
|
||||
.mockResolvedValueOnce([200, "text/plain", Buffer.from("Ok.")])
|
||||
.mockResolvedValueOnce([200, "application/json", Buffer.from("data")]);
|
||||
|
||||
const req = { query: { group: "g", service: "svc", endpoint: "torrents/info", index: "0" } };
|
||||
const res = createMockRes();
|
||||
|
||||
await qbittorrentProxyHandler(req, res);
|
||||
|
||||
expect(httpProxy).toHaveBeenCalledTimes(3);
|
||||
expect(httpProxy.mock.calls[1][0]).toBe("http://qb/api/v2/auth/login");
|
||||
expect(httpProxy.mock.calls[1][1].headers.Authorization).toBe("Bearer abc123");
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toEqual(Buffer.from("data"));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user