-
Notifications
You must be signed in to change notification settings - Fork 664
/
captcha_test.go
66 lines (58 loc) · 1.59 KB
/
captcha_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package helper
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
"github.com/yaoapp/kun/maps"
)
func TestCaptcha(t *testing.T) {
id, content := CaptchaMake(CaptchaOption{
Type: "audio",
Width: 240,
Height: 80,
Length: 4,
Lang: "zh",
})
assert.IsType(t, "string", id)
assert.IsType(t, "string", content)
assert.True(t, CaptchaValidate(id, toString(store.Get(id, false))))
id, content = CaptchaMake(CaptchaOption{
Type: "math",
Width: 240,
Height: 80,
Length: 4,
Lang: "zh",
})
assert.IsType(t, "string", id)
assert.IsType(t, "string", content)
assert.True(t, CaptchaValidate(id, toString(store.Get(id, false))))
id, content = CaptchaMake(CaptchaOption{
Type: "digit",
Width: 240,
Height: 80,
Length: 4,
Lang: "zh",
})
assert.IsType(t, "string", id)
assert.IsType(t, "string", content)
assert.True(t, CaptchaValidate(id, toString(store.Get(id, false))))
}
func TestProcessCaptcha(t *testing.T) {
args := url.Values{}
args.Add("type", "math")
args.Add("lang", "zh")
p := process.New("xiang.helper.Captcha", args)
res := p.Run().(maps.Map)
assert.IsType(t, "string", res.Get("id"))
assert.IsType(t, "string", res.Get("content"))
value := toString(store.Get(res.Get("id").(string), false))
p = process.New("xiang.helper.CaptchaValidate", res.Get("id"), value)
assert.True(t, p.Run().(bool))
assert.Panics(t, func() {
process.New("xiang.helper.CaptchaValidate", res.Get("id"), "xxx").Run()
})
assert.Panics(t, func() {
process.New("xiang.helper.CaptchaValidate", res.Get("id"), "").Run()
})
}