frostfs-api-go/pkg/token/test/generate.go
Leonard Lyubich 00778cc9ba [#293] pkg/token: Implement and use generator of BearerToken
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-08 18:59:15 +03:00

35 lines
776 B
Go

package tokentest
import (
eacltest "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl/test"
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-crypto/test"
)
// Generate returns random token.BearerToken.
//
// Resulting token is unsigned.
func Generate() *token.BearerToken {
x := token.NewBearerToken()
x.SetLifetime(3, 2, 1)
x.SetOwner(ownertest.Generate())
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()
err := tok.SignToken(test.DecodeKey(0))
if err != nil {
panic(err)
}
return tok
}