40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
const frontendBase = process.env.PIM_FRONTEND_URL?.replace(/\/$/, '');
|
|
const backendBase = process.env.PIM_BACKEND_URL?.replace(/\/$/, '');
|
|
|
|
if (!frontendBase || !backendBase) {
|
|
console.error('Set PIM_FRONTEND_URL and PIM_BACKEND_URL before running this smoke test.');
|
|
process.exit(2);
|
|
}
|
|
|
|
async function checkFrontend() {
|
|
const response = await fetch(`${frontendBase}/sso/callback`);
|
|
const body = await response.text();
|
|
if (!response.ok || !body.toLowerCase().includes('<div id="root"></div>')) {
|
|
throw new Error(`Frontend callback is not serving the PIM application (HTTP ${response.status})`);
|
|
}
|
|
return response.status;
|
|
}
|
|
|
|
async function checkBackend() {
|
|
const response = await fetch(`${backendBase}/api/v1/auth/sso/exchange`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ grant: 'invalid-deployment-smoke-test' })
|
|
});
|
|
if (response.status === 404) {
|
|
throw new Error('Backend SSO exchange endpoint is not deployed (HTTP 404)');
|
|
}
|
|
if (response.status < 400 || response.status >= 500) {
|
|
throw new Error(`Backend did not safely reject the invalid smoke-test grant (HTTP ${response.status})`);
|
|
}
|
|
return response.status;
|
|
}
|
|
|
|
try {
|
|
const [frontendStatus, backendRejectionStatus] = await Promise.all([checkFrontend(), checkBackend()]);
|
|
console.log(JSON.stringify({ success: true, frontendStatus, backendRejectionStatus }, null, 2));
|
|
} catch (error) {
|
|
console.error(JSON.stringify({ success: false, message: error.message }, null, 2));
|
|
process.exit(1);
|
|
}
|