forked from mikespook/gorbac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permission_layer_test.go
44 lines (41 loc) · 1.29 KB
/
permission_layer_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
package gorbac
import (
"encoding/json"
"testing"
)
func TestLayerPermission(t *testing.T) {
profile1 := NewLayerPermission("profile1", "::")
profile2 := NewLayerPermission("profile2", "::")
admin := NewLayerPermission("admin", "::")
admindashboard := NewLayerPermission("admin::dashboard", "::")
adminpassword := NewLayerPermission("admin::password", "::")
if !profile1.Match(profile1) {
t.Fatalf("`%[1]s` should have the permission `%[1]s`", profile1.ID())
}
if profile1.Match(profile2) {
t.Fatalf("`%s` should not have the permission `%s`", profile1.ID(), profile2.ID())
}
if profile1.Match(admin) {
t.Fatalf("`%s` should not have the permission `%s`", profile1.ID(), admin.ID())
}
text, err := json.Marshal(admin)
if err != nil {
t.Fatal(err)
}
var p LayerPermission
if err := json.Unmarshal(text, &p); err != nil {
t.Fatal(err)
}
if p.ID() != "admin" {
t.Fatalf("`admin` expected, but `%s` got", p.ID())
}
if !p.Match(admindashboard) {
t.Fatalf("`%s` should have the permission `%s`", p.ID(), admindashboard.ID())
}
if admindashboard.Match(p) {
t.Fatalf("`%s` should not have the permission `%s`", admindashboard.ID(), p.ID())
}
if adminpassword.Match(admindashboard) {
t.Fatalf("`%s` should not have the permission `%s`", adminpassword.ID(), admindashboard)
}
}