test(auth): smoke test for /api/auth/users + reset-password
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Smoke test: /api/auth/users + /api/auth/reset-password."""
|
||||
import json
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
BASE = "http://localhost:8000"
|
||||
|
||||
def req(method, path, body=None, token=None):
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
data = json.dumps(body).encode() if body else None
|
||||
r = urllib.request.Request(f"{BASE}{path}", data=data, headers=headers, method=method)
|
||||
try:
|
||||
with urllib.request.urlopen(r, timeout=10) as resp:
|
||||
return resp.status, json.loads(resp.read().decode() or "{}")
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, json.loads(e.read().decode() or "{}")
|
||||
|
||||
# 1. Login
|
||||
code, body = req("POST", "/api/auth/login", {"email": "admin@aars.hk", "password": "admin123"})
|
||||
if code != 200:
|
||||
print(f"LOGIN FAILED: {code} {body}")
|
||||
sys.exit(1)
|
||||
token = body["access_token"]
|
||||
print(f"✅ login ok, token={token[:30]}...")
|
||||
|
||||
# 2. List users
|
||||
code, body = req("GET", "/api/auth/users", token=token)
|
||||
print(f"\n--- GET /api/auth/users (code={code}) ---")
|
||||
print(json.dumps(body, indent=2, ensure_ascii=False))
|
||||
|
||||
# 3. Reset password (no actual change, just smoke test)
|
||||
code, body = req("POST", "/api/auth/reset-password",
|
||||
{"email": "admin@aars.hk", "new_password": "admin123"},
|
||||
token=token)
|
||||
print(f"\n--- POST /api/auth/reset-password (code={code}) ---")
|
||||
print(json.dumps(body, indent=2, ensure_ascii=False))
|
||||
|
||||
# 4. Verify login still works
|
||||
code, body = req("POST", "/api/auth/login", {"email": "admin@aars.hk", "password": "admin123"})
|
||||
print(f"\n--- verify login (code={code}) ---")
|
||||
if code == 200:
|
||||
print("✅ login still works after reset")
|
||||
else:
|
||||
print(f"❌ login broken: {body}")
|
||||
Reference in New Issue
Block a user