diff --git a/pkg/token/bearer.go b/pkg/token/bearer.go index 8ac333e4..621052cb 100644 --- a/pkg/token/bearer.go +++ b/pkg/token/bearer.go @@ -99,6 +99,15 @@ func (b *BearerToken) Issuer() *owner.ID { return owner.NewIDFromNeo3Wallet(wallet) } +// NewBearerToken creates and initializes blank BearerToken. +// +// Defaults: +// - signature: nil; +// - eacl: nil; +// - ownerID: nil; +// - exp: 0; +// - nbf: 0; +// - iat: 0. func NewBearerToken() *BearerToken { b := new(BearerToken) b.token = acl.BearerToken{} diff --git a/pkg/token/bearer_test.go b/pkg/token/bearer_test.go index 26dca9e5..191398b1 100644 --- a/pkg/token/bearer_test.go +++ b/pkg/token/bearer_test.go @@ -63,3 +63,20 @@ func TestBearerToken_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewBearerToken(t *testing.T) { + t.Run("default values", func(t *testing.T) { + tkn := token.NewBearerToken() + + // convert to v2 message + tknV2 := tkn.ToV2() + + require.NotNil(t, tknV2.GetBody()) + require.Zero(t, tknV2.GetBody().GetLifetime().GetExp()) + require.Zero(t, tknV2.GetBody().GetLifetime().GetNbf()) + require.Zero(t, tknV2.GetBody().GetLifetime().GetIat()) + require.Nil(t, tknV2.GetBody().GetEACL()) + require.Nil(t, tknV2.GetBody().GetOwnerID()) + require.Nil(t, tknV2.GetSignature()) + }) +}