2022-02-11 12:25:05 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
|
|
|
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2022-05-12 07:22:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/bearer"
|
2022-02-28 12:35:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
2022-02-11 12:25:05 +00:00
|
|
|
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
2022-05-18 15:20:08 +00:00
|
|
|
sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test"
|
2022-02-11 12:25:05 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestOriginalTokens(t *testing.T) {
|
2022-05-18 15:20:08 +00:00
|
|
|
sToken := sessiontest.ObjectSigned()
|
2022-05-12 07:22:02 +00:00
|
|
|
bTokenV2 := acltest.GenerateBearerToken(false)
|
|
|
|
|
|
|
|
var bToken bearer.Token
|
|
|
|
bToken.ReadFromV2(*bTokenV2)
|
2022-02-11 12:25:05 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
var sTokenV2 session.Token
|
|
|
|
sToken.WriteToV2(&sTokenV2)
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
2022-05-18 15:20:08 +00:00
|
|
|
metaHeaders := testGenerateMetaHeader(uint32(i), bTokenV2, &sTokenV2)
|
|
|
|
res, err := originalSessionToken(metaHeaders)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, sToken, res, i)
|
2022-05-12 07:22:02 +00:00
|
|
|
require.Equal(t, &bToken, originalBearerToken(metaHeaders), i)
|
2022-02-11 12:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 08:49:19 +00:00
|
|
|
func testGenerateMetaHeader(depth uint32, b *acl.BearerToken, s *session.Token) *session.RequestMetaHeader {
|
2022-02-11 12:25:05 +00:00
|
|
|
metaHeader := new(session.RequestMetaHeader)
|
|
|
|
metaHeader.SetBearerToken(b)
|
|
|
|
metaHeader.SetSessionToken(s)
|
|
|
|
|
|
|
|
for i := uint32(0); i < depth; i++ {
|
|
|
|
link := metaHeader
|
|
|
|
metaHeader = new(session.RequestMetaHeader)
|
|
|
|
metaHeader.SetOrigin(link)
|
|
|
|
}
|
|
|
|
|
|
|
|
return metaHeader
|
|
|
|
}
|
2022-02-28 12:35:10 +00:00
|
|
|
|
|
|
|
func TestIsVerbCompatible(t *testing.T) {
|
|
|
|
// Source: https://nspcc.ru/upload/neofs-spec-latest.pdf#page=28
|
2022-05-18 15:20:08 +00:00
|
|
|
table := map[eacl.Operation][]sessionSDK.ObjectVerb{
|
|
|
|
eacl.OperationPut: {sessionSDK.VerbObjectPut, sessionSDK.VerbObjectDelete},
|
|
|
|
eacl.OperationDelete: {sessionSDK.VerbObjectDelete},
|
|
|
|
eacl.OperationGet: {sessionSDK.VerbObjectGet},
|
|
|
|
eacl.OperationHead: {
|
|
|
|
sessionSDK.VerbObjectHead,
|
|
|
|
sessionSDK.VerbObjectGet,
|
|
|
|
sessionSDK.VerbObjectDelete,
|
|
|
|
sessionSDK.VerbObjectRange,
|
|
|
|
sessionSDK.VerbObjectRangeHash,
|
|
|
|
},
|
|
|
|
eacl.OperationRange: {sessionSDK.VerbObjectRange, sessionSDK.VerbObjectRangeHash},
|
|
|
|
eacl.OperationRangeHash: {sessionSDK.VerbObjectRangeHash},
|
|
|
|
eacl.OperationSearch: {sessionSDK.VerbObjectSearch, sessionSDK.VerbObjectDelete},
|
2022-02-28 12:35:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
verbs := []sessionSDK.ObjectVerb{
|
|
|
|
sessionSDK.VerbObjectPut,
|
|
|
|
sessionSDK.VerbObjectDelete,
|
|
|
|
sessionSDK.VerbObjectHead,
|
|
|
|
sessionSDK.VerbObjectRange,
|
|
|
|
sessionSDK.VerbObjectRangeHash,
|
|
|
|
sessionSDK.VerbObjectGet,
|
|
|
|
sessionSDK.VerbObjectSearch,
|
2022-02-28 12:35:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
var tok sessionSDK.Object
|
|
|
|
|
|
|
|
for op, list := range table {
|
|
|
|
for _, verb := range verbs {
|
2022-02-28 12:35:10 +00:00
|
|
|
var contains bool
|
2022-05-18 15:20:08 +00:00
|
|
|
for _, v := range list {
|
|
|
|
if v == verb {
|
2022-02-28 12:35:10 +00:00
|
|
|
contains = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
tok.ForVerb(verb)
|
|
|
|
|
|
|
|
require.Equal(t, contains, assertVerb(tok, op),
|
|
|
|
"%v in token, %s executing", verb, op)
|
2022-02-28 12:35:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|