73 lines
3.8 KiB
Python
73 lines
3.8 KiB
Python
import importlib.util
|
|
import json
|
|
import subprocess
|
|
import time
|
|
from pathlib import Path
|
|
from urllib.parse import unquote
|
|
|
|
OUT = Path(__file__).resolve().parent
|
|
ROOT = OUT.parents[1]
|
|
QA = ROOT / 'storage/app/private/investmoz-v2/portal-audit/onboarding-qa-internal-20261011_191450'
|
|
PHP = 'C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64/php.exe'
|
|
BASE = 'http://127.0.0.1:18119'
|
|
spec = importlib.util.spec_from_file_location('contact_helpers', OUT / 'test-contact-http-qa.py')
|
|
# Reuse just the standard-library HTTP classes without rerunning the contact test.
|
|
source = (OUT / 'test-contact-http-qa.py').read_text(encoding='utf-8').split("ROOT = Path(__file__)")[0]
|
|
namespace = {}
|
|
exec(source, namespace)
|
|
Session = namespace['Session']
|
|
proof = {'QA_only': True, 'active_writes': 0, 'server': BASE, 'workflow_on': False, 'administration_on': True, 'real_user_sessions_changed': 0, 'browser_demonstration': False, 'criteria': {}}
|
|
step = 'prepare'
|
|
|
|
def send(session, path, payload):
|
|
return session.post(BASE+path, json=payload, headers={'Accept': 'application/json', 'X-XSRF-TOKEN': unquote(session.cookies.get('XSRF-TOKEN',''))}, allow_redirects=False, timeout=20)
|
|
|
|
def fresh_login():
|
|
# Do not reuse a code accepted during enrollment or a previous challenge.
|
|
time.sleep(31 - time.time() % 30)
|
|
session = Session()
|
|
assert session.get(BASE+'/login', timeout=20).status_code == 200
|
|
response = send(session, '/login', {'email': actor['email'], 'password': actor['password']})
|
|
assert response.status_code in (200, 302)
|
|
assert session.get(BASE+'/two-factor-challenge', timeout=20).status_code == 200
|
|
code = subprocess.check_output([PHP, str(OUT/'c130-http-fixture-qa.php'), 'otp'], text=True).strip()
|
|
response = send(session, '/two-factor-challenge', {'code': code})
|
|
del code
|
|
assert response.status_code in (200,302,204)
|
|
return session
|
|
|
|
try:
|
|
actor = json.loads((QA/'storage/app/private/c130-http-fixture-local.json').read_text())
|
|
assert actor['email']=='c130-governance-probe@example.invalid'
|
|
step = 'normal_login_mfa'
|
|
session = fresh_login()
|
|
profile = session.get(BASE+'/settings/profile', timeout=20)
|
|
assert profile.status_code==200 and profile.url.endswith('/settings/profile')
|
|
proof['criteria']['login_mfa_administration_only'] = True
|
|
refreshed = session.get(BASE+'/settings/profile', timeout=20)
|
|
assert refreshed.status_code==200 and refreshed.url.endswith('/settings/profile')
|
|
proof['criteria']['page_refresh_authenticated']=True
|
|
assert session.get(BASE+'/minhas-oportunidades', allow_redirects=False, timeout=20).status_code==404
|
|
proof['criteria']['workflow_remains_disabled']=True
|
|
step = 'revision_invalidation'
|
|
result=json.loads(subprocess.check_output([PHP,str(OUT/'c130-http-fixture-qa.php'),'advance-revision'],text=True))
|
|
assert result['synthetic_revision_advanced']
|
|
rejected=session.get(BASE+'/settings/profile',allow_redirects=False,timeout=20)
|
|
assert rejected.status_code==302
|
|
proof['criteria']['stale_revision_rejected']=True
|
|
session.close()
|
|
step='new_session_new_revision'
|
|
session=fresh_login()
|
|
profile=session.get(BASE+'/settings/profile',timeout=20)
|
|
assert profile.status_code==200 and profile.url.endswith('/settings/profile')
|
|
proof['criteria']['new_login_binds_current_revision']=True
|
|
assert send(session,'/logout',{}).status_code in (200,302,204)
|
|
assert session.get(BASE+'/settings/profile',allow_redirects=False,timeout=20).status_code==302
|
|
proof['criteria']['logout_protects_profile']=True
|
|
proof.update(result='passed',secrets_recorded=False)
|
|
except Exception as error:
|
|
proof.update(result='failed',step=step,exception=type(error).__name__)
|
|
(OUT/'c130-http-governance-only-qa.json').write_text(json.dumps(proof,indent=2),encoding='utf-8')
|
|
print(json.dumps(proof,indent=2))
|
|
raise SystemExit(0 if proof['result']=='passed' else 1)
|