Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const appDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const coreRootSurfaceSource = readFileSync(path.join(appDirectory, "root-core-surface.tsx"), "utf8");
|
||||
const rootDataSource = readFileSync(path.join(appDirectory, "utils", "data", ".server", "rootData.ts"), "utf8");
|
||||
const entryServerSource = readFileSync(path.join(appDirectory, "entry.server.tsx"), "utf8");
|
||||
|
||||
describe("root CSP nonce wiring", () => {
|
||||
it("passes the loader nonce to every server-rendered executable script surface", () => {
|
||||
expect(rootDataSource).toContain("const cspNonce = getRequestCspNonce(request)");
|
||||
expect(rootDataSource).toContain("cspNonce,");
|
||||
expect(coreRootSurfaceSource).toContain("<ScrollRestoration nonce={cspNonce} />");
|
||||
expect(coreRootSurfaceSource).toContain("<Scripts nonce={cspNonce} />");
|
||||
expect(coreRootSurfaceSource).toContain('<script nonce={cspNonce} dangerouslySetInnerHTML={{ __html: SERVICE_WORKER_RECOVERY_BOOTSTRAP }} />');
|
||||
expect(coreRootSurfaceSource).toMatch(/<script nonce=\{cspNonce\}[^>]+widget\.trustpilot\.com/u);
|
||||
expect(coreRootSurfaceSource).toContain("<ScriptAnalytics nonce={cspNonce} />");
|
||||
expect(coreRootSurfaceSource).toContain("scripts={customScriptsEnabled ? rootData.appConfiguration?.scripts : undefined}");
|
||||
});
|
||||
|
||||
it("runs the static service-worker recovery bootstrap before stylesheet discovery", () => {
|
||||
const recoveryScriptIndex = coreRootSurfaceSource.indexOf(
|
||||
'<script nonce={cspNonce} dangerouslySetInnerHTML={{ __html: SERVICE_WORKER_RECOVERY_BOOTSTRAP }} />'
|
||||
);
|
||||
const linksIndex = coreRootSurfaceSource.indexOf("<Links />");
|
||||
|
||||
expect(recoveryScriptIndex).toBeGreaterThan(0);
|
||||
expect(linksIndex).toBeGreaterThan(recoveryScriptIndex);
|
||||
});
|
||||
|
||||
it("gates the Trustpilot connection and script on public-surface functional consent", () => {
|
||||
expect(coreRootSurfaceSource).toContain("const trustpilotEnabled =");
|
||||
expect(coreRootSurfaceSource).toContain("CookieHelper.hasConsent(rootData.userSession ?? null, CookieCategory.FUNCTIONAL)");
|
||||
expect(coreRootSurfaceSource).toContain("{trustpilotEnabled && (");
|
||||
});
|
||||
|
||||
it("keeps administrator-authored custom scripts off authenticated surfaces and behind advertisement consent", () => {
|
||||
expect(coreRootSurfaceSource).toContain("const customScriptsEnabled =");
|
||||
expect(coreRootSurfaceSource).toContain("CookieHelper.hasConsent(rootData.userSession ?? null, CookieCategory.ADVERTISEMENT)");
|
||||
expect(coreRootSurfaceSource).toContain("scripts={customScriptsEnabled ? rootData.appConfiguration?.scripts : undefined}");
|
||||
});
|
||||
|
||||
it("keeps the original document nonce stable across client loader revalidations", () => {
|
||||
expect(coreRootSurfaceSource).toContain("const cspNonce = useStableDocumentCspNonce(rootData.cspNonce)");
|
||||
expect(coreRootSurfaceSource).toContain('typeof document === "undefined" ? loaderNonce : (getCurrentDocumentCspNonce(document) ?? loaderNonce)');
|
||||
});
|
||||
|
||||
it("gives React Router the same internal request nonce for streamed framework scripts", () => {
|
||||
expect(entryServerSource).toContain("const cspNonce = getRequestCspNonce(request)");
|
||||
expect(entryServerSource).toContain("<ServerRouter context={reactRouterContext} url={request.url} nonce={cspNonce} />");
|
||||
expect(entryServerSource).toMatch(/renderToPipeableStream\([\s\S]+nonce: cspNonce,/u);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user