#!/usr/bin/env python3 """Check Socket.IO transport on HedgeDoc.""" import argparse import os import sys import urllib.request sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..')) from utils.tests.helpers import resolve_domain def main(): parser = argparse.ArgumentParser() parser.add_argument('--domain', default=os.environ.get('TEST_DOMAIN')) args = parser.parse_args() domain = args.domain or resolve_domain('hedgedoc') url = f"https://{domain}" print(f"Checking Socket.IO transport on {url} ...") req = urllib.request.Request(f"{url}/socket.io/?EIO=4&transport=polling") try: with urllib.request.urlopen(req, timeout=15) as resp: response = resp.read().decode('utf-8') except Exception as e: print(f"FAIL: Could not connect to Socket.IO endpoint: {e}") sys.exit(1) if response.startswith('0{'): print("PASS: Socket.IO handshake successful") else: print("FAIL: Unexpected Socket.IO response") print(f"Got: {response}") sys.exit(1) if __name__ == '__main__': main()