Files
Investidor-V2/outputs/investmoz-classificacao-ativacao-20261015/http-operacional.py
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

33 lines
2.8 KiB
Python

from pathlib import Path
import urllib.request,urllib.error,urllib.parse,ssl,json,hashlib,datetime,sys
from html.parser import HTMLParser
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
phase=sys.argv[1];assert phase in ['before','after']
base='https://portal-investidor.test'
ctx=ssl.create_default_context(cafile='C:/Users/macbook/.config/investmoz/tls/portal-investidor.test-fullchain.pem')
class Parser(HTMLParser):
def __init__(self):super().__init__();self.on=False;self.data=[];self.assets=[]
def handle_starttag(self,t,a):
a=dict(a)
if t=='script' and a.get('type')=='application/json':self.on=True
if t=='script' and a.get('type')=='module' and a.get('src'):self.assets.append(a['src'])
if t=='link' and a.get('rel')=='stylesheet' and '/build/' in a.get('href',''):self.assets.append(a['href'])
def handle_endtag(self,t):
if t=='script':self.on=False
def handle_data(self,d):
if self.on:self.data.append(d)
with urllib.request.urlopen(base+'/up',context=ctx,timeout=30) as response:assert response.status==200
with urllib.request.urlopen(urllib.request.Request(base+'/oportunidades',headers={'Accept':'text/html'}),context=ctx,timeout=30) as response:
assert response.status==200;p=Parser();p.feed(response.read().decode('utf-8'));v=json.loads(''.join(p.data))
assert v['component']=='investment/catalogue' and v['props']['auth']['user'] is None
result=v['props']['results'];public={'total':result['total'],'first_page':[{'id':x['id'],'slug':x['slug'],'title':x['title']} for x in result['data']]}
assets=[]
for url in p.assets:
path=urllib.parse.urlsplit(url).path;assert path.startswith('/build/')
with urllib.request.urlopen(base+path,context=ctx,timeout=30) as response:
assert response.status==200;h=hashlib.sha256(response.read()).hexdigest();assert h==hashlib.sha256((root/'public'/path.lstrip('/')).read_bytes()).hexdigest();assets.append({'path':path,'status':200,'sha256':h})
if phase=='after':assert public==json.loads((out/'HTTP-BEFORE.json').read_text('utf-8'))['public_catalogue']
proof={'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'candidate':'classificacao-multidimensional-QA-64ab05e20b95','phase':phase,'TLS_certificate_and_hostname_verified':True,'checks':[{'method':'GET','path':'/up','status':200},{'method':'GET','path':'/oportunidades','status':200,'anonymous':True}],'public_catalogue':public,'served_entry_assets':assets,'public_catalogue_preserved':phase=='after','business_writes':0,'functional_QA_repeated':False}
file=out/('HTTP-'+phase.upper()+'.json');assert not file.exists();file.write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n','utf-8')
print(json.dumps({'phase':phase,'operational_GETs':2,'served_assets_verified':len(assets),'public_total':public['total'],'catalogue_preserved':phase=='after'}))