修复登录及验证码功能
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user