frostfs-node/pkg/services/object/acl/acl_test.go
Dmitrii Stepanov 61541eaec2 [#294] aclsvc: Refactor checker constructor
Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-07-12 07:42:10 +00:00

89 lines
2.2 KiB
Go

package acl
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
v2 "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/acl/v2"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
eaclSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
"github.com/stretchr/testify/require"
)
type emptyEACLSource struct{}
func (e emptyEACLSource) GetEACL(_ cid.ID) (*container.EACL, error) {
return nil, nil
}
type emptyNetmapState struct{}
func (e emptyNetmapState) CurrentEpoch() uint64 {
return 0
}
func TestStickyCheck(t *testing.T) {
checker := NewChecker(
emptyNetmapState{},
emptyEACLSource{},
eaclSDK.NewValidator(),
&engine.StorageEngine{})
t.Run("system role", func(t *testing.T) {
var info v2.RequestInfo
info.SetSenderKey(make([]byte, 33)) // any non-empty key
info.SetRequestRole(acl.RoleContainer)
require.True(t, checker.StickyBitCheck(info, *usertest.ID()))
var basicACL acl.Basic
basicACL.MakeSticky()
info.SetBasicACL(basicACL)
require.True(t, checker.StickyBitCheck(info, *usertest.ID()))
})
t.Run("owner ID and/or public key emptiness", func(t *testing.T) {
var info v2.RequestInfo
info.SetRequestRole(acl.RoleOthers) // should be non-system role
assertFn := func(isSticky, withKey, withOwner, expected bool) {
info := info
if isSticky {
var basicACL acl.Basic
basicACL.MakeSticky()
info.SetBasicACL(basicACL)
}
if withKey {
info.SetSenderKey(make([]byte, 33))
} else {
info.SetSenderKey(nil)
}
var ownerID user.ID
if withOwner {
ownerID = *usertest.ID()
}
require.Equal(t, expected, checker.StickyBitCheck(info, ownerID))
}
assertFn(true, false, false, false)
assertFn(true, true, false, false)
assertFn(true, false, true, false)
assertFn(false, false, false, true)
assertFn(false, true, false, true)
assertFn(false, false, true, true)
assertFn(false, true, true, true)
})
}