1. 移除NFC和蓝牙相关依赖、权限及功能代码,精简传输链路 2. 重构设备在线统计逻辑,使用后端7天活跃字段替代本地计算 3. 更新应用名称、权限说明和协议文档 4. 新增消息转发、缓存管理、医疗免责提示功能 5. 优化运势模块和字体管理文案,修复构建日志问题
183 lines
5.1 KiB
Python
183 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
闲言APP OAuth社交登录 API 测试脚本
|
|
|
|
创建时间: 2026-06-05
|
|
更新时间: 2026-06-05
|
|
作用: 测试OAuth社交登录接口的可用性和参数校验
|
|
上次更新: 初始版本
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
|
|
BASE = 'https://tools.wktyl.com'
|
|
TIMEOUT = 15
|
|
|
|
|
|
def test_install():
|
|
"""测试安装数据表"""
|
|
print("1. 安装数据表...")
|
|
r = requests.get(f'{BASE}/api/oauth/install', timeout=TIMEOUT)
|
|
data = r.json()
|
|
print(f" 结果: {json.dumps(data, ensure_ascii=False, indent=2)}")
|
|
assert data['code'] == 1, f"安装失败: {data['msg']}"
|
|
print(" ✅ 安装成功")
|
|
return True
|
|
|
|
|
|
def test_config():
|
|
"""测试获取OAuth配置"""
|
|
print("2. 获取OAuth配置...")
|
|
for platform in ['apple', 'google', 'github']:
|
|
r = requests.get(f'{BASE}/api/oauth/config', params={'platform': platform}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
configured = data.get('data', {}).get('configured', False) if data.get('code') == 1 else False
|
|
print(f" {platform}: code={data['code']}, configured={configured}")
|
|
print(" ✅ 配置接口正常")
|
|
return True
|
|
|
|
|
|
def test_config_invalid_platform():
|
|
"""测试不支持的平台"""
|
|
print("3. 测试不支持的平台...")
|
|
r = requests.get(f'{BASE}/api/oauth/config', params={'platform': 'facebook'}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
assert data['code'] == 0, "应该返回错误"
|
|
print(f" 结果: {data['msg']}")
|
|
print(" ✅ 不支持的平台正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_login_invalid_platform():
|
|
"""测试无效平台登录"""
|
|
print("4. 测试无效平台登录...")
|
|
r = requests.post(f'{BASE}/api/oauth/login', data={
|
|
'platform': 'invalid_platform',
|
|
'code': 'test',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
assert data['code'] == 0, "应该返回错误"
|
|
print(f" 结果: {data['msg']}")
|
|
print(" ✅ 无效平台正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_login_github_empty_code():
|
|
"""测试GitHub空授权码"""
|
|
print("5. 测试GitHub空授权码...")
|
|
r = requests.post(f'{BASE}/api/oauth/login', data={
|
|
'platform': 'github',
|
|
'code': '',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
assert data['code'] == 0, "应该返回错误"
|
|
print(f" 结果: {data['msg']}")
|
|
print(" ✅ 空授权码正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_login_apple_empty_token():
|
|
"""测试Apple空id_token"""
|
|
print("6. 测试Apple空id_token...")
|
|
r = requests.post(f'{BASE}/api/oauth/login', data={
|
|
'platform': 'apple',
|
|
'id_token': '',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
assert data['code'] == 0, "应该返回错误"
|
|
print(f" 结果: {data['msg']}")
|
|
print(" ✅ 空id_token正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_login_google_empty_code():
|
|
"""测试Google空授权码"""
|
|
print("7. 测试Google空授权码...")
|
|
r = requests.post(f'{BASE}/api/oauth/login', data={
|
|
'platform': 'google',
|
|
'code': '',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
assert data['code'] == 0, "应该返回错误"
|
|
print(f" 结果: {data['msg']}")
|
|
print(" ✅ 空授权码正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_bound_without_login():
|
|
"""测试未登录查询绑定列表"""
|
|
print("8. 测试未登录查询绑定...")
|
|
r = requests.get(f'{BASE}/api/oauth/bound', timeout=TIMEOUT)
|
|
data = r.json()
|
|
print(f" 结果: code={data['code']}, msg={data['msg']}")
|
|
print(" ✅ 未登录正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_bind_without_login():
|
|
"""测试未登录绑定"""
|
|
print("9. 测试未登录绑定...")
|
|
r = requests.post(f'{BASE}/api/oauth/bind', data={
|
|
'platform': 'github',
|
|
'code': 'test',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
print(f" 结果: code={data['code']}, msg={data['msg']}")
|
|
print(" ✅ 未登录绑定正确拒绝")
|
|
return True
|
|
|
|
|
|
def test_unbind_without_login():
|
|
"""测试未登录解绑"""
|
|
print("10. 测试未登录解绑...")
|
|
r = requests.post(f'{BASE}/api/oauth/unbind', data={
|
|
'platform': 'github',
|
|
}, timeout=TIMEOUT)
|
|
data = r.json()
|
|
print(f" 结果: code={data['code']}, msg={data['msg']}")
|
|
print(" ✅ 未登录解绑正确拒绝")
|
|
return True
|
|
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("闲言APP OAuth社交登录 API 测试")
|
|
print("=" * 60)
|
|
|
|
tests = [
|
|
test_install,
|
|
test_config,
|
|
test_config_invalid_platform,
|
|
test_login_invalid_platform,
|
|
test_login_github_empty_code,
|
|
test_login_apple_empty_token,
|
|
test_login_google_empty_code,
|
|
test_bound_without_login,
|
|
test_bind_without_login,
|
|
test_unbind_without_login,
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for test in tests:
|
|
try:
|
|
if test():
|
|
passed += 1
|
|
except Exception as e:
|
|
print(f" ❌ 失败: {e}")
|
|
failed += 1
|
|
print()
|
|
|
|
print("=" * 60)
|
|
print(f"测试完成: ✅ {passed} 通过, ❌ {failed} 失败")
|
|
print("=" * 60)
|
|
|
|
return 0 if failed == 0 else 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|