mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-03 02:46:01 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b8d44b5439 | |||
| ddc5adc91c |
@@ -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",
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user