"""Compare the affected HTTP behaviour on the isolated QA, then recover it.""" from pathlib import Path import json,sys,time,hashlib helper=Path(__file__).with_name('audit-http.py').read_text(encoding='utf-8').split("proof={'at'")[0] exec(helper,globals()) QA=Path(json.loads((PRIVATE/'portal-stability-latest.json').read_text(encoding='utf-8'))['source']) service=QA/'app/Services/OpportunityContacts.php';original=ROOT/'app/Services/OpportunityContacts.php' patched=service.read_bytes();before_bytes=original.read_bytes() assert hashlib.sha256(before_bytes).hexdigest()=='e6bd6d786cb8b0ecfcb1e4bbe6778e2bf1cf5460650db2fd9f0e443e096e7827' assert hashlib.sha256(patched).hexdigest()=='d186abf83a959069c61b837a2424ce78719286e32d94672e3eedbe46f419121a' record=json.loads((OUT/'contact-whitespace-after.json').read_text())['record_id'] proof={'at':datetime.now(timezone.utc).isoformat(),'target':TARGET,'base':BASE,'active_writes':0,'browser_observed':False,'record_id':record,'checks':{}} s=Session();stage='isolation' def login(): a=actors['promoter'];assert s.request('GET','/login')[0]==200 assert s.request('POST','/login',{'email':a['email'],'password':a['password']},'application/json')[0] in [200,204,302] assert s.request('GET','/two-factor-challenge')[0]==200 if time.time()%30>26:time.sleep(4) assert s.request('POST','/two-factor-challenge',{'code':otp(a['totp_secret'])},'application/json')[0] in [200,204,302] def draft(): status,_,body=s.request('GET',f'/minhas-oportunidades/{record}/edit');assert status==200;return page(body)['props'] try: status,_,body=s.request('GET','/_qa/runtime',check_target=False);assert status==200 and json.loads(body)['target']['database']=='stability_consumers_20261011_084534_test' login();p=draft() name='Contacto'+' '*146+'QA auditoria' data={'etag':p['etag'],'full_name':name,'email':'audit-normalized-contact@example.invalid','phone':'+258840000008','investor_type':'domestic'} stage='original_HTTP';service.write_bytes(before_bytes);time.sleep(3) status,_,body=s.request('POST',f'/minhas-oportunidades/{record}/contacts',data,'application/json') assert status==422 and 'full_name' in json.loads(body).get('errors',{}) proof['checks']['before_valid_normalized_name_rejected']={'status':status,'incoming_length':len(name),'normalized_length':len('Contacto QA auditoria'),'field':'full_name'} # The global HTTP middleware already trims outer padding: do not claim the # single-character service fixture was also an observed HTTP bypass. status,_,body=s.request('POST',f'/minhas-oportunidades/{record}/contacts',{**data,'full_name':' A '},'application/json') assert status==422;proof['checks']['before_short_name_HTTP_already_protected']=422 stage='corrected_HTTP';service.write_bytes(patched);time.sleep(3) status,_,body=s.request('POST',f'/minhas-oportunidades/{record}/contacts',data,'application/json');assert status==200 result=json.loads(body);assert result['contact']['full_name']=='Contacto QA auditoria';contact_id=result['contact']['id'] status,_,body=s.request('POST',f'/minhas-oportunidades/{record}/contacts',data,'application/json');assert status==200 repeat=json.loads(body);assert repeat['reused'] and repeat['contact']['id']==contact_id proof['checks']['after_name_created_normalized_and_repeated_without_duplicate']={'status':200,'contact_id':contact_id,'reused':True} assert s.request('POST','/logout',{},'application/json')[0] in [200,204,302] s=Session();login();recovered=draft() assert any(c['id']==contact_id and c['full_name']=='Contacto QA auditoria' for c in recovered['canonicalOptions']['contacts']) proof['checks']['contact_recovered_in_new_session']=True assert recovered['values']==p['values'];proof['checks']['existing_draft_content_preserved']=True assert s.request('POST','/logout',{},'application/json')[0] in [200,204,302] proof['result']='passed' except Exception as error:proof.update(result='stopped',stage=stage,error_type=type(error).__name__) finally: service.write_bytes(patched) assert original.read_bytes()==before_bytes proof['active_source_unchanged']=True (OUT/'contact-normalization-http.json').write_text(json.dumps(proof,indent=2),encoding='utf-8') print(json.dumps(proof)) sys.exit(0 if proof['result']=='passed' else 1)