frostfs-api-go/pkg/session/test/token.go
Leonard Lyubich 37b415347d [#283] pkg/token: Replace SessionToken into a session package
There is a need to add session token to `eacl.Table` structure. To do this,
we need to replace `token.SessionToken` type to another package since `eacl`
package imports `token` one (potential cross-import).

Create `pkg/session` package and replace session token implementation to it.
Related API in `container` package is deprecated from now.

Additionally implement test generator of random session tokens.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00

35 lines
685 B
Go

package sessiontest
import (
"math/rand"
"github.com/google/uuid"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/session"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test"
)
// Generate returns random session.Token.
func Generate() *session.Token {
tok := session.NewToken()
uid, err := uuid.New().MarshalBinary()
if err != nil {
panic(err)
}
w := new(owner.NEO3Wallet)
rand.Read(w.Bytes())
ownerID := owner.NewID()
ownerID.SetNeo3Wallet(w)
keyBin := crypto.MarshalPublicKey(&test.DecodeKey(0).PublicKey)
tok.SetID(uid)
tok.SetOwnerID(ownerID)
tok.SetSessionKey(keyBin)
return tok
}