test(runtime): verify live same-origin canary

This commit is contained in:
chick
2026-07-18 15:45:57 +08:00
parent f89f393485
commit 3718c91706
7 changed files with 185 additions and 6 deletions
+34
View File
@@ -0,0 +1,34 @@
const FORBIDDEN_PORT = 8788;
export function parseExternalE2eOrigin(value) {
if (value === undefined) return undefined;
if (value === '') throw new Error('E2E_ORIGIN must not be empty when set.');
let url;
try {
url = new URL(value);
} catch {
throw new Error('E2E_ORIGIN must be a valid absolute URL.');
}
if (
url.protocol !== 'http:' ||
url.hostname !== '127.0.0.1' ||
!url.port ||
url.username ||
url.password ||
url.pathname !== '/' ||
url.search ||
url.hash
) {
throw new Error(
'E2E_ORIGIN must be an HTTP origin on numeric loopback with an explicit port (for example http://127.0.0.1:8789).',
);
}
if (Number(url.port) === FORBIDDEN_PORT) {
throw new Error(`E2E_ORIGIN must not use forbidden legacy port ${FORBIDDEN_PORT}.`);
}
return url.origin;
}