22 lines
496 B
Go
22 lines
496 B
Go
package auth_test
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/StevanFreeborn/chirpy/internal/auth"
|
||
|
|
"github.com/google/uuid"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestJwtCreationAndValidation(t *testing.T) {
|
||
|
|
userId := uuid.New()
|
||
|
|
secret := []byte("RTCK2UTcOUkiswdrClC6Z3KmmEq/+QicpD9iRx7J0qY=")
|
||
|
|
|
||
|
|
jwtString, err := auth.MakeJWT(userId, secret, time.Hour)
|
||
|
|
validatedUserId, err := auth.ValidateJWT(jwtString, secret)
|
||
|
|
|
||
|
|
if userId != validatedUserId {
|
||
|
|
t.Fatalf("received %s expected %s: %v", validatedUserId, userId, err)
|
||
|
|
}
|
||
|
|
}
|