-
Notifications
You must be signed in to change notification settings - Fork 3
/
member_test.go
127 lines (107 loc) · 2.33 KB
/
member_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package organization
import (
"crypto/md5"
"encoding/hex"
"errors"
"testing"
)
func TestAddDelMember(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
m := md5.New()
m.Write([]byte(`123456`))
pwd := m.Sum(nil)
roles, err := org.AllRoles()
if err != nil {
t.Fatal(err)
}
var rids []string
for _, r := range roles {
rids = append(rids, r[`id`].(string))
}
types, err := org.Types(true, 10, nil)
if err != nil {
t.Fatal(err)
}
var tids []string
for _, t := range types.Data {
tids = append(tids, t[`id`].(string))
}
units, err := org.AllUnit()
if err != nil {
t.Fatal(err)
}
var uids []string
for _, u := range units {
uids = append(uids, u[`id`].(string))
}
// 添加一个用户
id, err := org.AddMember(map[string][]string{
`name`: []string{`JustForTTTTTesting`},
`telephoneNumber`: []string{`13134564321`},
`cn`: []string{`王聪灵`},
`email`: []string{`heath.wang@dolores.store`},
`title`: []string{`Developer`},
`thirdAccount`: []string{`heath`},
`thirdPassword`: []string{`111`},
`rbacRole`: rids,
`rbacType`: tids,
`unitID`: uids,
`userPassword`: []string{hex.EncodeToString(pwd)},
})
if err != nil {
t.Fatal(err)
}
// 使用手机号和密码登录 然后返回用户ID
aid, err := org.AuthMember(`13134564321`, hex.EncodeToString(pwd))
if err != nil {
t.Fatal(err)
}
if aid != id {
t.Fatal(errors.New(`Auth method occured error !!!`))
}
// 删除这个用户
err = org.DelMember(id)
if err != nil {
t.Fatal(err)
}
}
func TestFetchAllMembers(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
_, err := org.Members(50, nil)
if err != nil {
t.Fatal(err)
}
}
func TestModifyPassword(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
id := `b4vb0vh1scghuujqilo0`
m := md5.New()
m.Write([]byte(`123456`))
op := hex.EncodeToString(m.Sum(nil))
m.Reset()
m.Write([]byte(`123456`))
np := hex.EncodeToString(m.Sum(nil))
err := org.ModifyPassword(id, op, np)
if err != nil {
t.Fatal(err)
}
member, err := org.MemberByID(id, false, false)
if err != nil {
t.Fatal(err)
}
tel := member[`telephoneNumber`].(string)
_, err = org.AuthMember(tel, np)
if err != nil {
t.Fatal(err)
}
err = org.ModifyPassword(id, np, op) // 还原密码
if err != nil {
t.Fatal(err)
}
}