25 lines
736 B
Go
25 lines
736 B
Go
package auth
|
|
|
|
import "testing"
|
|
|
|
func TestHasPermission(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
permissions []string
|
|
permission string
|
|
want bool
|
|
}{
|
|
{name: "exact", permissions: []string{"sop.view"}, permission: "sop.view", want: true},
|
|
{name: "wildcard", permissions: []string{"*"}, permission: "sop.publish", want: true},
|
|
{name: "denied", permissions: []string{"sop.view"}, permission: "sop.publish", want: false},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
principal := Principal{Permissions: test.permissions}
|
|
if got := HasPermission(principal, test.permission); got != test.want {
|
|
t.Fatalf("HasPermission() = %v, want %v", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|