2021-11-08 14:14:14 +00:00
|
|
|
package tokentest
|
|
|
|
|
|
|
|
import (
|
2021-11-22 12:38:15 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
|
|
|
"crypto/rand"
|
|
|
|
|
2021-11-08 14:14:14 +00:00
|
|
|
eacltest "github.com/nspcc-dev/neofs-sdk-go/eacl/test"
|
|
|
|
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/token"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Generate returns random token.BearerToken.
|
|
|
|
//
|
|
|
|
// Resulting token is unsigned.
|
|
|
|
func Generate() *token.BearerToken {
|
|
|
|
x := token.NewBearerToken()
|
|
|
|
|
|
|
|
x.SetLifetime(3, 2, 1)
|
|
|
|
x.SetOwner(ownertest.GenerateID())
|
|
|
|
x.SetEACLTable(eacltest.Table())
|
|
|
|
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenerateSigned returns signed random token.BearerToken.
|
|
|
|
//
|
|
|
|
// Panics if token could not be signed (actually unexpected).
|
|
|
|
func GenerateSigned() *token.BearerToken {
|
|
|
|
tok := Generate()
|
|
|
|
|
2021-11-22 12:38:15 +00:00
|
|
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
2021-11-08 14:14:14 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-22 12:38:15 +00:00
|
|
|
err = tok.SignToken(p)
|
2021-11-08 14:14:14 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tok
|
|
|
|
}
|