mjwt/auth/refresh-token_test.go

27 lines
610 B
Go
Raw Normal View History

package auth
import (
"crypto/rand"
"crypto/rsa"
2023-10-29 12:28:21 +00:00
"github.com/1f349/mjwt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreateRefreshToken(t *testing.T) {
2023-10-29 12:28:21 +00:00
t.Parallel()
key, err := rsa.GenerateKey(rand.Reader, 2048)
assert.NoError(t, err)
s := mjwt.NewMJwtSigner("mjwt.test", key)
refreshToken, err := CreateRefreshToken(s, "1", "test", "test2", nil)
assert.NoError(t, err)
_, b, err := mjwt.ExtractClaims[RefreshTokenClaims](s, refreshToken)
assert.NoError(t, err)
assert.Equal(t, "1", b.Subject)
assert.Equal(t, "test", b.ID)
assert.Equal(t, "test2", b.Claims.AccessTokenId)
}