forked from TrueCloudLab/frostfs-api-go
[#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:
parent
05e74d56db
commit
fb0b1ea108
2 changed files with 36 additions and 0 deletions
|
@ -11,6 +11,8 @@ import (
|
|||
)
|
||||
|
||||
// Generate returns random session.Token.
|
||||
//
|
||||
// Resulting token is unsigned.
|
||||
func Generate() *session.Token {
|
||||
tok := session.NewToken()
|
||||
|
||||
|
@ -33,3 +35,17 @@ func Generate() *session.Token {
|
|||
|
||||
return tok
|
||||
}
|
||||
|
||||
// GenerateSigned returns signed random session.Token.
|
||||
//
|
||||
// Panics if token could not be signed (actually unexpected).
|
||||
func GenerateSigned() *session.Token {
|
||||
tok := Generate()
|
||||
|
||||
err := tok.Sign(test.DecodeKey(0))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return tok
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue