mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-30 16:01:17 -07:00
Chore: simplify qbittorrent api key handling (#6888)
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:
@@ -84,23 +84,20 @@ describe("widgets/qbittorrent/proxy", () => {
|
||||
expect(res.body).toEqual(Buffer.from("Denied"));
|
||||
});
|
||||
|
||||
it("supports API keys by including them in the Authorization header and not the body", async () => {
|
||||
it("uses an API key on the WebAPI request without attempting login", 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")]);
|
||||
httpProxy.mockResolvedValueOnce([403, "application/json", Buffer.from("nope")]);
|
||||
|
||||
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"));
|
||||
expect(httpProxy).toHaveBeenCalledTimes(1);
|
||||
expect(httpProxy.mock.calls[0][0].toString()).toBe("http://qb/api/v2/torrents/info");
|
||||
expect(httpProxy.mock.calls[0][1].headers.Authorization).toBe("Bearer abc123");
|
||||
expect(res.statusCode).toBe(403);
|
||||
expect(res.body).toEqual(Buffer.from("nope"));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user