diff --git a/Test-Verification-Debug.ps1 b/Test-Verification-Debug.ps1 new file mode 100644 index 0000000..00c43e4 --- /dev/null +++ b/Test-Verification-Debug.ps1 @@ -0,0 +1,112 @@ +# 验证码问题调试脚本 +# 作者: moyin +# 日期: 2025-12-17 + +$baseUrl = "http://localhost:3000" +$testEmail = "debug@example.com" + +Write-Host "=== 验证码问题调试脚本 ===" -ForegroundColor Green + +# 步骤1: 发送验证码 +Write-Host "`n1. 发送验证码..." -ForegroundColor Yellow +$sendBody = @{ + email = $testEmail +} | ConvertTo-Json + +try { + $sendResponse = Invoke-RestMethod -Uri "$baseUrl/auth/send-email-verification" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "发送响应: $($sendResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Cyan + + if ($sendResponse.success) { + Write-Host "✅ 验证码发送成功" -ForegroundColor Green + + # 步骤2: 立即查看验证码调试信息 + Write-Host "`n2. 查看验证码调试信息..." -ForegroundColor Yellow + $debugResponse = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "调试信息: $($debugResponse | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤3: 故意输入错误验证码 + Write-Host "`n3. 测试错误验证码..." -ForegroundColor Yellow + $wrongVerifyBody = @{ + email = $testEmail + verification_code = "000000" + } | ConvertTo-Json + + try { + $wrongResponse = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $wrongVerifyBody -ContentType "application/json" + Write-Host "错误验证响应: $($wrongResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Red + } catch { + Write-Host "错误验证失败(预期): $($_.Exception.Message)" -ForegroundColor Yellow + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + + # 步骤4: 再次查看调试信息 + Write-Host "`n4. 错误验证后的调试信息..." -ForegroundColor Yellow + $debugResponse2 = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "调试信息: $($debugResponse2 | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤5: 再次尝试错误验证码 + Write-Host "`n5. 再次测试错误验证码..." -ForegroundColor Yellow + try { + $wrongResponse2 = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $wrongVerifyBody -ContentType "application/json" + Write-Host "第二次错误验证响应: $($wrongResponse2 | ConvertTo-Json -Depth 3)" -ForegroundColor Red + } catch { + Write-Host "第二次错误验证失败: $($_.Exception.Message)" -ForegroundColor Yellow + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + + # 步骤6: 最终调试信息 + Write-Host "`n6. 最终调试信息..." -ForegroundColor Yellow + $debugResponse3 = Invoke-RestMethod -Uri "$baseUrl/auth/debug-verification-code" -Method POST -Body $sendBody -ContentType "application/json" + Write-Host "最终调试信息: $($debugResponse3 | ConvertTo-Json -Depth 5)" -ForegroundColor Cyan + + # 步骤7: 使用正确验证码(如果有的话) + if ($sendResponse.data.verification_code) { + Write-Host "`n7. 使用正确验证码..." -ForegroundColor Yellow + $correctVerifyBody = @{ + email = $testEmail + verification_code = $sendResponse.data.verification_code + } | ConvertTo-Json + + try { + $correctResponse = Invoke-RestMethod -Uri "$baseUrl/auth/verify-email" -Method POST -Body $correctVerifyBody -ContentType "application/json" + Write-Host "正确验证响应: $($correctResponse | ConvertTo-Json -Depth 3)" -ForegroundColor Green + } catch { + Write-Host "正确验证也失败了: $($_.Exception.Message)" -ForegroundColor Red + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } + } + } + + } else { + Write-Host "❌ 验证码发送失败: $($sendResponse.message)" -ForegroundColor Red + } +} catch { + Write-Host "❌ 请求失败: $($_.Exception.Message)" -ForegroundColor Red + if ($_.Exception.Response) { + $errorResponse = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($errorResponse) + $errorBody = $reader.ReadToEnd() + Write-Host "错误详情: $errorBody" -ForegroundColor Red + } +} + +Write-Host "`n=== 调试完成 ===" -ForegroundColor Green +Write-Host "请查看上述输出,重点关注:" -ForegroundColor Yellow +Write-Host "1. TTL值的变化" -ForegroundColor White +Write-Host "2. attempts字段的变化" -ForegroundColor White +Write-Host "3. 验证码是否被意外删除" -ForegroundColor White \ No newline at end of file