Compare commits

...

2 Commits

Author SHA1 Message Date
Crowdin Bot b8d44b5439 New Crowdin translations by GitHub Action
Lint / Linting Checks (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
2026-09-03 00:54:20 +00:00
shamoon ddc5adc91c Fix: handle literal null from crowdsec api alerts (#7088)
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
2026-09-02 12:40:40 -07:00
5 changed files with 46 additions and 5 deletions
+4 -4
View File
@@ -21,7 +21,7 @@
"seconds": "s"
},
"auth": {
"signout": "Sign out"
"signout": "Teken uit"
},
"widget": {
"missing_type": "Ontbrekende legstuk-tipe: {{type}}",
@@ -40,8 +40,8 @@
},
"search": {
"placeholder": "Soek…",
"provider": "Search engine: {{name}}",
"select_provider": "Select search engine"
"provider": "Soekenjin: {{name}}",
"select_provider": "Kies soekenjin"
},
"resources": {
"cpu": "SVE",
@@ -474,7 +474,7 @@
"users": "Gebruikers",
"loginsLast24H": "Aantekenings (24h)",
"failedLoginsLast24H": "Mislukte Aantekenings (24h)",
"authorizationsLast24H": "Auths (24h)"
"authorizationsLast24H": "Magtigings (24h)"
},
"proxmox": {
"mem": "GEH",
+1 -1
View File
@@ -21,7 +21,7 @@ export default function Component({ service }) {
return <Container service={service} error={alertsError ?? bansError} />;
}
if (!alerts && !bans) {
if (alerts === undefined && bans === undefined) {
return (
<Container service={service}>
<Block label="crowdsec.alerts" />
+11
View File
@@ -86,4 +86,15 @@ describe("widgets/crowdsec/component", () => {
expectBlockValue(container, "crowdsec.alerts", 499);
});
it("renders null responses as 0 counts", () => {
useWidgetAPI.mockImplementation(() => ({ data: null, error: undefined }));
const { container } = renderWithProviders(<Component service={{ widget: { type: "crowdsec" } }} />, {
settings: { hideErrors: false },
});
expectBlockValue(container, "crowdsec.alerts", 0);
expectBlockValue(container, "crowdsec.bans", 0);
});
});
+5
View File
@@ -102,6 +102,11 @@ export default async function crowdsecProxyHandler(req, res) {
return res.status(status).json({ error: "Crowdsec API Error", data });
}
// Crowdsec returns a literal null instead of an empty array when nothing matches
if (data?.toString().trim() === "null") {
return res.status(status).json([]);
}
return res.status(status).send(data);
} catch (error) {
logger.error("Exception calling Crowdsec API: %s", error.message);
+25
View File
@@ -161,4 +161,29 @@ describe("widgets/crowdsec/proxy", () => {
expect(res.statusCode).toBe(500);
expect(res.body).toEqual({ error: "Failed to authenticate with Crowdsec" });
});
it("normalizes a literal null response to an empty array", async () => {
getServiceWidget.mockResolvedValue({
type: "crowdsec",
url: "http://cs",
username: "machine",
password: "pw",
});
httpProxy
.mockResolvedValueOnce([
200,
"application/json",
JSON.stringify({ token: "tok", expire: new Date(Date.now() + 60_000).toISOString() }),
])
.mockResolvedValueOnce([200, "application/json", Buffer.from("null")]);
const req = { query: { group: "g", service: "svc", endpoint: "alerts", index: "0" } };
const res = createMockRes();
await crowdsecProxyHandler(req, res);
expect(res.statusCode).toBe(200);
expect(res.body).toEqual([]);
});
});