Fix tests

This commit is contained in:
Pavindu Lakshan 2025-08-12 07:58:34 +05:30
parent c38e27b097
commit eb72be0aab

View file

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings"
"testing" "testing"
"time" "time"
@ -47,7 +48,14 @@ func TestValidateJWT(t *testing.T) {
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
err := ValidateJWT(tc.authHeader) var accessToken string
parts := strings.Split(tc.authHeader, "Bearer ")
if len(parts) == 2 {
accessToken = parts[1]
} else {
accessToken = ""
}
err := ValidateJWT(true, accessToken, "test-audience")
if tc.expectError && err == nil { if tc.expectError && err == nil {
t.Errorf("Expected error but got none") t.Errorf("Expected error but got none")
} }
@ -128,6 +136,7 @@ func createValidJWT(t *testing.T) string {
token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{ token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
"sub": "1234567890", "sub": "1234567890",
"name": "Test User", "name": "Test User",
"aud": "test-audience",
"iat": time.Now().Unix(), "iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(), "exp": time.Now().Add(time.Hour).Unix(),
}) })