Commit graph

7 commits

Author SHA1 Message Date
Pavel Karpy
fb77bd3511 [#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>
2021-06-09 17:23:35 +03:00
Pavel Karpy
707776976a [#302] pkg/session: Convert nil Token to nil message
Document that `Token.ToV2` method return `nil`
when called on `nil`. Document that `NewTokenFromV2`
function return `nil` when called on `nil`. Write
corresponding unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-06-09 17:23:35 +03:00
Leonard Lyubich
779a61c97d [#298] pkg/session: Implement methods to work with Token lifetime
Implement `Exp`/`SetExp`/`Nbf`/`SetNbf`/`Iat`/`SetIat` methods on `Token`
type which provide access to the message fields of the same name.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-07 13:26:59 +03:00
Leonard Lyubich
65080c8b69 [#295] pkg: Remove usage of deprecated elements
Remove usage of deprecated of `container.ID` and `token.SessionToken` code
elements. Replace using of custom message generators with the ones provided
by packages. Replace string comparison with `Equal` method call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-01 08:04:12 +03:00
Leonard Lyubich
6cd3497388 [#283] pkg/session: Implement work with token contexts
Implement `Context` / `SetContext` methods on `Token` which reads / sets
token context. Support container context (`ContainerContext`).

Add helper function `GetContainerContext` for easy reading of the container
context.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
fb0b1ea108 [#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>
2021-05-28 16:32:02 +03:00
Leonard Lyubich
37b415347d [#283] pkg/token: Replace SessionToken into a session package
There is a need to add session token to `eacl.Table` structure. To do this,
we need to replace `token.SessionToken` type to another package since `eacl`
package imports `token` one (potential cross-import).

Create `pkg/session` package and replace session token implementation to it.
Related API in `container` package is deprecated from now.

Additionally implement test generator of random session tokens.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00