forked from TrueCloudLab/frostfs-node
[#553] eacl: Fix bug with casting to ObjectAccessDenied error
Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
parent
ec8a631d31
commit
b3695411d9
2 changed files with 32 additions and 2 deletions
|
@ -25,14 +25,14 @@ const accessDeniedACLReasonFmt = "access to operation %s is denied by basic ACL
|
||||||
const accessDeniedEACLReasonFmt = "access to operation %s is denied by extended ACL check: %v"
|
const accessDeniedEACLReasonFmt = "access to operation %s is denied by extended ACL check: %v"
|
||||||
|
|
||||||
func basicACLErr(info RequestInfo) error {
|
func basicACLErr(info RequestInfo) error {
|
||||||
var errAccessDenied apistatus.ObjectAccessDenied
|
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
||||||
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedACLReasonFmt, info.operation))
|
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedACLReasonFmt, info.operation))
|
||||||
|
|
||||||
return errAccessDenied
|
return errAccessDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
func eACLErr(info RequestInfo, err error) error {
|
func eACLErr(info RequestInfo, err error) error {
|
||||||
var errAccessDenied apistatus.ObjectAccessDenied
|
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
||||||
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedEACLReasonFmt, info.operation, err))
|
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedEACLReasonFmt, info.operation, err))
|
||||||
|
|
||||||
return errAccessDenied
|
return errAccessDenied
|
||||||
|
|
30
pkg/services/object/acl/v2/errors_test.go
Normal file
30
pkg/services/object/acl/v2/errors_test.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package v2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBasicACLErr(t *testing.T) {
|
||||||
|
var reqInfo RequestInfo
|
||||||
|
err := basicACLErr(reqInfo)
|
||||||
|
|
||||||
|
var errAccessDenied *apistatus.ObjectAccessDenied
|
||||||
|
|
||||||
|
require.ErrorAs(t, err, &errAccessDenied,
|
||||||
|
"basicACLErr must be able to be casted to apistatus.ObjectAccessDenied")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEACLErr(t *testing.T) {
|
||||||
|
var reqInfo RequestInfo
|
||||||
|
testErr := errors.New("test-eacl")
|
||||||
|
err := eACLErr(reqInfo, testErr)
|
||||||
|
|
||||||
|
var errAccessDenied *apistatus.ObjectAccessDenied
|
||||||
|
|
||||||
|
require.ErrorAs(t, err, &errAccessDenied,
|
||||||
|
"eACLErr must be able to be casted to apistatus.ObjectAccessDenied")
|
||||||
|
}
|
Loading…
Reference in a new issue