diff --git a/pkg/token/bearer_test.go b/pkg/token/bearer_test.go index afcde5a7..38bf47b1 100644 --- a/pkg/token/bearer_test.go +++ b/pkg/token/bearer_test.go @@ -6,6 +6,7 @@ import ( "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" + tokentest "github.com/nspcc-dev/neofs-api-go/pkg/token/test" "github.com/nspcc-dev/neofs-crypto/test" "github.com/stretchr/testify/require" ) @@ -32,8 +33,7 @@ func TestBearerToken_Issuer(t *testing.T) { } func TestFilterEncoding(t *testing.T) { - f := token.NewBearerToken() - f.SetLifetime(1, 2, 3) + f := tokentest.Generate() t.Run("binary", func(t *testing.T) { data, err := f.Marshal() diff --git a/pkg/token/test/generate.go b/pkg/token/test/generate.go new file mode 100644 index 00000000..f7ae59d4 --- /dev/null +++ b/pkg/token/test/generate.go @@ -0,0 +1,35 @@ +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 +}