forked from TrueCloudLab/frostfs-api-go
[#302] pkg/session: Document default values set in NewToken
Document field values of instance constructed via `NewToken`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
707776976a
commit
fb77bd3511
2 changed files with 30 additions and 0 deletions
|
@ -24,6 +24,15 @@ func NewTokenFromV2(tV2 *session.SessionToken) *Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewToken creates and returns blank Token.
|
// NewToken creates and returns blank Token.
|
||||||
|
//
|
||||||
|
// Defaults:
|
||||||
|
// - body: nil;
|
||||||
|
// - id: nil;
|
||||||
|
// - ownerId: nil;
|
||||||
|
// - sessionKey: nil;
|
||||||
|
// - exp: 0;
|
||||||
|
// - iat: 0;
|
||||||
|
// - nbf: 0;
|
||||||
func NewToken() *Token {
|
func NewToken() *Token {
|
||||||
return NewTokenFromV2(new(session.SessionToken))
|
return NewTokenFromV2(new(session.SessionToken))
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,3 +179,24 @@ func TestToken_ToV2(t *testing.T) {
|
||||||
require.Nil(t, x.ToV2())
|
require.Nil(t, x.ToV2())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewToken(t *testing.T) {
|
||||||
|
t.Run("default values", func(t *testing.T) {
|
||||||
|
token := session.NewToken()
|
||||||
|
|
||||||
|
// check initial values
|
||||||
|
require.Nil(t, token.Signature())
|
||||||
|
require.Nil(t, token.OwnerID())
|
||||||
|
require.Nil(t, token.SessionKey())
|
||||||
|
require.Nil(t, token.ID())
|
||||||
|
require.Zero(t, token.Exp())
|
||||||
|
require.Zero(t, token.Iat())
|
||||||
|
require.Zero(t, token.Nbf())
|
||||||
|
|
||||||
|
// convert to v2 message
|
||||||
|
tokenV2 := token.ToV2()
|
||||||
|
|
||||||
|
require.Nil(t, tokenV2.GetSignature())
|
||||||
|
require.Nil(t, tokenV2.GetBody())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue