Files
huncode 9b5b080e60
Production container deploy / production (push) Successful in 34s
Stamp release health and align preview security smoke checks
2026-10-26 14:34:32 +03:00

42 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Check rendered pages and every internal link/asset, without running a browser."""
import argparse,json,subprocess
from html.parser import HTMLParser
from urllib.parse import urlsplit,urldefrag
parser=argparse.ArgumentParser();parser.add_argument('--base',required=True);parser.add_argument('--origin');parser.add_argument('--output');args=parser.parse_args()
class Links(HTMLParser):
def __init__(self):super().__init__();self.urls=set();self.ids=set()
def handle_starttag(self,tag,attrs):
a=dict(attrs)
if 'id' in a:self.ids.add(a['id'])
for key in ('href','src'):
u=a.get(key,'')
if u.startswith('/') and not u.startswith('//'):self.urls.add(u)
paths=['/','/about','/catalog','/guides/choose','/guides/memory-card','/guides/installation','/guides/save-video','/tools/recording-time','/health/ready','/health/live']
results=[];discovered=set();fragments=[];documents={}
def request(path,method="GET"):
cmd=['curl','-sS','--max-time','20','-w','\n%{http_code}']
if args.origin:cmd+=['-k','--resolve',urlsplit(args.base).hostname+':443:'+args.origin]
cmd+=['-X',method,args.base+path]
r=subprocess.run(cmd,capture_output=True);body,code=r.stdout.rsplit(b'\n',1);return int(code),body
for path in paths:
code,body=request(path);assert code==200,(path,code)
results.append(dict(path=path,status=code,bytes=len(body)))
if path.startswith('/health/'):
assert json.loads(body)['status']=='ok';continue
parsed=Links();parsed.feed(body.decode());documents[path]=parsed.ids;discovered.update(parsed.urls)
assert b'mc.yandex.ru' not in body and b'web.archive.org/web/' not in body,path
for url in sorted(discovered):
path,frag=urldefrag(url)
if path not in paths and path != '/auto.shtml':
code,body=request(path);assert code==200,(path,code);results.append(dict(path=path,status=code,bytes=len(body)))
if frag:
assert frag in documents[path],(url,'missing fragment')
for path in ['/api/videos','/_dev/showcase','/does-not-exist']:
code,_=request(path);assert code==404,(path,code);results.append(dict(path=path,status=code))
code,_=request('/api/videos','POST');assert code==404,code;results.append(dict(path='/api/videos',method='POST',status=code))
code,_=request('/auto.shtml');assert code==308,code;results.append(dict(path='/auto.shtml',status=code))
report=dict(base=args.base,origin=args.origin,tlsVerified=(not bool(args.origin)) if args.base.startswith('https://') else None,checks=results,internalLinksAndAssets='passed',date='2026-10-26')
if args.output:open(args.output,'w').write(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
print(json.dumps(dict(requests=len(results),status='passed',origin=args.origin)))