-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth_test.go
73 lines (64 loc) · 1.56 KB
/
auth_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
67
68
69
70
71
72
73
package bingauth_test
import (
"encoding/json"
"fmt"
"strings"
"testing"
bingauth "github.com/Harry-zklcdc/ms-auth"
)
func TestAuthPasswd(t *testing.T) {
t.Log("Test Auth Passwd")
auth := bingauth.NewAuth("[email protected]", "123456", bingauth.TYPE_PASSWD)
cookie, err := auth.Auth()
if err != nil {
t.Error(err)
}
t.Log(cookie)
}
func TestAuthEmail(t *testing.T) {
t.Log("Test Auth Email")
auth := bingauth.NewAuth("[email protected]", "", bingauth.TYPE_EMAIL)
cookie, err := auth.Auth()
if err != nil {
if err.Error() != "email login need code to continue" || auth.GetLoginType() != bingauth.TYPE_EMAIL {
t.Error(err)
return
}
d, _ := json.Marshal(auth)
var code string
fmt.Printf("input code: ")
fmt.Scan(&code)
auth = bingauth.NewAuth("[email protected]", "", bingauth.TYPE_EMAIL)
auth.SetContext(d)
auth.SetCookie(cookie)
cookie, err = auth.AuthEmail(code)
if err != nil {
t.Error(err)
return
}
}
t.Log(cookie)
}
func TestAuthDevice(t *testing.T) {
t.Log("Test Auth Device")
auth := bingauth.NewAuth("[email protected]", "", bingauth.TYPE_DEVICE)
cookie, err := auth.Auth()
if err != nil {
if !strings.HasPrefix(err.Error(), "device login need handler to continue") || auth.GetLoginType() != bingauth.TYPE_DEVICE {
t.Error(err)
return
}
d, _ := json.Marshal(auth)
code := strings.Split(err.Error(), "code: ")[1]
t.Log("Verify Code: ", code)
auth := bingauth.NewAuth("[email protected]", "", bingauth.TYPE_DEVICE)
auth.SetContext(d)
auth.SetCookie(cookie)
cookie, err = auth.AuthDevice()
if err != nil {
t.Error(err)
return
}
}
t.Log(cookie)
}