feat(auth): 防账号枚举 — 已注册邮箱发"已注册"提醒,不内联暴露
发码/注册都不再泄露"邮箱是否已注册"(对翻墙工具尤其敏感:已注册=该人是用户)。 - SendCode:邮箱已注册时不发验证码、改发"您已注册请直接登录"邮件,接口统一 返回 204(注册/未注册无差别)→ 关掉发码侧枚举 - Register:命中已注册(ErrEmailTaken)改回通用 ErrCodeInvalid(与错码一致), 不再返回"该邮箱已注册"→ 关掉注册侧枚举 - Mailer 接口加 SendAlreadyRegistered(SMTP + Log 两实现) - 测试:DuplicateEmailConflict 改为断言"已注册不发码 + 强制码也只回通用错误"; integration 同步 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -162,14 +162,15 @@ func TestIntegration_FullChain(t *testing.T) {
|
||||
t.Fatalf("trial length = %.2f days, want ~7", days)
|
||||
}
|
||||
|
||||
// 3. Duplicate email → 409.
|
||||
// 3. Duplicate email — anti-enumeration: registered email gets no code, and
|
||||
// even a forced code yields the generic code error (not "email exists").
|
||||
if _, e := svc.SendCode(ctx, email, ""); e != nil && e.Code != ErrRateLimited.Code {
|
||||
t.Fatalf("second SendCode: %v", e)
|
||||
}
|
||||
// Force a fresh code regardless of rate limit.
|
||||
_ = rdb.Set(ctx, codeKey(email), code, 10*time.Minute).Err()
|
||||
if _, e := svc.Register(ctx, email, code, pw); e == nil || e.Code != ErrEmailExists.Code {
|
||||
t.Fatalf("want email_exists, got %v", e)
|
||||
if _, e := svc.Register(ctx, email, code, pw); e == nil || e.Code != ErrCodeInvalid.Code {
|
||||
t.Fatalf("want code_invalid (anti-enumeration), got %v", e)
|
||||
}
|
||||
|
||||
// 4. Login.
|
||||
|
||||
Reference in New Issue
Block a user