2020-10-22 09:18:07 +00:00
|
|
|
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"
|
2021-06-08 11:39:17 +00:00
|
|
|
tokentest "github.com/nspcc-dev/neofs-api-go/pkg/token/test"
|
2020-10-22 09:18:07 +00:00
|
|
|
"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))
|
2021-05-31 12:09:04 +00:00
|
|
|
require.True(t, ownerID.Equal(bearerToken.Issuer()))
|
2020-10-22 09:18:07 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-13 12:08:37 +00:00
|
|
|
|
|
|
|
func TestFilterEncoding(t *testing.T) {
|
2021-06-08 11:39:17 +00:00
|
|
|
f := tokentest.Generate()
|
2020-11-13 12:08:37 +00:00
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := f.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
f2 := token.NewBearerToken()
|
|
|
|
require.NoError(t, f2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, f, f2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := f.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
d2 := token.NewBearerToken()
|
|
|
|
require.NoError(t, d2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, f, d2)
|
|
|
|
})
|
|
|
|
}
|
2021-06-08 17:52:46 +00:00
|
|
|
|
|
|
|
func TestBearerToken_ToV2(t *testing.T) {
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
var x *token.BearerToken
|
|
|
|
|
|
|
|
require.Nil(t, x.ToV2())
|
|
|
|
})
|
|
|
|
}
|