diff options
Diffstat (limited to 'lib/paseto/v2/json_token_test.go')
| -rw-r--r-- | lib/paseto/v2/json_token_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/paseto/v2/json_token_test.go b/lib/paseto/v2/json_token_test.go new file mode 100644 index 00000000..5081ebf4 --- /dev/null +++ b/lib/paseto/v2/json_token_test.go @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020 Shulhan <ms@kilabit.info> + +package pasetov2 + +import ( + "fmt" + "testing" + "time" + + "git.sr.ht/~shulhan/pakakeh.go/lib/test" +) + +func TestJSONToken_Validate(t *testing.T) { + now := time.Now().Round(time.Second) + peer := Key{} + + issued1sAgo := now.Add(-1 * time.Second) + issued6sAgo := now.Add(-6 * time.Second) + + cases := []struct { + desc string + jtoken *JSONToken + expErr string + }{{ + desc: "With IssuedAt less than current time", + jtoken: &JSONToken{ + IssuedAt: &issued1sAgo, + }, + }, { + desc: "With IssuedAt greater than drift", + jtoken: &JSONToken{ + IssuedAt: &issued6sAgo, + }, + expErr: fmt.Sprintf("token issued at %s before current time %s", + issued6sAgo, now), + }} + + for _, c := range cases { + var gotErr string + + err := c.jtoken.Validate("", peer) + if err != nil { + gotErr = err.Error() + } + + test.Assert(t, c.desc, c.expErr, gotErr) + } +} |
