Files
Investidor-V2/outputs/investmoz-audit-current-20261012/verify-case32-reauth-assets-20261014.py
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

55 lines
2.9 KiB
Python

from pathlib import Path
from urllib.request import urlopen
from urllib.parse import urlparse, urljoin
from datetime import datetime, timezone
import hashlib
import json
import re
import ssl
OUT = Path(__file__).resolve().parent
ROOT = OUT.parents[1]
QA = ROOT / 'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'
BASE = 'https://portal-investidor.test:18445'
DEST = OUT / 'case32-reauth-loaded-assets-20261014.json'
assert not DEST.exists()
ctx = ssl.create_default_context()
def get(path):
with urlopen(BASE + path, context=ctx, timeout=20) as response:
assert response.status == 200
assert (urlparse(response.url).hostname, urlparse(response.url).port) == ('portal-investidor.test', 18445)
return response.read()
runtime = json.loads(get('/_qa/runtime'))
assert runtime['target']['database'] == 'stability_consumers_20261011_084534_test' and int(runtime['target']['port']) == 55441
manifest_bytes = get('/build/manifest.json')
assert manifest_bytes == (QA / 'public/build/manifest.json').read_bytes()
manifest = json.loads(manifest_bytes)
login = get('/login').decode('utf-8')
scripts = [value for _, value in re.findall(r'<script\b[^>]*\bsrc=([\"\x27])([^\"\x27]+)\1', login)]
app = manifest['resources/js/app.tsx']['file']
assert any(urlparse(urljoin(BASE, value)).path == '/build/' + app for value in scripts)
page = manifest['resources/js/pages/management/opportunity-draft.tsx']['file']
checks = []
for file in [app, page]:
binary = get('/build/' + file)
assert binary == (QA / 'public/build' / file).read_bytes()
checks.append({'path': '/build/' + file, 'status': 200, 'sha256': hashlib.sha256(binary).hexdigest()})
page_bytes = (QA / 'public/build' / page).read_bytes()
imports = manifest['resources/js/pages/management/opportunity-draft.tsx'].get('imports', [])
chunk_bytes = page_bytes
for item in imports:
if item in manifest:
chunk = manifest[item]['file']
data = get('/build/' + chunk)
assert data == (QA / 'public/build' / chunk).read_bytes()
chunk_bytes += data
assert 'Entrar novamente nesta janela'.encode() in chunk_bytes
assert 'X-Portal-Reauthentication'.encode() in chunk_bytes
receipt = {'at': datetime.now(timezone.utc).isoformat(), 'result': 'passed', 'target': runtime['target'],
'HTTPS_validation_bypassed': False, 'server_manifest_sha256': hashlib.sha256(manifest_bytes).hexdigest(),
'login_HTML_uses_current_app_chunk': True, 'reauthentication_code_served_with_matching_hashes': True,
'checked_entry_assets': checks, 'active_changes': 0, 'visual_acceptance': False,
'limits': ['Verifies assets served by QA, not the cache or DOM in the user browser.', 'No credentials or cookies recorded.']}
DEST.write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
print(json.dumps({'result': 'passed', 'current_QA_assets_verified': True, 'visual_acceptance': False}))