Files
Investidor-V2/tools/portal-functional-document-images-qa.cjs
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

14 lines
3.8 KiB
JavaScript

const {start,assert,DIR,path,fs,sanitized,TARGET}=require('./portal-functional-qa-lib.cjs');
void(async()=>{const q=await start('functional-document-images-chromium-20261011');const contexts=[];try{
const inspection=JSON.parse(fs.readFileSync(path.join(DIR,'functional-scope-inspection-qa-20261011.json'),'utf8'));const image=inspection.images.find(i=>i.opportunity_id===33);assert(image);const original=image.documents.find(d=>d.source_system==='opportunity-resources'),derivatives=image.documents.filter(d=>d.source_system==='opportunity-image-derivatives');assert(original&&derivatives.length===2);
async function actor(role){const a=await q.context(role);contexts.push(a.ctx);await q.login(a.page,role);return a.page;}
async function binary(page,url){const out=await page.evaluate(async u=>{const r=await fetch(u,{headers:{Accept:'application/json'}}),b=await r.arrayBuffer(),h=await crypto.subtle.digest('SHA-256',b);return {status:r.status,target:r.headers.get('X-Investmoz-QA-Target'),sha256:[...new Uint8Array(h)].map(v=>v.toString(16).padStart(2,'0')).join(''),final_path:new URL(r.url).pathname};},url);assert.equal(out.target,TARGET);return out;}
const promoter=await actor('promoter');await q.open(promoter,'/minhas-oportunidades/33/resources');await promoter.getByRole('button',{name:'Imagens',exact:true}).click();const preview=promoter.locator('img[src*="/resources/images/"]').first();await preview.waitFor();const signed=await preview.getAttribute('src');const recovered=await binary(promoter,signed);assert.equal(recovered.status,200);assert(derivatives.some(d=>d.sha256===recovered.sha256));assert.equal((await binary(promoter,`/minhas-oportunidades/33/resources/images/${image.resource_id}/download`)).sha256,original.sha256);await preview.scrollIntoViewIfNeeded();await q.shot(promoter,'private-image-and-derivative-authorized',false);q.proof.checks.original_and_signed_derivative_hashes_recovered=true;
const manager=await actor('manager');for(const d of image.documents)assert.equal((await binary(manager,'/management/documents/'+d.id+'/download')).status,403);assert.equal((await binary(manager,signed)).status,403);q.proof.checks.general_alias_and_signed_url_deny_unscoped_manager=true;
const source=await binary(manager,'/management/documents/589ed9ac-967e-439e-9dde-b0fb3996e546/download');assert.equal(source.status,200);assert.equal(source.sha256,'bf26caeee0437a8d292bf29be59247e2862c14e79b5ae465c00322747af72af5');q.proof.checks.accepted_library_original_unaffected=true;
const resources=await q.json(manager,'/management/opportunity-resources-install');assert.equal(resources.status,200);assert(resources.data.installed);q.proof.resources_preview=resources.data;
const superuser=await actor('super_first');const profile=await q.json(superuser,'/management/profile-install');assert.equal(profile.status,200);assert(profile.data.installed);assert(Object.values(profile.data.dependencies).every(Boolean));q.proof.profiles_preview=profile.data;q.proof.checks.dependencies_030000_before_040000_installed_consistent_QA=true;
const anonymous=await q.context('anonymous');contexts.push(anonymous.ctx);await q.open(anonymous.page,'/login');const denied=await binary(anonymous.page,signed);assert(denied.status!==200||denied.final_path==='/login');assert.notEqual(denied.sha256,recovered.sha256);q.proof.checks.public_teaser_does_not_publish_signed_image=true;
q.proof.image={resource_id:image.resource_id,opportunity_id:33,original_sha256:original.sha256,derivative_sha256:recovered.sha256};q.proof.AB_C37_not_repeated=true;q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',checks:q.proof.checks,active_writes:0}));
}catch(e){q.proof.result='failed';q.proof.failure=sanitized(e);q.save();console.log(JSON.stringify({result:'failed',failure:q.proof.failure,active_writes:0}));process.exitCode=1;}finally{for(const c of contexts)await c.close();await q.browser.close();}})();