-
Notifications
You must be signed in to change notification settings - Fork 2
/
role_test.go
79 lines (59 loc) · 1.61 KB
/
role_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
package acl
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewRole(t *testing.T) {
assert.Equal(t, &Role{Id: "test"}, NewRole("test"))
}
func TestRole_AcquireFrom(t *testing.T) {
a := assert.New(t)
r1 := NewRole("r1").Grant("a", "b")
r2 := NewRole("r2").Grant("c", "d")
a.Equal(r2, r2.AcquireFrom(r1))
a.Equal(r1, r1.AcquireFrom(r2))
expected := []string{"a", "b", "c", "d"}
a.Equal(expected, r1.granted)
a.Equal(expected, r2.granted)
}
func TestRole_Revoke(t *testing.T) {
a := assert.New(t)
role := NewRole("test").Grant("a", "b", "c")
a.Equal([]string{"a", "b", "c"}, role.granted)
}
func TestRole_Has(t *testing.T) {
a := assert.New(t)
role := NewRole("test").Grant("a", "b")
a.True(role.Has("a"))
a.True(role.Has("b"))
a.False(role.Has("c"))
}
func TestRole_HasOneOf(t *testing.T) {
a := assert.New(t)
role := NewRole("test").Grant("a", "b")
a.True(role.HasOneOf("a", "b"))
a.True(role.HasOneOf("b", "c"))
a.False(role.HasOneOf("c", "d"))
}
func TestRole_HasAllOf(t *testing.T) {
a := assert.New(t)
role := NewRole("test").Grant("a", "b")
a.True(role.HasAllOf("a", "b"))
a.False(role.HasAllOf("b", "c"))
a.False(role.HasAllOf("c", "d"))
}
func TestRole_SetExaminer(t *testing.T) {
a := assert.New(t)
role := NewRole("test")
a.Nil(role.examiner)
role.SetExaminer(func(payload interface{}) bool { return false })
a.NotNil(role.examiner)
}
func TestRole_examine(t *testing.T) {
a := assert.New(t)
role := NewRole("test")
type fake struct{}
a.False(role.examine(fake{}))
role.SetExaminer(func(payload interface{}) bool { return true })
a.True(role.examine(fake{}))
}