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"
|
|
|
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/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-02-11 12:25:05 +00:00
|
|
|
func (e emptyEACLSource) GetEACL(_ *cidSDK.ID) (*eaclSDK.Table, error) {
|
|
|
|
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-02-11 12:25:05 +00:00
|
|
|
require.True(t, checker.StickyBitCheck(info, ownertest.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-02-11 12:25:05 +00:00
|
|
|
require.True(t, checker.StickyBitCheck(info, ownertest.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
|
|
|
}
|
|
|
|
|
|
|
|
var ownerID *owner.ID
|
|
|
|
|
|
|
|
if withOwner {
|
2021-12-01 13:56:48 +00:00
|
|
|
ownerID = ownertest.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))
|
|
|
|
}
|