From b3695411d907c3c65485bab04f9ff8479a72906b Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 1 Aug 2023 16:21:34 +0300 Subject: [PATCH] [#553] eacl: Fix bug with casting to ObjectAccessDenied error Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- pkg/services/object/acl/v2/errors.go | 4 +-- pkg/services/object/acl/v2/errors_test.go | 30 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 pkg/services/object/acl/v2/errors_test.go diff --git a/pkg/services/object/acl/v2/errors.go b/pkg/services/object/acl/v2/errors.go index 70c1ae991..7fc20d618 100644 --- a/pkg/services/object/acl/v2/errors.go +++ b/pkg/services/object/acl/v2/errors.go @@ -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 diff --git a/pkg/services/object/acl/v2/errors_test.go b/pkg/services/object/acl/v2/errors_test.go new file mode 100644 index 000000000..2d2b7bc8d --- /dev/null +++ b/pkg/services/object/acl/v2/errors_test.go @@ -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") +}