mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-12 07:05:56 -07:00
Enhancement: Add bearer authentication to whatsupdocker widget (#7134)
Docker CI / Docker Build & Push (push) Waiting to run
Lint / Linting Checks (push) Waiting to run
Release Drafter / Update Release Draft (push) Waiting to run
Release Drafter / Auto Label PR (push) Waiting to run
Tests / vitest (1) (push) Waiting to run
Tests / vitest (2) (push) Waiting to run
Tests / vitest (3) (push) Waiting to run
Tests / vitest (4) (push) Waiting to run
Docker CI / Docker Build & Push (push) Waiting to run
Lint / Linting Checks (push) Waiting to run
Release Drafter / Update Release Draft (push) Waiting to run
Release Drafter / Auto Label PR (push) Waiting to run
Tests / vitest (1) (push) Waiting to run
Tests / vitest (2) (push) Waiting to run
Tests / vitest (3) (push) Waiting to run
Tests / vitest (4) (push) Waiting to run
This commit is contained in:
@@ -13,4 +13,5 @@ widget:
|
||||
url: http://whatsupdocker:port
|
||||
username: username # optional
|
||||
password: password # optional
|
||||
key: bearer-token # optional, takes precedence over username/password
|
||||
```
|
||||
|
||||
@@ -77,7 +77,7 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
} else {
|
||||
headers.Authorization = basicAuthHeader(widget);
|
||||
}
|
||||
} else if (widget.type === "ntfy") {
|
||||
} else if (["ntfy", "whatsupdocker"].includes(widget.type)) {
|
||||
if (widget.key) {
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
} else if (widget.username && widget.password) {
|
||||
|
||||
@@ -35,6 +35,7 @@ vi.mock("widgets/widgets", () => ({
|
||||
proxmox: { api: "{url}/api2/json/{endpoint}" },
|
||||
truenas: { api: "{url}/api/v2.0/{endpoint}" },
|
||||
ntfy: { api: "{url}/{endpoint}" },
|
||||
whatsupdocker: { api: "{url}/{endpoint}" },
|
||||
proxmoxbackupserver: { api: "{url}/api2/json/{endpoint}" },
|
||||
checkmk: { api: "{url}/{endpoint}" },
|
||||
stocks: { api: "{url}/{endpoint}" },
|
||||
@@ -186,6 +187,24 @@ describe("utils/proxy/handlers/credentialed", () => {
|
||||
expect(params.headers.Authorization).toBe("Bearer k");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["Bearer", { key: "token" }, "Bearer token"],
|
||||
["Basic", { username: "u", password: "p" }, `Basic ${Buffer.from("u:p").toString("base64")}`],
|
||||
["no", {}, undefined],
|
||||
["Bearer over Basic", { key: "token", username: "u", password: "p" }, "Bearer token"],
|
||||
])("uses %s auth for whatsupdocker", async (_mode, credentials, authorization) => {
|
||||
getServiceWidget.mockResolvedValue({ type: "whatsupdocker", url: "http://whatsupdocker", ...credentials });
|
||||
httpProxy.mockResolvedValue([200, "application/json", []]);
|
||||
|
||||
const req = { method: "GET", query: { group: "g", service: "s", endpoint: "api/containers", index: 0 } };
|
||||
const res = createMockRes();
|
||||
|
||||
await credentialedProxyHandler(req, res);
|
||||
|
||||
const [, params] = httpProxy.mock.calls.at(-1);
|
||||
expect(params.headers.Authorization).toBe(authorization);
|
||||
});
|
||||
|
||||
it("uses Bearer auth for ntfy when key is provided", async () => {
|
||||
getServiceWidget.mockResolvedValue({ type: "ntfy", url: "http://ntfy", topic: "alerts", key: "tk_test" });
|
||||
httpProxy.mockResolvedValue([200, "application/json", { ok: true }]);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
containers: {
|
||||
|
||||
Reference in New Issue
Block a user