[#302] pkg/token: Document default values set in NewBearerToken

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 20:58:10 +03:00 committed by Alex Vanin
parent 00a0ea42a8
commit 245271bb65
2 changed files with 26 additions and 0 deletions

View file

@ -99,6 +99,15 @@ func (b *BearerToken) Issuer() *owner.ID {
return owner.NewIDFromNeo3Wallet(wallet) 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 { func NewBearerToken() *BearerToken {
b := new(BearerToken) b := new(BearerToken)
b.token = acl.BearerToken{} b.token = acl.BearerToken{}

View file

@ -63,3 +63,20 @@ func TestBearerToken_ToV2(t *testing.T) {
require.Nil(t, x.ToV2()) 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())
})
}