-
Notifications
You must be signed in to change notification settings - Fork 31
/
permission_client_test.go
76 lines (64 loc) · 1.76 KB
/
permission_client_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
package stream_chat
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPermissions_RoleEndpoints(t *testing.T) {
c := initClient(t)
p := c.Permissions()
ctx := context.Background()
roleName := randomString(12)
_, err := p.CreateRole(ctx, roleName)
require.NoError(t, err)
_, _ = p.DeleteRole(ctx, roleName)
// Unfortunately the API is too slow to create roles
// and we don't want to wait > 10 seconds.
// So we swallow potential errors here until that's fixed.
// Plus we add a cleanup as well.
roles, err := p.ListRoles(ctx)
require.NoError(t, err)
assert.NotEmpty(t, roles)
t.Cleanup(func() {
resp, _ := p.ListRoles(ctx)
for _, role := range resp.Roles {
if role.Custom {
_, _ = p.DeleteRole(ctx, role.Name)
}
}
})
}
func TestPermissions_PermissionEndpoints(t *testing.T) {
c := initClient(t)
p := c.Permissions()
ctx := context.Background()
permName := randomString(12)
_, err := p.CreatePermission(ctx, &Permission{
ID: permName,
Name: permName,
Action: "DeleteChannel",
Description: "integration test",
Condition: map[string]interface{}{
"$subject.magic_custom_field": map[string]string{"$eq": "true"},
},
})
require.NoError(t, err)
perms, err := p.ListPermissions(ctx)
require.NoError(t, err)
assert.NotEmpty(t, perms)
resp, err := p.GetPermission(ctx, "create-channel")
require.NoError(t, err)
perm := resp.Permission
assert.Equal(t, "create-channel", perm.ID)
assert.False(t, perm.Custom)
assert.Empty(t, perm.Condition)
t.Cleanup(func() {
resp, _ := p.ListPermissions(ctx)
for _, perm := range resp.Permissions {
if perm.Description == "integration test" {
_, _ = p.DeletePermission(ctx, perm.ID)
}
}
})
}