[#283] pkg/session: Cover Token's Sign/Verify methods with unit test

Add `sessiontest.GenerateSigned` function which returns signed random token.
Clarify that `sessiontest.Generate` returns an unsigned token. Use these
functions to assert the correctness of `Sign` / `VerifySignature` methods.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-28 11:00:46 +03:00 committed by Leonard Lyubich
parent 05e74d56db
commit fb0b1ea108
2 changed files with 36 additions and 0 deletions

View file

@ -66,3 +66,23 @@ func TestSessionTokenEncoding(t *testing.T) {
require.Equal(t, tok, tok2)
})
}
func TestToken_VerifySignature(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var tok *session.Token
require.False(t, tok.VerifySignature())
})
t.Run("unsigned", func(t *testing.T) {
tok := sessiontest.Generate()
require.False(t, tok.VerifySignature())
})
t.Run("signed", func(t *testing.T) {
tok := sessiontest.GenerateSigned()
require.True(t, tok.VerifySignature())
})
}