docs(comments): 注释中文化 · plugins/channels/weixin_ilink(20 文件,纯替换)
- 只翻注释/文档字符串:剥掉行尾注释后,每条「-」都有逐字节相同的「+」对应行(8 组,代码零改动) - 保留协议/线上标识符原文:errcode、bot_token、context_token、getupdates、binded_redirect、PKCS#7、ECB 等 - 术语对齐既有译法:owner→主人、peer→对端、long poll→长轮询、backoff→退避、sentinel error→哨兵错误 - 已知既有欠债(未顺手修):login_reuse_test.go 在 HEAD 上就未 gofmt 干净;login_test.go 的 TestStartLogin_ScanStatusTransition 91 行 >80(HEAD 同为 91 行)
This commit is contained in:
1 parent
09fba77f87
commit
95f97f5df3
20 files changed
+488
-590
No files matched your search
@@ -10,9 +10,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestStartLogin_ScanedExposesWaitingDetail verifies that an observed "scaned" wire
|
||||
// status is surfaced to the panel as the backward-compatible waiting status with the
|
||||
// "please confirm" detail, so the frontend keeps its waiting UI without a new status.
|
||||
// TestStartLogin_ScanedExposesWaitingDetail 验证观测到的线上状态 "scaned" 会以
|
||||
// 向后兼容的 waiting 状态加「请确认」详情呈现给面板,使前端不新增状态就能保留其
|
||||
// 等待界面。
|
||||
func TestStartLogin_ScanedExposesWaitingDetail(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newJSONServer(t, nil, func(req recordedReq) handlerResult {
|
||||
@@ -38,10 +38,9 @@ func TestStartLogin_ScanedExposesWaitingDetail(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// TestStartLogin_ScanedPastWindowReusesQR verifies the re-mint protection: once the
|
||||
// poll has observed "scaned" (awaiting confirmation), StartLogin reuses the current QR
|
||||
// even past the qrReuseWindow and never issues a second get_bot_qrcode — the pending
|
||||
// confirm is not dropped.
|
||||
// TestStartLogin_ScanedPastWindowReusesQR 验证重新取码保护:一旦轮询观测到 "scaned"
|
||||
// (等待确认),StartLogin 即使在超过 qrReuseWindow 后也复用当前二维码,绝不发出第二次
|
||||
// get_bot_qrcode——待处理的确认不会被丢弃。
|
||||
func TestStartLogin_ScanedPastWindowReusesQR(t *testing.T) {
|
||||
t.Parallel()
|
||||
rec := &reqRecorder{}
|
||||
@@ -64,15 +63,15 @@ func TestStartLogin_ScanedPastWindowReusesQR(t *testing.T) {
|
||||
t.Fatalf("first StartLogin: %v", err)
|
||||
}
|
||||
|
||||
// Wait until the poll goroutine has observed "scaned" (the session is confirming).
|
||||
// 等到轮询 goroutine 观测到 "scaned"(该会话处于确认中)。
|
||||
waitFor(t, func() bool {
|
||||
ad.loginMu.Lock()
|
||||
defer ad.loginMu.Unlock()
|
||||
return ad.loginSession != nil && ad.loginSession.currentPhase() == "scaned"
|
||||
})
|
||||
|
||||
// Push startedAt well past the reuse window so only the protection, not the window,
|
||||
// could keep the QR. Then a refresh must still reuse it.
|
||||
// 把 startedAt 推到远超复用窗口之前,使保住该二维码的只能是保护逻辑而非窗口本身。
|
||||
// 此时一次刷新仍必须复用它。
|
||||
ad.loginMu.Lock()
|
||||
if ad.loginSession != nil {
|
||||
ad.loginSession.startedAt = time.Now().Add(-(60*time.Second + time.Second))
|
||||
@@ -91,10 +90,9 @@ func TestStartLogin_ScanedPastWindowReusesQR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStartLogin_WaitingPastWindowReMints verifies the explicit-refresh scenario is
|
||||
// preserved: a QR that is still waiting (not yet scanned) and is past the reuse window
|
||||
// is re-minted with a fresh get_bot_qrcode, and the cancelled old poll never clobbers
|
||||
// the new session's state with "failed".
|
||||
// TestStartLogin_WaitingPastWindowReMints 验证显式刷新场景仍然成立:仍在等待(尚未
|
||||
// 被扫描)且已过复用窗口的二维码会用新的 get_bot_qrcode 重新生成,且被取消的旧轮询
|
||||
// 绝不会用 "failed" 覆盖新会话的状态。
|
||||
func TestStartLogin_WaitingPastWindowReMints(t *testing.T) {
|
||||
t.Parallel()
|
||||
rec := &reqRecorder{}
|
||||
@@ -142,15 +140,14 @@ func TestStartLogin_WaitingPastWindowReMints(t *testing.T) {
|
||||
if got := len(rec.find(func(q recordedReq) bool { return q.path == "/ilink/bot/get_bot_qrcode" })); got != 2 {
|
||||
t.Fatalf("get_bot_qrcode called %d times, want 2 (past-window waiting refresh re-mints)", got)
|
||||
}
|
||||
// The cancelled old poll must not clobber the freshly-minted waiting state.
|
||||
// 被取消的旧轮询不得覆盖刚生成出来的 waiting 状态。
|
||||
if status, _ := ad.LoginStatus(context.Background()); status != LoginStatusWaiting {
|
||||
t.Fatalf("LoginStatus after re-mint = %q, want waiting (superceded session must not set failed)", status)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLogin_LogRedaction verifies the scan-login path logs only redacted identifiers:
|
||||
// the renderable QR URL and the bot id are present, but the raw qrcode identifier, the
|
||||
// bot_token, and the owner user_id are never written.
|
||||
// TestLogin_LogRedaction 验证扫码登录路径只记录已脱敏的标识:可渲染的二维码 URL 与
|
||||
// bot id 会出现,但原始 qrcode 标识符、bot_token 以及主人的 user_id 绝不写入。
|
||||
func TestLogin_LogRedaction(t *testing.T) {
|
||||
t.Parallel()
|
||||
var buf bytes.Buffer
|
||||
@@ -188,9 +185,9 @@ func TestLogin_LogRedaction(t *testing.T) {
|
||||
logs := buf.String()
|
||||
for _, want := range []string{
|
||||
"get_bot_qrcode ok",
|
||||
"https://img/redact", // sanitized renderable URL
|
||||
"https://img/redact", // 已脱敏的可渲染 URL
|
||||
"login confirmed",
|
||||
"bot-redact", // bot id is non-sensitive
|
||||
"bot-redact", // bot id 非敏感
|
||||
} {
|
||||
if !strings.Contains(logs, want) {
|
||||
t.Fatalf("logs missing %q:\n%s", want, logs)
|
||||
|
||||
Reference in new issue
Block a user