Files
user-system/scripts/test/test_api.sh
long-agent 5b6bd93179 refactor: 整理项目根目录结构
整理内容:
- 删除 60+ 临时测试输出文件 (*.txt)
- 移动二进制文件到 bin/ 目录
- 移动 Shell 脚本到 scripts/ 目录
  - scripts/dev/: check_gitea.sh, check_sub2api.sh, run_tests.sh
  - scripts/deploy/: deploy_*.sh, simple_deploy.sh
  - scripts/ops/: fix_nginx.sh, fix_ssl.sh, install_docker.sh
  - scripts/test/: test_*.sh, test_*.bat
- 移动批处理文件到 scripts/
- 移动 Python 脚本到 tools/
- 清理临时日志文件

保留根目录必要文件:
- go.mod, go.sum, go.work
- Makefile, docker-compose.yml
- .env.example, .gitignore
- README.md, AGENTS.md, DEPLOY_GUIDE.md

验证: go build ./... && go test ./... 通过
2026-04-07 18:10:36 +08:00

50 lines
1.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 用户管理系统 API 测试脚本
TEST_ADMIN_ACCOUNT="${TEST_ADMIN_ACCOUNT:-admin}"
if [ -z "${TEST_ADMIN_PASSWORD:-}" ]; then
echo "请先设置 TEST_ADMIN_PASSWORD"
exit 1
fi
echo "=== 1. 健康检查 ==="
curl http://localhost:8080/health
echo -e "\n"
echo "=== 2. 用户注册 ==="
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"testuser","password":"Test123456","email":"test@example.com"}'
echo -e "\n"
echo "=== 3. 用户登录admin ==="
LOGIN_RESPONSE=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d "{\"account\":\"${TEST_ADMIN_ACCOUNT}\",\"password\":\"${TEST_ADMIN_PASSWORD}\"}")
echo "$LOGIN_RESPONSE"
# 提取token
TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
echo -e "\n=== 4. 获取用户信息 ==="
if [ -n "$TOKEN" ]; then
curl -X GET http://localhost:8080/api/v1/auth/userinfo \
-H "Authorization: Bearer $TOKEN"
echo -e "\n"
else
echo "无法获取token跳过此测试"
fi
echo -e "\n=== 5. 测试限流(连续快速请求) ==="
for i in {1..6}; do
echo "$i 次登录请求:"
curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"account":"wrong","password":"wrong"}'
echo ""
done
echo -e "\n测试完成"