moved sync out of JWT and added new secret reader
This commit is contained in:
parent
4c14116a41
commit
9b4adfe863
3 changed files with 82 additions and 33 deletions
29
jwt_test.go
29
jwt_test.go
|
|
@ -3,20 +3,24 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
jwt := New(time.Second, NewMapBlacklist())
|
||||
jwt, err := New(time.Second, NewMemBlacklist(), nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
token := NewToken(map[string]interface{}{
|
||||
"sub": "1234567890",
|
||||
"name": "John Doe",
|
||||
"admin": true,
|
||||
"fizz": "buzz",
|
||||
}, nil)
|
||||
err := jwt.Sign(token)
|
||||
err = jwt.Sign(token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -57,14 +61,17 @@ func TestValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNoBlacklist(t *testing.T) {
|
||||
jwt := New(time.Second, nil)
|
||||
jwt, err := New(time.Second, nil, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
token := NewToken(map[string]interface{}{
|
||||
"sub": "1234567890",
|
||||
"name": "John Doe",
|
||||
"admin": true,
|
||||
"fizz": "buzz",
|
||||
}, nil)
|
||||
err := jwt.Sign(token)
|
||||
err = jwt.Sign(token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -91,3 +98,17 @@ func TestNoBlacklist(t *testing.T) {
|
|||
t.Error(errors.New("blacklisting should be disabled"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptySecretReader(t *testing.T) {
|
||||
_, err := New(time.Second, nil, new(bytes.Buffer))
|
||||
if err == nil {
|
||||
t.Error(errors.New("error should be secret reader error"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidSecretReader(t *testing.T) {
|
||||
_, err := New(time.Second, nil, bytes.NewBufferString("123"))
|
||||
if err != ErrInvalidKeySize {
|
||||
t.Error(errors.New("error should be invalid key size"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue