Private
Public Access
actualizado tema tokens
This commit is contained in:
1 parent
38afdcc742
commit
441e2f5833
28 files changed
+506
-194
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package jwtutils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTokenRoundTrip(t *testing.T) {
|
||||
os.Setenv("JWTString", "test-secret")
|
||||
t.Cleanup(func() { os.Unsetenv("JWTString") })
|
||||
|
||||
token, err := GenerarToken(7, "a@b.c", "Nombre", TokenTypeAccess, []uint{1, 2, 4}, time.Minute)
|
||||
if err != nil {
|
||||
t.Fatalf("generar token: %v", err)
|
||||
}
|
||||
|
||||
claims, err := ValidarTokenDeTipo(token, TokenTypeAccess)
|
||||
if err != nil {
|
||||
t.Fatalf("validar token: %v", err)
|
||||
}
|
||||
|
||||
if id, ok := ClaimUint(claims, ClaimSubject); !ok || id != 7 {
|
||||
t.Fatalf("sub esperado 7, obtenido %v (%v)", id, ok)
|
||||
}
|
||||
|
||||
if got := PermisosDesdeClaims(claims); !reflect.DeepEqual(got, []uint{1, 2, 4}) {
|
||||
t.Fatalf("permisos esperados [1 2 4], obtenidos %v", got)
|
||||
}
|
||||
|
||||
if _, err := ValidarTokenDeTipo(token, TokenTypeRefresh); err == nil {
|
||||
t.Fatal("un access token no deberia validar como refresh")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user