37 lines
1.7 KiB
Python
37 lines
1.7 KiB
Python
"""Read-only acceptance checks through the user's actual LAN entry point."""
|
|
import hashlib
|
|
import http.client
|
|
import json
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parent
|
|
dist = root / 'payload/admin-web/apps/web-antd/dist'
|
|
assets = list((dist / 'js').glob('ModelUsageStats-*.js'))
|
|
assert len(assets) == 1
|
|
asset = '/' + assets[0].relative_to(dist).as_posix()
|
|
checks = [('/', 200), ('/api/v2/health', 200), ('/gateway/health', 200),
|
|
('/api/v2/stats/model-usage', 401), ('/api/v2/stats/model-usage/log', 401),
|
|
('/api/stats/model-usage', 401), (asset, 200)]
|
|
results = {}
|
|
for path, wanted in checks:
|
|
connection = http.client.HTTPConnection('192.168.110.111', 8369, timeout=20,
|
|
source_address=('192.168.123.43', 0))
|
|
try:
|
|
connection.request('GET', path, headers={'Accept-Encoding': 'identity'})
|
|
response = connection.getresponse()
|
|
body = response.read()
|
|
assert response.status == wanted, (path, response.status, wanted)
|
|
if path in ('/', asset):
|
|
expected = (dist / 'index.html').read_bytes() if path == '/' else assets[0].read_bytes()
|
|
assert hashlib.sha256(body).digest() == hashlib.sha256(expected).digest(), path
|
|
elif wanted == 200:
|
|
assert isinstance(json.loads(body), dict), path
|
|
results[path] = response.status
|
|
finally:
|
|
connection.close()
|
|
report = {'entry': 'http://192.168.110.111:8369', 'http': results,
|
|
'frontend_matches_release': True, 'unauthenticated_usage_rejected': True,
|
|
'real_model_calls': 0}
|
|
(root / 'lan-verification.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
|
print(json.dumps(report, ensure_ascii=False))
|