2022-02-02 11:18:05 +00:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-04-06 08:03:41 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
|
|
|
sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test"
|
2022-02-02 11:18:05 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-04-06 08:03:41 +00:00
|
|
|
func TestSessionCache_GetUnmodifiedToken(t *testing.T) {
|
|
|
|
const key = "Foo"
|
|
|
|
target := sessiontest.Token()
|
|
|
|
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
check := func(t *testing.T, tok *session.Token, extra string) {
|
2022-04-05 11:13:34 +00:00
|
|
|
require.False(t, tok.VerifySignature(), extra)
|
2022-04-06 08:03:41 +00:00
|
|
|
require.Nil(t, tok.Context(), extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
cache, err := newCache()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cache.Put(key, target)
|
|
|
|
value := cache.Get(key)
|
|
|
|
check(t, value, "before sign")
|
|
|
|
|
|
|
|
err = value.Sign(&pk.PrivateKey)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
octx := sessiontest.ObjectContext()
|
|
|
|
value.SetContext(octx)
|
|
|
|
|
|
|
|
value = cache.Get(key)
|
|
|
|
check(t, value, "after sign")
|
|
|
|
}
|