session: support the expiration of private tokens

All sessions in NeoFS has limited in epochs lifetime. There is a need
to limit the lifetime of private session tokens.

This commmit:

  * extends PrivateToken interface with Expired method;

  * defines EpochLifetimeStore interface with RemoveExpired method
    and embeds it to PrivateTokenStore interface;

  * adds epoch value parameter to private token constructor.
This commit is contained in:
Leonard Lyubich 2020-04-29 14:11:19 +03:00
parent 8cbdb9183f
commit 4fa7360cd1
5 changed files with 116 additions and 4 deletions

View file

@ -10,7 +10,7 @@ import (
func TestPrivateToken(t *testing.T) {
// create new private token
pToken, err := NewPrivateToken()
pToken, err := NewPrivateToken(0)
require.NoError(t, err)
// generate data to sign
@ -31,3 +31,20 @@ func TestPrivateToken(t *testing.T) {
),
)
}
func TestPToken_Expired(t *testing.T) {
e := uint64(10)
var token PrivateToken = &pToken{
validUntil: e,
}
// must not be expired in the epoch before last
require.False(t, token.Expired(e-1))
// must not be expired in the last epoch
require.False(t, token.Expired(e))
// must be expired in the epoch after last
require.True(t, token.Expired(e+1))
}