-
Notifications
You must be signed in to change notification settings - Fork 18
/
auth_test.go
52 lines (44 loc) · 1.1 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
package client
import (
"encoding/json"
clientv3 "go.etcd.io/etcd/client/v3"
. "gopkg.in/check.v1"
)
const (
TEST_AUTH_ROLE = "test_role"
TEST_AUTH_FROM_KEY = "/test_from"
TEST_AUTH_TO_KEY = "/test_to"
)
type AuthSuite struct{}
func (s *AuthSuite) SetUpSuite(c *C) {
_, err := client.client.RoleAdd(client.ctx, TEST_AUTH_ROLE)
if err != nil {
c.Error(err)
}
}
func (s *AuthSuite) TearDownSuite(c *C) {
_, err := client.client.RoleDelete(client.ctx, TEST_AUTH_ROLE)
if err != nil {
c.Error(err)
}
}
func (s *AuthSuite) TestRole(c *C) {
c.Assert(
client.RoleGrantPermission(TEST_AUTH_ROLE, TEST_AUTH_FROM_KEY, TEST_AUTH_TO_KEY, clientv3.PermissionType(clientv3.PermRead)),
Equals,
nil,
)
perms, err := client.GetRolePerms(TEST_AUTH_ROLE)
c.Assert(err, Equals, nil)
b, _ := json.MarshalIndent(perms, "", " ")
c.Log(string(b))
c.Assert(
client.RoleRevokePermission(TEST_AUTH_ROLE, TEST_AUTH_FROM_KEY, TEST_AUTH_TO_KEY),
Equals,
nil,
)
perms, err = client.GetRolePerms(TEST_AUTH_ROLE)
c.Assert(err, Equals, nil)
b, _ = json.MarshalIndent(perms, "", " ")
c.Log(string(b))
}