forked from TrueCloudLab/frostfs-api-go
[#179] sdk/token: Add function to return token issuer
With new neofs-api changes, token issuer will not be stored in ownerID field of bearer token. We can identify owner by public key that has been used in signature. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
e023b6e51e
commit
7b212431df
2 changed files with 47 additions and 0 deletions
32
pkg/token/bearer_test.go
Normal file
32
pkg/token/bearer_test.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package token_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBearerToken_Issuer(t *testing.T) {
|
||||
bearerToken := token.NewBearerToken()
|
||||
|
||||
t.Run("non signed token", func(t *testing.T) {
|
||||
require.Nil(t, bearerToken.Issuer())
|
||||
})
|
||||
|
||||
t.Run("signed token", func(t *testing.T) {
|
||||
key := test.DecodeKey(1)
|
||||
|
||||
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
ownerID := owner.NewIDFromNeo3Wallet(wallet)
|
||||
|
||||
bearerToken.SetEACLTable(eacl.NewTable())
|
||||
require.NoError(t, bearerToken.SignToken(key))
|
||||
require.Equal(t, bearerToken.Issuer().String(), ownerID.String())
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue