#!/usr/bin/env python3
"""
Debug script to test the registration endpoint
"""

import requests
import time

BASE_URL = "https://unrealistic-1-7e47fbb90382563c.chals.uoftctf.org"

print("[*] Testing server endpoints...")

# Test GET /register
print("\n[1] Testing GET /register...")
try:
    resp = requests.get(f"{BASE_URL}/register", timeout=10)
    print(f"    Status: {resp.status_code}")
    print(f"    Length: {len(resp.text)} bytes")
except Exception as e:
    print(f"    Error: {e}")

# Test POST /register with valid data
print("\n[2] Testing POST /register...")
try:
    username = f"test_{int(time.time())}"
    resp = requests.post(
        f"{BASE_URL}/register",
        data={"username": username, "password": "test123"},
        allow_redirects=False,
        timeout=10
    )
    print(f"    Status: {resp.status_code}")
    print(f"    Headers: {dict(resp.headers)}")
    print(f"    Cookies: {resp.cookies}")
    if resp.status_code != 200:
        print(f"    Response: {resp.text[:500]}")
except Exception as e:
    print(f"    Error: {e}")

# Test if it's a CORS issue
print("\n[3] Testing with different headers...")
try:
    username = f"test2_{int(time.time())}"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Origin': BASE_URL,
        'Referer': f'{BASE_URL}/register'
    }
    resp = requests.post(
        f"{BASE_URL}/register",
        data={"username": username, "password": "test123"},
        headers=headers,
        allow_redirects=False,
        timeout=10
    )
    print(f"    Status: {resp.status_code}")
    print(f"    Cookies: {resp.cookies}")
except Exception as e:
    print(f"    Error: {e}")

# Test /bot endpoint
print("\n[4] Testing GET /bot...")
try:
    resp = requests.get(f"{BASE_URL}/bot", timeout=10)
    print(f"    Status: {resp.status_code}")
except Exception as e:
    print(f"    Error: {e}")
