Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
+86
@@ -0,0 +1,86 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
const settingsDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const protectedRoutes = [
|
||||
{ name: "general", file: "general.tsx", parserScope: "general" },
|
||||
{ name: "authentication", file: "authentication.tsx", parserScope: "authentication" },
|
||||
{ name: "analytics", file: "analytics.tsx", parserScope: "analytics" },
|
||||
{ name: "cookies", file: "cookies.tsx", parserScope: "cookies" },
|
||||
] as const;
|
||||
|
||||
const transactionalEmailException = {
|
||||
routeFile: "transactional-emails.tsx",
|
||||
testFile: "transactional-emails.test.tsx",
|
||||
serviceImport: "~/modules/emails/services/TransactionalEmailSettings.server",
|
||||
};
|
||||
|
||||
const secretAuditFieldNames = [
|
||||
"headScripts",
|
||||
"bodyScripts",
|
||||
"apiKey",
|
||||
"token",
|
||||
"password",
|
||||
"secret",
|
||||
];
|
||||
|
||||
function readSettingsRoute(file: string) {
|
||||
return readFileSync(join(settingsDir, file), "utf8");
|
||||
}
|
||||
|
||||
function extractActionBody(source: string) {
|
||||
const actionStart = source.indexOf("export const action");
|
||||
expect(actionStart, "route must export an action").toBeGreaterThanOrEqual(0);
|
||||
const componentStart = source.indexOf("export default", actionStart);
|
||||
expect(componentStart, "route must define action before default component").toBeGreaterThan(actionStart);
|
||||
return source.slice(actionStart, componentStart);
|
||||
}
|
||||
|
||||
function removeRedactionHelperCalls(source: string) {
|
||||
return source.replace(/redactSettingsAuditDetails\([^)]*\)/gs, "redactSettingsAuditDetails(<redacted>)");
|
||||
}
|
||||
|
||||
describe("admin settings validation/audit contract", () => {
|
||||
it.each(protectedRoutes)("$name route uses the shared validation service before mutating settings", ({ file, parserScope }) => {
|
||||
const source = readSettingsRoute(file);
|
||||
const actionBody = extractActionBody(source);
|
||||
|
||||
expect(source).toContain('from "~/utils/services/adminSettingsValidation.server"');
|
||||
expect(source).toContain("parseAdminSettingsForm");
|
||||
expect(source).toContain("redactSettingsAuditDetails");
|
||||
expect(actionBody).toContain(`parseAdminSettingsForm("${parserScope}", form)`);
|
||||
expect(actionBody).toContain("if (!parsed.ok)");
|
||||
expect(actionBody).toContain("Response.json({ error: t(\"shared.invalidForm\"), fieldErrors: parsed.errors }, { status: parsed.status })");
|
||||
expect(actionBody).toContain("updateAppConfiguration");
|
||||
expect(actionBody).toContain("createAdminLog");
|
||||
expect(actionBody.indexOf("if (!parsed.ok)")).toBeLessThan(actionBody.indexOf("updateAppConfiguration"));
|
||||
expect(actionBody.indexOf("updateAppConfiguration")).toBeLessThan(actionBody.indexOf("createAdminLog"));
|
||||
});
|
||||
|
||||
it.each(protectedRoutes)("$name route writes audit details only through the redaction helper", ({ file, parserScope }) => {
|
||||
const source = readSettingsRoute(file);
|
||||
const actionBody = extractActionBody(source);
|
||||
const redactionCall = `redactSettingsAuditDetails("${parserScope}"`;
|
||||
|
||||
expect(actionBody).toContain("createAdminLog(request, \"admin.settings.updated\"");
|
||||
expect(actionBody).toContain(redactionCall);
|
||||
|
||||
const unredactedActionBody = removeRedactionHelperCalls(actionBody);
|
||||
for (const fieldName of secretAuditFieldNames) {
|
||||
expect(unredactedActionBody, `${file} must not reference raw audit-sensitive field ${fieldName} outside redactSettingsAuditDetails`).not.toContain(fieldName);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps transactional emails as an explicit provider-settings-service exception", () => {
|
||||
const routeSource = readSettingsRoute(transactionalEmailException.routeFile);
|
||||
const testSource = readSettingsRoute(transactionalEmailException.testFile);
|
||||
|
||||
expect(routeSource).toContain(transactionalEmailException.serviceImport);
|
||||
expect(routeSource).toContain("updateMailjetSettings(form)");
|
||||
expect(testSource).toContain("updateMailjetSettings");
|
||||
expect(testSource).toContain("action rejects provider tampering through the Mailjet update helper");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user