38 lines
2.8 KiB
JavaScript
38 lines
2.8 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { createRequire } from 'node:module';
|
|
import assert from 'node:assert/strict';
|
|
const out = path.dirname(fileURLToPath(import.meta.url));
|
|
const qa = path.resolve(out, '../../storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742');
|
|
const destination = path.join(out, 'case32-reauth-transport-QA-20261014.json');
|
|
try { await fs.access(destination); throw Error('Regressão já registada.'); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
const require = createRequire(path.join(qa, 'package.json'));
|
|
const ts = require('typescript');
|
|
const source = await fs.readFile(path.join(qa, 'resources/js/lib/profile-json.ts'), 'utf8');
|
|
const code = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } }).outputText;
|
|
const { profileJson, ProfileValidationError } = await import('data:text/javascript;base64,' + Buffer.from(code).toString('base64'));
|
|
globalThis.document = { cookie: '' };
|
|
const results = {};
|
|
async function rejected(body, status, headers = {}) {
|
|
globalThis.fetch = async () => new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json', ...headers } });
|
|
try { await profileJson('/minhas-oportunidades/32/workflow', {}); throw Error('Erro esperado.'); }
|
|
catch (error) { assert(error instanceof ProfileValidationError); return error; }
|
|
}
|
|
let failure = await rejected({ message: 'Renove MFA nesta janela.' }, 403, { 'X-Portal-Reauthentication': 'required' });
|
|
assert.equal(failure.reauthenticate, true);
|
|
results.MFA_403_enables_same_window_reauthentication = true;
|
|
failure = await rejected({ message: 'Perfil não autorizado.' }, 403);
|
|
assert.equal(failure.reauthenticate, false);
|
|
results.unrelated_403_does_not_request_MFA_or_grant_access = true;
|
|
failure = await rejected({ message: 'Validação rejeitada.', errors: { reason: ['Fundamentação insuficiente.'] } }, 422);
|
|
assert.equal(failure.fields.reason, 'Fundamentação insuficiente.');
|
|
assert.equal(failure.reauthenticate, false);
|
|
results.field_validation_errors_remain_available = true;
|
|
globalThis.fetch = async () => new Response(JSON.stringify({ status: 'in_review', message: 'Ação registada.' }), { status: 200 });
|
|
assert.equal((await profileJson('/minhas-oportunidades/32/workflow', {})).status, 'in_review');
|
|
results.success_response_unchanged = true;
|
|
await fs.writeFile(destination, JSON.stringify({ at: new Date().toISOString(), result: 'passed', tests: results,
|
|
mocked_transport_only: true, network_requests: 0, active_changes: 0, visual_acceptance: false }, null, 2));
|
|
console.log(JSON.stringify({ result: 'passed', transport_cases: Object.keys(results).length, network_requests: 0 }));
|