-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
59 lines (53 loc) · 1.34 KB
/
main_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
package iriscaptchago
import (
"fmt"
"testing"
)
func TestNewIrisCaptchaHandler(t *testing.T) {
var secretCases = []struct {
secret string
want error
}{
{"", ErrInvalidSecret},
{"abcabcabc", ErrInvalidSecret},
{"533a64afb4c496ca4dcbe081aa40x2711", nil},
{"533a64afb4c496ca4dcb0x2711e081aa40x2711", nil},
}
for _, tt := range secretCases {
testname := fmt.Sprintf("%s\n", tt.secret)
t.Run(testname, func(t *testing.T) {
_, err := NewIrisCaptchaHandler(tt.secret)
if err != tt.want {
t.Errorf("got %v, want %v", err, tt.want)
}
})
}
}
func TestGetJs(t *testing.T) {
c, err := NewIrisCaptchaHandler("533a64afb4c496ca4dcb0x2711e081aa40x2711")
if err != nil {
t.Errorf("got %v, want %v", err, nil)
}
ans := c.GetJs()
const cres = `<script src="https://captcha.irisdev.net/js/0x2711></script>`
if ans != cres {
t.Errorf("got %s, want %s", ans, cres)
}
}
func TestLoadPublicKey(t *testing.T) {
c := new(irisCaptchaHandler)
c.provider = IrisDevServer
err := c.loadPublicKey()
if err != nil {
t.Errorf("got %v, want %v", err, nil)
}
}
func TestValidateReq(t *testing.T) {
c, err := NewIrisCaptchaHandler("533a64afb4c496cc34dfd00d1ecbd45cfa2784b2c3eba4aa02e7a4dcbe081aa40x2711")
if err != nil {
t.Errorf("got %v, want %v", err, nil)
}
h := c.(*irisCaptchaHandler)
h.TestValidateReq(t)
h.TestValidateSig(t)
}