39 lines
5.2 KiB
Python
39 lines
5.2 KiB
Python
from pathlib import Path
|
|
from datetime import datetime,timezone
|
|
import importlib.util,json,hashlib
|
|
OUT=Path(__file__).resolve().parent;spec=importlib.util.spec_from_file_location('transport',OUT/'option-B8-transport.py');lib=importlib.util.module_from_spec(spec);spec.loader.exec_module(lib)
|
|
meta=next(c for c in json.loads((OUT/'QA-credential-correspondence.json').read_text(encoding='utf-8'))['candidates']if c['source_file']=='i0-qa-actor-private.json');assert meta['password_matches']and meta['MFA_secret_matches']and meta['can_manage_portal']
|
|
lib.actors['manager']=json.loads((lib.PRIVATE/'i0-qa-actor-private.json').read_text(encoding='utf-8'));lib.actors['manager']['id']=meta['user_id']
|
|
baseline=json.loads((OUT/'option-B8-path-context-read.json').read_text(encoding='utf-8'));cid=baseline['owned21'][0]['id'];other=baseline['other'][0]['id'];secondary=json.loads((OUT/'option-B8-secondary-progress.json').read_text(encoding='utf-8'));oldcase=secondary['land_case_id'];proof={'at':datetime.now(timezone.utc).isoformat(),'target':lib.TARGET,'active_writes':0,'browser_observed':False};clients=[];stage='owner';code=1
|
|
try:
|
|
owner=lib.Client().login('promoter');clients.append(owner);path=owner.call('GET','/investimentos/'+cid,json_response=False);assert path['path']['tools']['land']=='/investidor/terra-duat/novo?context='+cid
|
|
form=owner.call('GET',path['path']['tools']['land'],json_response=False);assert form['returnDossier']['id']==cid
|
|
payload={'request_description':'SIMULAÇÃO QA B8: apoio fundiário ligado explicitamente ao dossier escolhido, sem misturar projetos','investor_path_case_id':cid}
|
|
created=owner.call('POST','/investidor/terra-duat',{'payload':payload},expected=201);caseid=created['id'];route='/investidor/terra-duat/'+caseid
|
|
progress={'case_id':caseid,'dossier_id':cid};(OUT/'option-B8-context-progress.json').write_text(json.dumps(progress,indent=2),encoding='utf-8')
|
|
x=owner.call('GET',route);assert x['returnDossier']['id']==cid and x['case']['payload']['investor_path_case_id']==cid
|
|
ownother=baseline['owned21'][1]['id'];owner.call('PUT',route,{'version':x['case']['version'],'payload':{**x['case']['payload'],'investor_path_case_id':ownother}},expected=422)
|
|
owner.call('POST','/investidor/terra-duat',{'payload':{**payload,'investor_path_case_id':other}},expected=422);owner.call('GET','/investidor/terra-duat/novo?context='+other,expected=403,json_response=False)
|
|
linked=owner.call('GET','/investimentos/'+cid,json_response=False);assert linked['path']['tools']['land']==route;unrelated=owner.call('GET','/investimentos/'+ownother,json_response=False);assert unrelated['path']['tools']['land']!=route
|
|
assert owner.call('GET','/investidor/terra-duat/'+oldcase)['returnDossier']is None
|
|
owner.logout();clients.remove(owner);owner=lib.Client().login('promoter');clients.append(owner);assert owner.call('GET',route)['returnDossier']['url']=='/investimentos/'+cid;assert owner.call('GET','/investimentos/'+cid,json_response=False)['path']['tools']['land']==route
|
|
stage='manager_document';manager=lib.Client().login('manager');clients.append(manager);p=manager.call('GET','/management/terra-duat/'+oldcase,json_response=False);assert p['management']
|
|
for label,r in secondary['documents'].items():
|
|
if r['consumer']!='land':continue
|
|
# The previous link is still correctly owner-only: this reproduces the original administrative link failure.
|
|
manager.call('GET','/investidor/terra-duat/'+oldcase+'/documentos/'+r['attachment_id'],expected=404)
|
|
st,h,raw=manager.request('GET','/management/terra-duat/'+oldcase+'/documentos/'+r['attachment_id']);assert st==200 and hashlib.sha256(raw).hexdigest()==r['fixture_sha256']
|
|
outsider=lib.Client().login('outsider');clients.append(outsider);outsider.call('GET',route,expected=404)
|
|
for label,r in secondary['documents'].items():
|
|
if r['consumer']=='land':outsider.call('GET','/management/terra-duat/'+oldcase+'/documentos/'+r['attachment_id'],expected=403);lib.Client().call('GET','/management/terra-duat/'+oldcase+'/documentos/'+r['attachment_id'],expected=401)
|
|
st,h,raw=owner.request('GET', '/build/manifest.json',check_target=False);assert st==200;manifest=json.loads(raw)
|
|
appasset=manifest['resources/js/app.tsx']['file'];st,h,raw=owner.request('GET','/build/'+appasset,check_target=False);assert st==200
|
|
proof.update(result='passed',context={'dossier_id':cid,'land_case_id':caseid,'new_session_recovers_bidirectional_links':True,'other_dossier_never_receives_link':True,'foreign_dossier_GET':403,'foreign_dossier_POST':422,'switch_bound_project':422,'old_unbound_case_not_inferred':True},management_document_access={'explicit_permission':'existing manage-portal group','old_owner_URL_denied':404,'correct_management_URL_hash_matches':200,'nonmanager':403,'anonymous':401},bundle={'asset':appasset,'sha256':hashlib.sha256(raw).hexdigest(),'HTTPS':lib.BASE.startswith('https:')});code=0
|
|
except Exception as e:proof.update(result='stopped',stage=stage,error_type=type(e).__name__)
|
|
finally:
|
|
for c in clients:
|
|
try:c.logout()
|
|
except Exception:pass
|
|
proof['requests']=lib.events;dest=OUT/'option-B8-context-access-HTTP.json';assert not dest.exists();dest.write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n',encoding='utf-8');print(json.dumps({k:v for k,v in proof.items()if k!='requests'},ensure_ascii=False))
|
|
raise SystemExit(code)
|