多平台账号批量注册系统,支持 OpenAI / Grok / Kiro / Gemini 平台的全自动注册。 Features: - 用户名/密码注册登录(首个用户自动管理员) - JWT 认证 + bcrypt 密码加密 - 积分系统与多用户管理 - HuggingFace Space 弹性 Worker 节点管理 - Cloudflare Worker 负载均衡 - 实时日志推送(SSE/WebSocket) - 管理后台(用户管理、系统设置、代理池、卡池) Tech Stack: Go 1.25 / Gin / GORM / PostgreSQL / Vue 3 / Vite / TailwindCSS
128 lines
3.4 KiB
Go
128 lines
3.4 KiB
Go
package tempmail
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestYYDSMailFetchVerificationCodeUsesLatestMessage(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/v1/messages", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"messages": []map[string]interface{}{
|
|
{
|
|
"id": "old-msg",
|
|
"subject": "Gemini Enterprise verification code",
|
|
"created_at": "2026-03-18T14:00:00Z",
|
|
},
|
|
{
|
|
"id": "new-msg",
|
|
"subject": "Gemini Enterprise verification code",
|
|
"created_at": "2026-03-18T14:05:00Z",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
})
|
|
mux.HandleFunc("/v1/messages/old-msg", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"text": "Your Google verification code is OLD111",
|
|
"html": []string{},
|
|
},
|
|
})
|
|
})
|
|
mux.HandleFunc("/v1/messages/new-msg", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"text": "",
|
|
"html": []string{
|
|
`<div>Your one-time verification code is:</div>`,
|
|
`<div>DZJW4P</div>`,
|
|
},
|
|
},
|
|
})
|
|
})
|
|
|
|
server := httptest.NewServer(mux)
|
|
t.Cleanup(server.Close)
|
|
|
|
provider := NewYYDSMailProvider(server.URL, "test-api-key")
|
|
code, err := provider.FetchVerificationCode(context.Background(), "gemini@example.com", map[string]string{
|
|
"provider": "yydsmail",
|
|
"token": "temp-token",
|
|
}, 1, 0)
|
|
if err != nil {
|
|
t.Fatalf("FetchVerificationCode() error = %v", err)
|
|
}
|
|
if code != "DZJW4P" {
|
|
t.Fatalf("FetchVerificationCode() = %q, want %q", code, "DZJW4P")
|
|
}
|
|
}
|
|
|
|
func TestYYDSMailFetchVerificationCodePreservesOriginalOrderWhenTimestampMissing(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/v1/messages", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"messages": []map[string]interface{}{
|
|
{
|
|
"id": "latest-without-time",
|
|
"subject": "Verification code",
|
|
},
|
|
{
|
|
"id": "older-with-time",
|
|
"subject": "Verification code",
|
|
"created_at": "2026-03-18T14:00:00Z",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
})
|
|
mux.HandleFunc("/v1/messages/latest-without-time", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"text": "Use this passcode: 456789",
|
|
"html": []string{},
|
|
},
|
|
})
|
|
})
|
|
mux.HandleFunc("/v1/messages/older-with-time", func(w http.ResponseWriter, r *http.Request) {
|
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"success": true,
|
|
"data": map[string]interface{}{
|
|
"text": "Use this passcode: 123456",
|
|
"html": []string{},
|
|
},
|
|
})
|
|
})
|
|
|
|
server := httptest.NewServer(mux)
|
|
t.Cleanup(server.Close)
|
|
|
|
provider := NewYYDSMailProvider(server.URL, "test-api-key")
|
|
code, err := provider.FetchVerificationCode(context.Background(), "latest@example.com", map[string]string{
|
|
"provider": "yydsmail",
|
|
"token": "temp-token",
|
|
}, 1, 0)
|
|
if err != nil {
|
|
t.Fatalf("FetchVerificationCode() error = %v", err)
|
|
}
|
|
if code != "456789" {
|
|
t.Fatalf("FetchVerificationCode() = %q, want %q", code, "456789")
|
|
}
|
|
}
|