修复登录及验证码功能

This commit is contained in:
2026-09-03 10:12:30 +08:00
parent 57d9866dab
commit 7c38e84e30
13 changed files with 309 additions and 118 deletions
+33
View File
@@ -0,0 +1,33 @@
package captcha
import (
"bytes"
"encoding/base64"
"image/png"
"strings"
"testing"
)
func TestDrawImageValidPNG(t *testing.T) {
img := drawImage("ABCD")
b64 := encodeToBase64(img)
data, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
t.Fatalf("base64 decode failed: %v", err)
}
decoded, err := png.Decode(bytes.NewReader(data))
if err != nil {
t.Fatalf("png decode failed: %v", err)
}
bounds := decoded.Bounds()
if bounds.Dx() != 120 || bounds.Dy() != 40 {
t.Fatalf("expected 120x40, got %dx%d", bounds.Dx(), bounds.Dy())
}
// Verify all characters in chars set can be drawn without panic
for _, ch := range chars {
_ = drawImage(strings.Repeat(string(ch), 4))
}
}