package wechatcallback import ( "crypto/sha256" "encoding/base64" "net/http" "net/http/httptest" "strings" "testing" ) func TestWriteAuthorizationResult(t *testing.T) { for _, test := range []struct { name string authorized bool status int message string }{ {"authorized", true, http.StatusOK, "等待确认绑定"}, {"expired", false, http.StatusBadRequest, "请重新扫码"}, } { t.Run(test.name, func(t *testing.T) { response := httptest.NewRecorder() Write(response, test.authorized) if response.Code != test.status { t.Fatalf("授权结果状态码错误:%d", response.Code) } body := response.Body.String() for _, expected := range []string{test.message, `lang="zh-CN"`, `width=device-width, initial-scale=1`, "回到发起扫码的 Smail 页面", ""} { if !strings.Contains(body, expected) { t.Fatalf("结果页缺少预期内容:%s", expected) } } for _, forbidden := range []string{"