-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_permission_cookie.py
More file actions
63 lines (53 loc) · 2 KB
/
test_permission_cookie.py
File metadata and controls
63 lines (53 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Quick test to check if permissions cookie is being set correctly
"""
import requests
import json
import base64
from urllib.parse import quote
# 测试步骤:
# 1. 检查权限 cookie 是否存在
# 2. 解码权限 cookie
# 3. 尝试调用受保护的接口
BASE_URL = "http://localhost:8001"
print("=" * 60)
print("🔍 Testing Permission Cookie Setup")
print("=" * 60)
# 创建会话来保持 cookies
session = requests.Session()
# 第一步:检查权限 debug 端点
print("\n1️⃣ Checking /auth/debug/permissions endpoint...")
resp = session.get(f"{BASE_URL}/auth/debug/permissions")
print(f"Status: {resp.status_code}")
print(f"Response: {json.dumps(resp.json(), indent=2, ensure_ascii=False)}")
# 检查原始 cookies
print("\n2️⃣ Checking cookies in session...")
print(f"Cookies: {session.cookies}")
for cookie in session.cookies:
print(f" - {cookie.name}: {cookie.value[:50]}..." if len(cookie.value) > 50 else f" - {cookie.name}: {cookie.value}")
# 如果有权限 cookie,尝试解码
perm_cookie = session.cookies.get('deepwiki_repo_permissions')
if perm_cookie:
print(f"\n3️⃣ Found permission cookie, trying to decode...")
try:
decoded = base64.b64decode(perm_cookie).decode('utf-8')
data = json.loads(decoded)
print(f"✅ Decoded successfully!")
print(f"User: {data.get('user_id')}")
print(f"Repos: {len(data.get('repos', []))} repositories")
for repo in data.get('repos', [])[:3]:
print(f" - {repo['owner']}/{repo['repo']}")
except Exception as e:
print(f"❌ Failed to decode: {e}")
else:
print(f"\n3️⃣ ❌ No permission cookie found!")
# 第三步:尝试调用受保护的接口
print(f"\n4️⃣ Testing protected endpoint...")
print(f"Calling: POST /api/wiki/projects/status/batch")
resp = session.post(
f"{BASE_URL}/api/wiki/projects/status/batch",
json={"project_keys": ["gitlab:test/test"]}
)
print(f"Status: {resp.status_code}")
print(f"Response: {resp.json()}")
print("\n" + "=" * 60)