1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 12:57:05 +00:00

jwt: add more helpers (DefaultRSA and DefaultHMAC)

Former-commit-id: fe06c0e0f4d7e121c678ffda7ac702ae865abd00
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-05-31 17:57:30 +03:00
parent cbe336a583
commit b2fddc7d68
7 changed files with 280 additions and 161 deletions

View File

@@ -2,6 +2,7 @@
package jwt_test
import (
"os"
"testing"
"time"
@@ -18,12 +19,21 @@ type userClaims struct {
const testMaxAge = 3 * time.Second
// Random RSA verification and encryption.
func TestRSA(t *testing.T) {
j := jwt.Random(testMaxAge)
func TestDefaultRSA(t *testing.T) {
j := jwt.DefaultRSA(testMaxAge)
t.Cleanup(func() {
os.Remove(jwt.SignFilename)
os.Remove(jwt.EncFilename)
})
testWriteVerifyToken(t, j)
}
// HMAC verification and encryption.
func TestDefaultHMAC(t *testing.T) {
j := jwt.DefaultHMAC(testMaxAge, "secret", "itsa16bytesecret")
testWriteVerifyToken(t, j)
}
func TestHMAC(t *testing.T) {
j, err := jwt.New(testMaxAge, jwt.HS256, []byte("secret"))
if err != nil {