2022-02-11 20:53:23 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPermissionDeniedError(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
err PermissionDeniedError
|
|
|
|
expected string
|
|
|
|
}
|
|
|
|
|
|
|
|
testName := func(t testCase) string {
|
|
|
|
return t.expected
|
|
|
|
}
|
|
|
|
|
2022-11-14 20:35:12 +00:00
|
|
|
auth1 := MockAuthorizer{}
|
2022-02-11 20:53:23 +00:00
|
|
|
|
|
|
|
cases := []testCase{
|
|
|
|
{
|
|
|
|
err: PermissionDeniedError{},
|
|
|
|
expected: "Permission denied",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
err: PermissionDeniedError{Cause: "simon says"},
|
|
|
|
expected: "Permission denied: simon says",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
err: PermissionDeniedByACL(&auth1, nil, ResourceService, AccessRead, "foobar"),
|
2022-03-25 19:34:59 +00:00
|
|
|
expected: "Permission denied: provided token lacks permission 'service:read' on \"foobar\"",
|
2022-02-11 20:53:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
err: PermissionDeniedByACLUnnamed(&auth1, nil, ResourceService, AccessRead),
|
2022-03-25 19:34:59 +00:00
|
|
|
expected: "Permission denied: provided token lacks permission 'service:read'",
|
2022-02-11 20:53:23 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tcase := range cases {
|
|
|
|
t.Run(testName(tcase), func(t *testing.T) {
|
|
|
|
require.Error(t, tcase.err)
|
|
|
|
require.Equal(t, tcase.expected, tcase.err.Error())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|