Guard API tests against destructive non-loopback targets
This commit is contained in:
1 parent
4e47e350bf
commit
7627c36642
3 files changed
+33
-1
No files matched your search
@@ -20,3 +20,24 @@ export const RUNTIME_DIR = path.join(
|
||||
export const COVERAGE_DIR = path.join(RUNTIME_DIR, 'coverage');
|
||||
export const SEED_FILE = path.join(RUNTIME_DIR, 'seed.json');
|
||||
export const OPENAPI_FILE = path.join(ROOT_DIR, 'public/openapi.json');
|
||||
|
||||
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
||||
|
||||
/**
|
||||
* The suite is destructive: global setup deletes and recreates fixed-ID websites
|
||||
* and ingests analytics data, and specs toggle the global 2FA requirement. Only
|
||||
* loopback targets (the local Compose stack) run without an explicit opt-in.
|
||||
*/
|
||||
export function assertDisposableTarget(baseURL: string) {
|
||||
const { hostname } = new URL(baseURL);
|
||||
|
||||
if (LOOPBACK_HOSTS.has(hostname) || process.env.API_ALLOW_DESTRUCTIVE === '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Refusing to run the API suite against ${baseURL}: it deletes and recreates websites, ` +
|
||||
'ingests analytics data and changes the global 2FA setting. Point PLAYWRIGHT_BASE_URL ' +
|
||||
'at a disposable server and set API_ALLOW_DESTRUCTIVE=1 to confirm.',
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user