43 lines
2.5 KiB
JavaScript
43 lines
2.5 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import assert from 'node:assert/strict';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const source = await fs.readFile('scripts/supplier-evaluation-check.mjs', 'utf8');
|
|
const original = source.slice(source.indexOf('const base ='), source.indexOf('const author ='));
|
|
const common = original.replace(' request,', ` request,
|
|
cookieHeader: () => [...cookies].map(([k, v]) => k + '=' + v).join('; '),`);
|
|
assert.notEqual(common, original, 'Expected existing QA cookie helper');
|
|
|
|
await new Function('fs', 'assert', 'spawn', 'return (async()=>{' + common + `
|
|
const viewer = client();
|
|
await viewer.enter('admin');
|
|
const dashboard = await viewer.request('/dashboard');
|
|
if (dashboard.page?.props.context?.enforced || dashboard.page?.props.workContext?.enforced) {
|
|
await viewer.request('/contexto', 'POST', { area: 'procurement', option: 'procurement.internal' });
|
|
}
|
|
const tenant = dashboard.page?.props.auth?.user?.tenant_id;
|
|
assert.ok(Number.isSafeInteger(tenant) && tenant > 0);
|
|
const result = await new Promise((resolve, reject) => {
|
|
const child = spawn('php', ['scripts/warehouse-http-evaluation.php'], {
|
|
cwd: process.cwd(), windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'], timeout: 30000
|
|
});
|
|
let output = '';
|
|
child.stdout.on('data', chunk => { output += chunk; });
|
|
child.stderr.resume();
|
|
child.on('error', () => reject(new Error('Não foi possível iniciar o ensaio do conector.')));
|
|
child.on('close', code => {
|
|
if (code !== 0) return reject(new Error('A avaliação HTTP do conector não foi aprovada.'));
|
|
try { resolve(JSON.parse(output)); } catch { reject(new Error('Resultado de avaliação inválido.')); }
|
|
});
|
|
// Session travels only over the private child stdin, never in arguments or proof files.
|
|
child.stdin.end(JSON.stringify({ tenant_id: tenant, cookie: viewer.cookieHeader() }));
|
|
});
|
|
assert.equal(result.result, 'passed');
|
|
assert.equal(result.unauthenticated_read_denied, true);
|
|
await fs.writeFile('docs/proofs/warehouse-http-source-http.json', JSON.stringify({
|
|
checked_at: new Date().toISOString(), environment: base, ...result, credentials_recorded: false,
|
|
technical_credential_issued: false, visual_review: false
|
|
}, null, 2));
|
|
console.log('Cliente HTTP autenticado e receptor descartável conferidos contra a avaliação8005.');
|
|
` + '})()')(fs, assert, spawn);
|