diff --git a/pool/pool.go b/pool/pool.go index e7004bdf..4f2904d8 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -498,7 +498,12 @@ func (p *pool) conn(ctx context.Context, cfg *callConfig) (*clientPack, []client return nil, nil, err } - sessionToken = p.newSessionToken(cliRes) + wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey) + if err != nil { + return nil, nil, err + } + ownerID := owner.NewIDFromNeo3Wallet(wallet) + sessionToken = sessionTokenForOwner(ownerID, cliRes) _ = p.cache.Put(cacheKey, sessionToken) } diff --git a/pool/pool_test.go b/pool/pool_test.go index 766455a0..c23d6b5d 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -15,6 +15,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/netmap" + "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/stretchr/testify/require" "go.uber.org/zap" @@ -482,6 +483,46 @@ func newToken(t *testing.T) *session.Token { return tok } +func TestSessionTokenOwner(t *testing.T) { + ctrl := gomock.NewController(t) + clientBuilder := func(opts ...client.Option) (Client, error) { + mockClient := NewMockClient(ctrl) + mockClient.EXPECT().CreateSession(gomock.Any(), gomock.Any(), gomock.Any()).Return(&client.CreateSessionRes{}, nil).AnyTimes() + mockClient.EXPECT().EndpointInfo(gomock.Any(), gomock.Any()).Return(&client.EndpointInfoRes{}, nil).AnyTimes() + return mockClient, nil + } + + pb := new(Builder) + pb.AddNode("peer0", 1, 1) + + opts := &BuilderOptions{ + Key: newPrivateKey(t), + clientBuilder: clientBuilder, + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + pp, err := pb.Build(ctx, opts) + require.NoError(t, err) + t.Cleanup(pp.Close) + + p, ok := pp.(*pool) + require.True(t, ok) + + anonKey := newPrivateKey(t) + wallet, err := owner.NEO3WalletFromPublicKey(&anonKey.PublicKey) + require.NoError(t, err) + anonOwner := owner.NewIDFromNeo3Wallet(wallet) + + cfg := cfgFromOpts(WithKey(anonKey), useDefaultSession()) + cp, _, err := p.conn(ctx, cfg) + require.NoError(t, err) + + tkn := p.cache.Get(formCacheKey(cp.address, anonKey)) + require.True(t, anonOwner.Equal(tkn.OwnerID())) +} + func TestWaitPresence(t *testing.T) { ctrl := gomock.NewController(t)