"""HTTPS/runtime/static GET checks; no login, domain records or UI claims.""" from pathlib import Path from datetime import datetime, timezone from concurrent.futures import ThreadPoolExecutor from http.cookies import SimpleCookie import hashlib, json, re, secrets, urllib.request, urllib.error, sys ROOT=Path(__file__).resolve().parents[2] OUT=ROOT/'outputs/investmoz-workflow-opening-20261012' PHASE=sys.argv[1]; assert PHASE in ['staged','enabled'] BASE='https://portal-investidor.test' MANIFEST=json.loads((ROOT/'outputs/investmoz-staff-preparation-20261012/abertura-workflow-2e2f16c83483/manifesto-final.json').read_text()) class NoRedirect(urllib.request.HTTPRedirectHandler): def redirect_request(self,req,fp,code,msg,headers,newurl): return None opener=urllib.request.build_opener(NoRedirect()) def get(path,headers=None,base=BASE): request=urllib.request.Request(base+path,headers={'Accept-Encoding':'identity',**(headers or {})}) try: response=opener.open(request,timeout=20) except urllib.error.HTTPError as response: return response.code,response.headers,response.read() with response: return response.status,response.headers,response.read() nonce=secrets.token_hex(32); token_hash=hashlib.sha256(nonce.encode()).hexdigest() probe=ROOT/'public'/('.workflow-opening-check-'+secrets.token_hex(12)+'.php') assert probe.resolve().is_relative_to((ROOT/'public').resolve()) and not probe.exists() php_files=[x['path'] for x in MANIFEST['source_files'] if x['path'].endswith('.php')] source='''bootstrap($app);(new Illuminate\\Foundation\\Bootstrap\\LoadConfiguration)->bootstrap($app); $flags=[];foreach(config('portal') as $key=>$value)if(str_ends_with($key,'_enabled'))$flags[$key]=(bool)$value; $flags['investor_path_enabled']=(bool)config('investor-path.enabled'); $connection=config('database.connections.'.config('database.default')); $result=['result'=>'passed','sapi'=>PHP_SAPI,'php'=>PHP_VERSION,'HTTPS'=>($_SERVER['HTTPS']??'')==='on','target'=>$connection['database'].':'.$connection['port'],'flags'=>$flags,'config_cached'=>$app->configurationIsCached(),'opcache_invalidated'=>$invalidated,'contact_service_loaded'=>class_exists(App\\Services\\OpportunityContacts::class),'contact_controller_loaded'=>method_exists(App\\Http\\Controllers\\PortalProfileController::class,'contact'),'upload'=>ini_get('upload_max_filesize'),'post'=>ini_get('post_max_size'),'gd'=>extension_loaded('gd'),'webp'=>function_exists('imagewebp'),'database_writes'=>0]; echo json_encode($result,JSON_THROW_ON_ERROR); }catch(Throwable $e){http_response_code(500);echo json_encode(['result'=>'failed','type'=>$e::class]);} '''.replace('TOKENHASH',token_hash).replace('FILESJSON',json.dumps(php_files,separators=(',',':'))) proof={'at':datetime.now(timezone.utc).isoformat(),'phase':PHASE,'delivery':'2e2f16c83483','TLS_bypass':False,'UI_observed':False,'login_MFA_repeated':False,'business_records_created':0} try: probe.write_text(source,encoding='utf-8') status,headers,body=get('/'+probe.name,{'X-InvestMoz-Technical-Probe':nonce}) assert status==200 runtime=json.loads(body); proof['web_runtime']=runtime assert runtime['result']=='passed' and runtime['sapi']=='apache2handler' and runtime['HTTPS'] assert runtime['target']=='investemoz:5432' and runtime['php']=='8.5.11' assert runtime['contact_service_loaded'] and runtime['contact_controller_loaded'] and not runtime['config_cached'] assert runtime['gd'] and runtime['webp'] and runtime['upload']=='20M' and runtime['post']=='24M' expected=json.loads((OUT/('destino-codigo-gates-off.json' if PHASE=='staged' else 'destino-aberto.json')).read_text())['flags'] assert runtime['flags']==expected assert get('/'+probe.name)[0]==404 status,headers,body=get('/login'); assert status==200 html=body.decode('utf-8'); proof['login']={'status':status,'cookies':[]} for value in headers.get_all('Set-Cookie',[]): jar=SimpleCookie();jar.load(value) for name,cookie in jar.items(): proof['login']['cookies'].append({'name':name,'secure':bool(cookie['secure']),'http_only':bool(cookie['httponly']),'same_site':cookie['samesite'],'path':cookie['path'],'domain':cookie['domain']}) session=[x for x in proof['login']['cookies'] if x['name']=='portal_investidor_https'] assert len(session)==1 and session[0]['secure'] and session[0]['http_only'] and session[0]['same_site'].lower()=='lax' resources=re.findall(r'(?:src|href)=["\']([^"\']+)["\']',html) assert not any(x.startswith('http://') for x in resources),'Mixed HTML resource' assert any('/build/assets/app-' in x for x in resources) proof['login']['insecure_resource_links']=0 proof['routes']=[] for path in ['/dashboard','/minhas-oportunidades','/minhas-oportunidades/create','/perfis/gestao']: status,headers,_=get(path) location=headers.get('Location','');assert status==302 and location==BASE+'/login' proof['routes'].append({'path':path,'unauthenticated_status':status,'redirect_path':'/login'}) def check(item): status,_,body=get('/'+item['path'].removeprefix('public/')) assert status==200 and hashlib.sha256(body).hexdigest()==item['sha256'],item['path'] return item['path'] with ThreadPoolExecutor(max_workers=4) as pool: checked=list(pool.map(check,MANIFEST['compiled_resources'])) proof['compiled_resources_served_and_hashed']=len(checked) status,headers,_=get('/login',base='http://portal-investidor.test') assert status==308 and headers.get('Location')==BASE+'/login' proof['HTTP_to_HTTPS']=308 proof['result']='passed' except Exception as error: proof['result']='stopped';proof['error_class']=type(error).__name__;raise finally: if probe.exists(): assert probe.read_text(encoding='utf-8')==source probe.unlink() proof['ephemeral_probe_removed']=not probe.exists() (OUT/('web-'+PHASE+'.json')).write_text(json.dumps(proof,indent=2),encoding='utf-8') print(json.dumps({k:proof[k] for k in ['result','phase','delivery','TLS_bypass','UI_observed','ephemeral_probe_removed']}))