43 lines
2.7 KiB
Python
43 lines
2.7 KiB
Python
"""Inspect native authenticated views without changing business data or permissions."""
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
|
|
spec = importlib.util.spec_from_file_location('native', '/root/check-public-demonstration.py')
|
|
native = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(native)
|
|
identities = json.loads(Path('/root/compras-demo-access.json').read_text())
|
|
checks = []
|
|
for profile, paths in {
|
|
'procurement': ['/dashboard', '/requisicoes', '/cotacoes', '/ordens', '/ordens/1', '/compras/importacoes/12/documentos'],
|
|
'warehouse': ['/recepcoes', '/stock'],
|
|
'finance': ['/facturas', '/orcamentos', '/relatorios'],
|
|
'direction': ['/pessoas', '/pessoas/1'],
|
|
'auditor': ['/auditoria/privada'],
|
|
}.items():
|
|
client = native.Client(identities[profile], 'https://compras.tempo.co.mz')
|
|
entry = client.request('/')
|
|
assert entry['status'] == 302 and entry['location'].endswith('/dashboard')
|
|
for path in paths:
|
|
response = client.request(path)
|
|
page = response['page'] or {}
|
|
props = page.get('props', {})
|
|
collections = {}
|
|
for key, value in props.items():
|
|
if isinstance(value, dict) and isinstance(value.get('data'), list):
|
|
collections[key] = {'rows': len(value['data']), 'total': value.get('total')}
|
|
elif isinstance(value, list) and key in ['items', 'orders', 'invoices', 'documents', 'budgets', 'balances']:
|
|
collections[key] = {'rows': len(value)}
|
|
checks.append({'profile': profile, 'path': path, 'status': response['status'], 'component': page.get('component'),
|
|
'authenticated': bool(props.get('auth', {}).get('user')), 'collections': collections,
|
|
'flags': {k: v for k, v in props.items() if isinstance(v, bool) and (k.startswith('can') or k.endswith('Available') or k == 'ready')},
|
|
'context_enforced': (props.get('workContext') or {}).get('enforced')})
|
|
assert all(c['status'] == 200 and c['authenticated'] and c['component'] not in [None, 'home']
|
|
and (c['component'] != 'work-context' or c['path'] == '/dashboard') for c in checks)
|
|
empty = [c for c in checks if c['collections'] and sum(v['rows'] for v in c['collections'].values()) == 0]
|
|
assert not empty, json.dumps(empty)
|
|
proof = {'state': 'passed', 'release_id': json.loads(Path('/var/www/compras-deploy/current/compras-release.json').read_text())['release_id'],
|
|
'authenticated_root_redirects_to_dashboard': True, 'authenticated_workspace_checks': checks, 'business_data_changed': False, 'permissions_changed': False}
|
|
Path('/var/www/compras-deploy/demonstration-20261129/workspace-visibility.json').write_text(json.dumps(proof, indent=2)+'\n')
|
|
print(json.dumps(proof, indent=2))
|