35 lines
1,023 B
TypeScript
35 lines
1,023 B
TypeScript
/**
|
|
* Global Setup - E2E Production Auth Tests
|
|
*
|
|
* Runs once before all tests to ensure a clean rate limit state.
|
|
* Flushes all throttle:* keys from SSO Redis.
|
|
*/
|
|
|
|
import { execFileSync } from 'child_process';
|
|
|
|
const REDIS_HOST = process.env.REDIS_HOST || 'sso-redis';
|
|
const REDIS_PORT = process.env.REDIS_PORT || '26379';
|
|
|
|
export default async function globalSetup(): Promise<void> {
|
|
try {
|
|
const result = execFileSync(
|
|
'redis-cli',
|
|
[
|
|
'-h',
|
|
REDIS_HOST,
|
|
'-p',
|
|
REDIS_PORT,
|
|
'EVAL',
|
|
'local keys = redis.call("keys", ARGV[1]) for i=1,#keys do redis.call("del", keys[i]) end return #keys',
|
|
'0',
|
|
'throttle:*',
|
|
],
|
|
{ timeout: 5000, encoding: 'utf-8' }
|
|
);
|
|
console.log(`[global-setup] Flushed throttle keys from Redis: ${result.trim()}`);
|
|
} catch (error) {
|
|
console.warn(
|
|
`[global-setup] Could not flush throttle keys (redis-cli may not be available): ${error instanceof Error ? error.message : error}`
|
|
);
|
|
}
|
|
}
|