Enhancement: support pyload API key, fix error message (#6558)
Some checks failed
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 / Auto Label PR (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled

This commit is contained in:
shamoon
2026-04-12 11:00:54 -07:00
committed by GitHub
parent 1accddf29a
commit a7bab17f97
3 changed files with 57 additions and 9 deletions

View File

@@ -75,6 +75,46 @@ describe("widgets/pyload/proxy", () => {
expect(res.body).toEqual({ ok: true });
});
it("uses api key auth and returns data", async () => {
getServiceWidget.mockResolvedValue({
type: "pyload",
url: "http://pyload",
key: "apikey",
});
httpProxy.mockResolvedValueOnce([200, "application/json", Buffer.from(JSON.stringify({ ok: true })), {}]);
const req = { query: { group: "g", service: "svc", endpoint: "status", index: "0" } };
const res = createMockRes();
await pyloadProxyHandler(req, res);
expect(httpProxy).toHaveBeenCalledTimes(1);
expect(httpProxy.mock.calls[0][1].headers["X-API-Key"]).toBe("apikey");
expect(cache.put).toHaveBeenCalledWith("pyloadProxyHandler__isNg.svc", true);
expect(res.body).toEqual({ ok: true });
});
it("returns error if login fails", async () => {
getServiceWidget.mockResolvedValue({
type: "pyload",
url: "http://pyload",
username: "u",
password: "p",
});
httpProxy.mockResolvedValueOnce([401, "application/json", Buffer.from(JSON.stringify({ error: "bad" })), {}]);
const req = { query: { group: "g", service: "svc", endpoint: "status", index: "0" } };
const res = createMockRes();
await pyloadProxyHandler(req, res);
expect(httpProxy).toHaveBeenCalledTimes(1);
expect(res.statusCode).toBe(401);
expect(res.body).toMatchObject({ error: "Invalid credentials communicating with Pyload API" });
});
it("retries after 403 by clearing session and logging in again", async () => {
getServiceWidget.mockResolvedValue({
type: "pyload",