eacl: Fix bug with casting to ObjectAccessDenied error #553
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"
|
||||
|
||||
func basicACLErr(info RequestInfo) error {
|
||||
var errAccessDenied apistatus.ObjectAccessDenied
|
||||
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
||||
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedACLReasonFmt, info.operation))
|
||||
|
||||
return errAccessDenied
|
||||
}
|
||||
|
||||
func eACLErr(info RequestInfo, err error) error {
|
||||
var errAccessDenied apistatus.ObjectAccessDenied
|
||||
errAccessDenied := &apistatus.ObjectAccessDenied{}
|
||||
errAccessDenied.WriteReason(fmt.Sprintf(accessDeniedEACLReasonFmt, info.operation, err))
|
||||
|
||||
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
|
||||
fyrchik marked this conversation as resolved
Outdated
fyrchik
commented
This is not "any error", the most generic would be sth with This is not "any error", the most generic would be sth with `errors.New` I believe
aarifullin
commented
Alright. I think you are right. I needed any error to create the instance :) UPD: fixed to Alright. I think you are right. I needed any error to create the instance :)
UPD: fixed to `errors.New`
|
||||
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
require.True(...)
.Same below.
require.ErrorsAs
is also possibleChanged to
require.ErrorsAs
.To be honest I don't really like message format that
require
package uses for errors. That's why I initally usedt.Fatalf
, but I am ok withrequire.ErrorsAs