-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
session: Provide getters of lifetime claims
Previously they could not be obtained directly. It's natural need to get what was set, e.g. in unit tests, logging, etc. So, it's better to provide way to receive such an open info. Signed-off-by: Leonard Lyubich <[email protected]>
- Loading branch information
1 parent
a236057
commit b9b920d
Showing
4 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package session_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nspcc-dev/neofs-sdk-go/session" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func testLifetimeClaim[T session.Container | session.Object](t testing.TB, get func(T) uint64, set func(*T, uint64)) { | ||
var x T | ||
require.Zero(t, get(x)) | ||
set(&x, 12094032) | ||
require.EqualValues(t, 12094032, get(x)) | ||
set(&x, 5469830342) | ||
require.EqualValues(t, 5469830342, get(x)) | ||
} | ||
|
||
type lifetime interface { | ||
SetExp(uint64) | ||
SetIat(uint64) | ||
SetNbf(uint64) | ||
InvalidAt(uint64) bool | ||
} | ||
|
||
func testInvalidAt(t testing.TB, x lifetime) { | ||
require.False(t, x.InvalidAt(0)) | ||
|
||
const iat = 13 | ||
const nbf = iat + 1 | ||
const exp = nbf + 1 | ||
|
||
x.SetIat(iat) | ||
x.SetNbf(nbf) | ||
x.SetExp(exp) | ||
|
||
require.True(t, x.InvalidAt(iat-1)) | ||
require.True(t, x.InvalidAt(iat)) | ||
require.False(t, x.InvalidAt(nbf)) | ||
require.False(t, x.InvalidAt(exp)) | ||
require.True(t, x.InvalidAt(exp+1)) | ||
} | ||
|
||
func TestInvalidAt(t *testing.T) { | ||
testInvalidAt(t, new(session.Container)) | ||
testInvalidAt(t, new(session.Object)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters