Files
chirpy/internal/auth/auth_test.go
T

29 lines
618 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)
if err != nil {
t.Fatalf("failed to create JWT: %v", err)
}
validatedUserId, err := auth.ValidateJWT(jwtString, secret)
if err != nil {
t.Fatalf("failed to validate JWT: %v", err)
}
if userId != validatedUserId {
t.Fatalf("received %s expected %s", validatedUserId, userId)
}
}