37 lines
3.3 KiB
Python
37 lines
3.3 KiB
Python
from pathlib import Path, PurePosixPath
|
|
import hashlib, json, zipfile, datetime
|
|
root=Path(__file__).resolve().parents[2]
|
|
release=root/'outputs/investmoz-classificacao-multidimensional-QA-20261015'
|
|
out=Path(__file__).resolve().parent
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
r=json.loads((release/'RECIBO-INTEGRIDADE.json').read_text('utf-8'))
|
|
assert r['candidate']=='classificacao-multidimensional-QA-64ab05e20b95' and r['document_revision']=='DOC01'
|
|
assert sha(release/'RECIBO-INTEGRIDADE.json')=='5e6fc4e3661de95c18e3192dfe3f68c048a5e676b0df44485a0a0650ab032505'
|
|
archive=root/'outputs'/r['zip']['name']
|
|
assert sha(archive)==r['zip']['sha256']=='334d8ef2e47848a3c30cf526ae4d394004f112288cdddbcf635f06a1be1e0bc6'
|
|
assert archive.stat().st_size==r['zip']['bytes']
|
|
with zipfile.ZipFile(archive) as z:
|
|
assert z.testzip() is None
|
|
assert len(z.namelist())==len(set(z.namelist()))==234
|
|
manifest_bytes=z.read('MANIFESTO-ENTREGA.json')
|
|
assert hashlib.sha256(manifest_bytes).hexdigest()==r['manifest_sha256']
|
|
assert manifest_bytes==(release/'MANIFESTO-ENTREGA.json').read_bytes()
|
|
m=json.loads(manifest_bytes)
|
|
for p in m['payload']:
|
|
assert not PurePosixPath(p['path']).is_absolute() and '..' not in PurePosixPath(p['path']).parts
|
|
b=z.read(p['path']);assert hashlib.sha256(b).hexdigest()==p['sha256'] and len(b)==p['bytes']
|
|
for name,h in r['documents'].items():assert sha(release/name)==h
|
|
assert len(m['sources'])==17 and sum(x['operation']=='replace' for x in m['sources'])==14
|
|
for s in m['sources']:
|
|
p=root/s['path'];assert (sha(p) if p.is_file() else None)==s['previous_sha256'], 'Source diverged: '+s['path']
|
|
assert hashlib.sha256(z.read('fontes/'+s['path'])).hexdigest()==s['candidate_sha256']
|
|
assert sha(root/'public/build/manifest.json')==m['previous_build_manifest_sha256']
|
|
baseline=json.loads((release/'ATIVO-FICHEIROS-ANTES.json').read_text('utf-8'))
|
|
for n,h in baseline.items():assert (root/n).is_file() and sha(root/n)==h,'Protected source/build diverged: '+n
|
|
assert not (root/'public/hot').exists() and not (root/'storage/framework/down').exists()
|
|
protected=['.env','composer.lock','package-lock.json','bootstrap/app.php','config/inertia.php','config/portal.php','config/investor-path.php']
|
|
record={'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'candidate':m['candidate'],'document_revision':'DOC01','authorization':'Tempo: A Tempo autoriza a disponibilizaçaõ (current conversation)','receipt_sha256':sha(release/'RECIBO-INTEGRIDADE.json'),'archive_sha256':sha(archive),'manifest_sha256':r['manifest_sha256'],'payload_hashes_verified':len(m['payload']),'previous_sources_verified':14,'new_paths_absent':3,'protected_baseline_files_verified':len(baseline),'protected_files':{n:sha(root/n) for n in protected},'previous_build_files':{p.relative_to(root/'public/build').as_posix():sha(p) for p in (root/'public/build').rglob('*') if p.is_file()},'matrix_sha256':sha(root/'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv'),'active_business_writes':0}
|
|
assert not (out/'PREFLIGHT.json').exists()
|
|
(out/'PREFLIGHT.json').write_text(json.dumps(record,ensure_ascii=False,indent=2)+'\n','utf-8')
|
|
print(json.dumps({k:v for k,v in record.items() if k not in ['protected_files','previous_build_files']},ensure_ascii=True))
|