Fix: ensure authentik widget v1 fallback (#6991)
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

This commit is contained in:
shamoon
2026-08-15 11:05:46 -07:00
committed by GitHub
parent f711d290a7
commit 198c86fb49
2 changed files with 26 additions and 1 deletions
+2 -1
View File
@@ -35,7 +35,8 @@ export default function Component({ service }) {
let loginsLast24H;
let failedLoginsLast24H;
switch (widget.version) {
case 1:
// v1 is default
default:
const yesterday = new Date(Date.now()).setHours(-24);
loginsLast24H = loginsData.reduce(
(total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total),
+24
View File
@@ -99,4 +99,28 @@ describe("widgets/authentik/component", () => {
expectBlockValue(container, "authentik.loginsLast24H", 2);
expectBlockValue(container, "authentik.failedLoginsLast24H", 1);
});
it("falls back to v1 when no version is configured", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-01-02T00:00:00Z"));
const oneHourAgo = Date.now() - 60 * 60 * 1000;
useWidgetAPI.mockImplementation((widget, endpoint) => {
if (endpoint === "users") return { data: { pagination: { count: 5 } }, error: undefined };
if (endpoint === "login") return { data: [{ x_cord: oneHourAgo, y_cord: 2 }], error: undefined };
if (endpoint === "login_failed") return { data: [{ x_cord: oneHourAgo, y_cord: 1 }], error: undefined };
return { data: undefined, error: undefined };
});
// service-helpers sets version to null when the key is absent
const { container } = renderWithProviders(
<Component service={{ widget: { type: "authentik", version: null } }} />,
{ settings: { hideErrors: false } },
);
expectBlockValue(container, "authentik.users", 5);
expectBlockValue(container, "authentik.loginsLast24H", 2);
expectBlockValue(container, "authentik.failedLoginsLast24H", 1);
});
});