fix:修复API状态码和限流配置问题
- 修复登录控制器HTTP状态码问题,现在根据业务结果返回正确状态码 - 调整注册接口限流配置,从3次/5分钟放宽至10次/5分钟(开发环境) - 新增清除限流记录的调试接口,便于开发测试 - 更新API文档,反映状态码修复和限流调整 - 添加测试脚本验证修复效果 主要修复: - 业务失败时返回400/401而非200/201状态码 - 注册、登录、GitHub OAuth等接口现在正确处理错误状态码 - 限流配置更适合开发环境测试需求
This commit is contained in:
53
test-register-fix.ps1
Normal file
53
test-register-fix.ps1
Normal file
@@ -0,0 +1,53 @@
|
||||
# Test register API fix
|
||||
$baseUrl = "http://localhost:3000"
|
||||
|
||||
Write-Host "Testing register API fix..." -ForegroundColor Green
|
||||
|
||||
# Test 1: Register with email but no verification code (should return 400)
|
||||
Write-Host "`nTest 1: Register with email but no verification code" -ForegroundColor Yellow
|
||||
$registerData1 = @{
|
||||
username = "testuser1"
|
||||
password = "password123"
|
||||
nickname = "Test User 1"
|
||||
email = "test1@example.com"
|
||||
} | ConvertTo-Json
|
||||
|
||||
try {
|
||||
$response1 = Invoke-RestMethod -Uri "$baseUrl/auth/register" -Method POST -Body $registerData1 -ContentType "application/json" -ErrorAction Stop
|
||||
Write-Host "Status: 200/201 (Unexpected success)" -ForegroundColor Red
|
||||
Write-Host "Response: $($response1 | ConvertTo-Json -Depth 3)" -ForegroundColor Red
|
||||
} catch {
|
||||
$statusCode = $_.Exception.Response.StatusCode.value__
|
||||
Write-Host "Status Code: $statusCode" -ForegroundColor $(if ($statusCode -eq 400) { "Green" } else { "Red" })
|
||||
|
||||
if ($_.Exception.Response) {
|
||||
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
|
||||
$responseBody = $reader.ReadToEnd()
|
||||
Write-Host "Response: $responseBody" -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
|
||||
# Test 2: Register without email (should return 201)
|
||||
Write-Host "`nTest 2: Register without email" -ForegroundColor Yellow
|
||||
$registerData2 = @{
|
||||
username = "testuser2"
|
||||
password = "password123"
|
||||
nickname = "Test User 2"
|
||||
} | ConvertTo-Json
|
||||
|
||||
try {
|
||||
$response2 = Invoke-RestMethod -Uri "$baseUrl/auth/register" -Method POST -Body $registerData2 -ContentType "application/json" -ErrorAction Stop
|
||||
Write-Host "Status: 200/201 (Success)" -ForegroundColor Green
|
||||
Write-Host "Response: $($response2 | ConvertTo-Json -Depth 3)" -ForegroundColor Green
|
||||
} catch {
|
||||
$statusCode = $_.Exception.Response.StatusCode.value__
|
||||
Write-Host "Status Code: $statusCode (Unexpected failure)" -ForegroundColor Red
|
||||
|
||||
if ($_.Exception.Response) {
|
||||
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
|
||||
$responseBody = $reader.ReadToEnd()
|
||||
Write-Host "Response: $responseBody" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`nTest completed!" -ForegroundColor Green
|
||||
Reference in New Issue
Block a user