Skip to content

Open-source status page, incident response and uptime monitoring

small fix (#1797)

Thibault Le Ouayc0f52eae395b
diff --git a/apps/server/src/routes/rpc/services/status-report/__tests__/status-report.test.ts b/apps/server/src/routes/rpc/services/status-report/__tests__/status-report.test.ts
index f13daea2f..ea7301924 100644
--- a/apps/server/src/routes/rpc/services/status-report/__tests__/status-report.test.ts
+++ b/apps/server/src/routes/rpc/services/status-report/__tests__/status-report.test.ts
@@ -379,15 +379,34 @@ describe("StatusReportService.CreateStatusReport", () => {
);
});
- test("derives pageId from components when creating status report", async () => {
+ test("returns error when pageId does not match components page", async () => {
const res = await connectRequest(
"CreateStatusReport",
{
- title: `${TEST_PREFIX}-derived-pageid`,
+ title: `${TEST_PREFIX}-pageid-mismatch`,
status: "STATUS_REPORT_STATUS_INVESTIGATING",
- message: "Test deriving pageId from components.",
+ message: "Test pageId mismatch with components.",
date: new Date().toISOString(),
- pageId: "1", // This is ignored, pageId is derived from components
+ pageId: "1", // This doesn't match testPage2ComponentId's page
+ pageComponentIds: [String(testPage2ComponentId)],
+ },
+ { "x-openstatus-key": "1" },
+ );
+
+ expect(res.status).toBe(400);
+ const data = await res.json();
+ expect(data.message).toContain("does not match the page ID");
+ });
+
+ test("creates status report when pageId matches component page", async () => {
+ const res = await connectRequest(
+ "CreateStatusReport",
+ {
+ title: `${TEST_PREFIX}-matching-pageid`,
+ status: "STATUS_REPORT_STATUS_INVESTIGATING",
+ message: "Test with matching pageId and components.",
+ date: new Date().toISOString(),
+ pageId: String(testPage2Id), // Matching the component's page
pageComponentIds: [String(testPage2ComponentId)],
},
{ "x-openstatus-key": "1" },
@@ -401,7 +420,7 @@ describe("StatusReportService.CreateStatusReport", () => {
String(testPage2ComponentId),
);
- // Verify the pageId was derived from the component (page 2)
+ // Verify the pageId was set correctly
const createdReport = await db
.select()
.from(statusReport)
diff --git a/apps/server/src/routes/rpc/services/status-report/errors.ts b/apps/server/src/routes/rpc/services/status-report/errors.ts
index f4101983c..39fe7fbe0 100644
--- a/apps/server/src/routes/rpc/services/status-report/errors.ts
+++ b/apps/server/src/routes/rpc/services/status-report/errors.ts
@@ -10,6 +10,7 @@ export const ErrorReason = {
STATUS_REPORT_UPDATE_FAILED: "STATUS_REPORT_UPDATE_FAILED",
PAGE_COMPONENT_NOT_FOUND: "PAGE_COMPONENT_NOT_FOUND",
PAGE_COMPONENTS_MIXED_PAGES: "PAGE_COMPONENTS_MIXED_PAGES",
+ PAGE_ID_COMPONENT_MISMATCH: "PAGE_ID_COMPONENT_MISMATCH",
INVALID_DATE_FORMAT: "INVALID_DATE_FORMAT",
INVALID_STATUS: "INVALID_STATUS",
} as const;
@@ -139,3 +140,21 @@ export function invalidStatusError(statusValue: number): ConnectError {
{ "status-value": String(statusValue) },
);
}
+
+/**
+ * Creates a "page ID and component page mismatch" error.
+ */
+export function pageIdComponentMismatchError(
+ providedPageId: string,
+ componentPageId: string,
+): ConnectError {
+ return createError(
+ `Page ID ${providedPageId} does not match the page ID ${componentPageId} of the provided components`,
+ Code.InvalidArgument,
+ ErrorReason.PAGE_ID_COMPONENT_MISMATCH,
+ {
+ "provided-page-id": providedPageId,
+ "component-page-id": componentPageId,
+ },
+ );
+}
diff --git a/apps/server/src/routes/rpc/services/status-report/index.ts b/apps/server/src/routes/rpc/services/status-report/index.ts
index 3581cf0d1..53107d622 100644
--- a/apps/server/src/routes/rpc/services/status-report/index.ts
+++ b/apps/server/src/routes/rpc/services/status-report/index.ts
@@ -37,6 +37,7 @@ import {
invalidDateFormatError,
pageComponentNotFoundError,
pageComponentsMixedPagesError,
+ pageIdComponentMismatchError,
statusReportCreateFailedError,
statusReportIdRequiredError,
statusReportNotFoundError,
@@ -280,8 +281,23 @@ export const statusReportServiceImpl: ServiceImpl<typeof StatusReportService> =
tx,
);
- // Derive pageId from validated components (ensures consistency)
- const pageId = validatedComponents.pageId;
+ // Validate that provided pageId matches the components' page
+ const derivedPageId = validatedComponents.pageId;
+ const providedPageId = req.pageId?.trim();
+ if (
+ derivedPageId !== null &&
+ providedPageId &&
+ providedPageId !== "" &&
+ Number(providedPageId) !== derivedPageId
+ ) {
+ throw pageIdComponentMismatchError(
+ providedPageId,
+ String(derivedPageId),
+ );
+ }
+
+ // Use the derived pageId from components (null if no components)
+ const pageId = derivedPageId;
// Create the status report
const report = await tx