From 245271bb6572e423b935af6e4686ca11ead2fff3 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 20:58:10 +0300 Subject: [PATCH] [#302] pkg/token: Document default values set in `NewBearerToken` Signed-off-by: Pavel Karpy --- pkg/token/bearer.go | 9 +++++++++ pkg/token/bearer_test.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) 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()) + }) +}