forked from clerk/clerk-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt_test.go
60 lines (56 loc) · 1.07 KB
/
jwt_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
package clerk
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestSessionClaimsHasRole(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
active string
role string
want bool
}{
{
active: "active",
role: "non-active",
want: false,
},
{
active: "active",
role: "active",
want: true,
},
} {
claims := SessionClaims{}
claims.ActiveOrganizationRole = tc.active
require.Equal(t, claims.HasRole(tc.role), tc.want)
}
}
func TestSessionClaimsHasPermission(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
active []string
permission string
want bool
}{
{
active: []string{"active"},
permission: "non-active",
want: false,
},
{
active: []string{"active", "non-active"},
permission: "active",
want: true,
},
{
active: []string{},
permission: "active",
want: false,
},
} {
claims := SessionClaims{}
claims.ActiveOrganizationPermissions = tc.active
require.Equal(t, claims.HasPermission(tc.permission), tc.want)
}
}