43 lines
2.7 KiB
JavaScript
43 lines
2.7 KiB
JavaScript
// Bounded public read-only checks. No credentials are read or sent.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { execFileSync } = require('node:child_process');
|
|
const base = new URL(process.argv[2]);
|
|
if (base.protocol !== 'https:' || base.username || base.password || base.search || base.hash) throw new Error('Provide an HTTPS API base URL');
|
|
const output = path.resolve(process.argv[3] || 'docs/mobile-v1-deployment-check.json');
|
|
async function check(route, engine = false) {
|
|
const url = engine ? `${base.origin}/socket.io/?EIO=4&transport=polling` : `${base.href.replace(/\/$/, '')}${route}`;
|
|
try {
|
|
// curl honors the host's proxy configuration. No credential/header options.
|
|
const raw = execFileSync(process.platform === 'win32' ? 'curl.exe' : 'curl', [
|
|
'--silent', '--show-error', '--connect-timeout', '5', '--max-time', '10',
|
|
'--write-out', '\n%{http_code}', url,
|
|
], { encoding: 'utf8', timeout: 12000, windowsHide: true, maxBuffer: 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
const boundary = raw.lastIndexOf('\n');
|
|
const body = raw.slice(0, boundary);
|
|
const response = { status: Number(raw.slice(boundary + 1)), ok: Number(raw.slice(boundary + 1)) === 200 };
|
|
let data;
|
|
try { data = JSON.parse(body); } catch { /* Non-JSON proxy responses */ }
|
|
const result = { route, status: response.status, authenticated: false };
|
|
if (route === '/health/deployment' && response.ok) result.manifest = data;
|
|
if (route === '/reports/options' && response.ok) {
|
|
const options = data?.data ?? data;
|
|
result.reasonsCount = options?.reasons?.length;
|
|
result.targetedReasons = Array.isArray(options?.reasons) && options.reasons.every((reason) => typeof reason.targetType === 'string');
|
|
}
|
|
if (engine) result.engineHandshake = response.ok && body.startsWith('0') && body.includes('"sid"');
|
|
return result;
|
|
} catch (error) { return { route, error: error.name, status: 0 }; }
|
|
}
|
|
(async () => {
|
|
const checks = [];
|
|
for (const route of ['/health', '/health/deployment', '/reports/options']) checks.push(await check(route));
|
|
checks.push(await check('/socket.io', true));
|
|
const report = { observedAt: new Date().toISOString(), baseUrl: base.href, checks,
|
|
limitations: ['No account writes, old-session refresh, namespace authentication, fan-out, or device delivery tested.',
|
|
'401 does not prove protected controller availability. Polling handshake does not prove namespace authentication or WebSocket upgrade.'] };
|
|
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
fs.writeFileSync(output, JSON.stringify(report, null, 2) + '\n');
|
|
console.log(JSON.stringify(report, null, 2));
|
|
})().catch(() => { console.error('Deployment check failed'); process.exitCode = 1; });
|