2021-05-26 17:18:42 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
|
|
|
v2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/v2"
|
2022-05-31 17:00:41 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-02-11 12:25:05 +00:00
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
2022-05-17 13:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
|
|
|
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
|
2021-05-26 17:18:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
type emptyEACLSource struct{}
|
2021-05-26 17:18:42 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (e emptyEACLSource) GetEACL(_ cid.ID) (*eaclSDK.Table, error) {
|
2022-02-11 12:25:05 +00:00
|
|
|
return nil, nil
|
2021-05-26 17:18:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
type emptyNetmapState struct{}
|
2021-05-26 17:18:42 +00:00
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
func (e emptyNetmapState) CurrentEpoch() uint64 {
|
|
|
|
return 0
|
2021-05-26 17:18:42 +00:00
|
|
|
}
|
2021-09-10 11:35:29 +00:00
|
|
|
|
|
|
|
func TestStickyCheck(t *testing.T) {
|
2022-02-11 12:25:05 +00:00
|
|
|
checker := NewChecker(new(CheckerPrm).
|
|
|
|
SetLocalStorage(&engine.StorageEngine{}).
|
|
|
|
SetValidator(eaclSDK.NewValidator()).
|
|
|
|
SetEACLSource(emptyEACLSource{}).
|
|
|
|
SetNetmapState(emptyNetmapState{}),
|
|
|
|
)
|
|
|
|
|
2021-09-10 11:35:29 +00:00
|
|
|
t.Run("system role", func(t *testing.T) {
|
2022-02-11 12:25:05 +00:00
|
|
|
var info v2.RequestInfo
|
|
|
|
|
|
|
|
info.SetSenderKey(make([]byte, 33)) // any non-empty key
|
|
|
|
info.SetRequestRole(eaclSDK.RoleSystem)
|
|
|
|
|
|
|
|
setSticky(&info, true)
|
2021-09-10 11:35:29 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
require.True(t, checker.StickyBitCheck(info, *usertest.ID()))
|
2021-09-10 11:35:29 +00:00
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
setSticky(&info, false)
|
2021-09-10 11:35:29 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
require.True(t, checker.StickyBitCheck(info, *usertest.ID()))
|
2021-09-10 11:35:29 +00:00
|
|
|
})
|
2021-11-08 10:49:20 +00:00
|
|
|
|
|
|
|
t.Run("owner ID and/or public key emptiness", func(t *testing.T) {
|
2022-02-11 12:25:05 +00:00
|
|
|
var info v2.RequestInfo
|
2021-11-08 10:49:20 +00:00
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
info.SetRequestRole(eaclSDK.RoleOthers) // should be non-system role
|
2021-11-08 10:49:20 +00:00
|
|
|
|
|
|
|
assertFn := func(isSticky, withKey, withOwner, expected bool) {
|
|
|
|
if isSticky {
|
2022-02-11 12:25:05 +00:00
|
|
|
setSticky(&info, true)
|
2021-11-08 10:49:20 +00:00
|
|
|
} else {
|
2022-02-11 12:25:05 +00:00
|
|
|
setSticky(&info, false)
|
2021-11-08 10:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if withKey {
|
2022-02-11 12:25:05 +00:00
|
|
|
info.SetSenderKey(make([]byte, 33))
|
2021-11-08 10:49:20 +00:00
|
|
|
} else {
|
2022-02-11 12:25:05 +00:00
|
|
|
info.SetSenderKey(nil)
|
2021-11-08 10:49:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var ownerID user.ID
|
2021-11-08 10:49:20 +00:00
|
|
|
|
|
|
|
if withOwner {
|
2022-05-31 17:00:41 +00:00
|
|
|
ownerID = *usertest.ID()
|
2021-11-08 10:49:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
require.Equal(t, expected, checker.StickyBitCheck(info, ownerID))
|
2021-11-08 10:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2021-09-10 11:35:29 +00:00
|
|
|
}
|
2022-02-11 12:25:05 +00:00
|
|
|
|
|
|
|
func setSticky(req *v2.RequestInfo, enabled bool) {
|
|
|
|
bh := basicACLHelper(req.BasicACL())
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
bh.SetSticky()
|
|
|
|
} else {
|
|
|
|
bh.ResetSticky()
|
|
|
|
}
|
|
|
|
|
|
|
|
req.SetBasicACL(uint32(bh))
|
|
|
|
}
|