fix(批次D): 口令哈希升级 + 假签名放行 + 找回密码防枚举 + 告警按收件人
- 用户口令:hash_password 改 pbkdf2(加盐、260k 迭代);新增 verify_password 兼容旧的无盐 sha256 且恒定时间比较;登录成功后自动升级旧哈希(用户无感) - _verify_upstream_token:没有 access_token 时直接放行(假签名必被上游 102001 拒绝,原先把 102001 当「凭据失效」,导致只填 token_id 的合法用户注册被 400 拦、 /verify_token 永远 invalid) - 找回密码防枚举:未注册邮箱也占 60 秒冷却(email_verify.record_cooldown, 不发信),否则「第二次请求是否 429」就成了判断邮箱是否注册的预言机 - 凭据告警:_send_alert 改为按收件人统计,返回成功数;只要有一人收到就落库, 不再因为某个收件人失败导致「每 15 分钟给全员重发一遍」 测试:167 pytest(新增口令哈希 3 条)+ 32 node 全绿
This commit is contained in:
@@ -147,12 +147,22 @@ def _send_alert(recipients, level, owner_desc, expiry):
|
||||
("有效期至", expire_time), ("提醒时间", _now_bj_str())]
|
||||
plain = f"{title}\n\n{lead}\n\n" + "\n".join(f"{k}:{v}" for k, v in details)
|
||||
html_body = _render_alert_html(title, lead, details)
|
||||
ok_all = True
|
||||
sent_ok, failed = [], []
|
||||
for to in sorted(recipients):
|
||||
subject = f"【小白超人·告警】{title}"
|
||||
if not send_email(to, subject, plain, html_body):
|
||||
ok_all = False
|
||||
return ok_all
|
||||
try:
|
||||
if send_email(to, subject, plain, html_body):
|
||||
sent_ok.append(to)
|
||||
else:
|
||||
failed.append(to)
|
||||
except Exception as exc:
|
||||
print(f"[凭据告警] 发送给 {to} 异常: {exc}")
|
||||
failed.append(to)
|
||||
if failed:
|
||||
print(f"[凭据告警] {len(failed)} 个收件人发送失败: {failed[:3]}")
|
||||
# 返回成功数:只要有一个人收到就算「已通知」,否则每 15 分钟
|
||||
# 会把所有人重发一遍(原来的 ok_all 聚合就是这个问题)
|
||||
return len(sent_ok)
|
||||
|
||||
|
||||
# ========== 检查逻辑 ==========
|
||||
@@ -194,7 +204,7 @@ def check_user_credentials():
|
||||
recv = (u["alert_email"] or "").strip() or (u["email"] or "").strip()
|
||||
if recv:
|
||||
recipients.add(recv)
|
||||
if _send_alert(recipients, level, f"用户 {u['email']}", expiry):
|
||||
if _send_alert(recipients, level, f"用户 {u['email']}", expiry) > 0:
|
||||
_mark_sent(conn, target, level)
|
||||
sent += 1
|
||||
finally:
|
||||
@@ -258,7 +268,7 @@ def check_global_credential():
|
||||
recipients = set(get_alert_emails())
|
||||
if not recipients:
|
||||
return 0
|
||||
if _send_alert(recipients, level, "全局默认凭据", expiry):
|
||||
if _send_alert(recipients, level, "全局默认凭据", expiry) > 0:
|
||||
_mark_sent(conn, target, level)
|
||||
conn.commit()
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user