fix regex error sonarqube

This commit is contained in:
2025-12-17 16:52:27 +08:00
parent c4c03163ea
commit 219112a84c
+16 -16
View File
@@ -273,7 +273,7 @@ func TestGetRole(t *testing.T) {
}
}
func TestJWTAuth_NoAuthHeader(t *testing.T) {
func TestJWTAuthNoAuthHeader(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
@@ -288,7 +288,7 @@ func TestJWTAuth_NoAuthHeader(t *testing.T) {
}
}
func TestJWTAuth_InvalidToken(t *testing.T) {
func TestJWTAuthInvalidToken(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret-key")
jwtSecretOnce = sync.Once{}
jwtSecretError = nil
@@ -309,7 +309,7 @@ func TestJWTAuth_InvalidToken(t *testing.T) {
}
}
func TestJWTAuth_ValidToken(t *testing.T) {
func TestJWTAuthValidToken(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret-key")
jwtSecretOnce = sync.Once{}
jwtSecretError = nil
@@ -348,7 +348,7 @@ func TestJWTAuth_ValidToken(t *testing.T) {
// Additional comprehensive test cases
func TestExtractBearerToken_EdgeCases(t *testing.T) {
func TestExtractBearerTokenEdgeCases(t *testing.T) {
testCases := []struct {
name string
header string
@@ -374,7 +374,7 @@ func TestExtractBearerToken_EdgeCases(t *testing.T) {
}
}
func TestParseAndValidateToken_MalformedTokens(t *testing.T) {
func TestParseAndValidateTokenMalformedTokens(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret")
defer os.Unsetenv("JWT_KEY")
@@ -405,7 +405,7 @@ func TestParseAndValidateToken_MalformedTokens(t *testing.T) {
}
}
func TestBuildContext_WithDifferentRoles(t *testing.T) {
func TestBuildContextWithDifferentRoles(t *testing.T) {
roles := []string{"admin", "user", "guest", "superadmin", "", "role-with-dash"}
for _, role := range roles {
@@ -431,7 +431,7 @@ func TestBuildContext_WithDifferentRoles(t *testing.T) {
}
}
func TestGetClaims_WithoutClaims(t *testing.T) {
func TestGetClaimsWithoutClaims(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
claims, ok := GetClaims(req)
@@ -443,7 +443,7 @@ func TestGetClaims_WithoutClaims(t *testing.T) {
}
}
func TestGetClaims_WithWrongType(t *testing.T) {
func TestGetClaimsWithWrongType(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
ctx := context.WithValue(req.Context(), models.ContextKey("claims"), "wrong type")
req = req.WithContext(ctx)
@@ -457,7 +457,7 @@ func TestGetClaims_WithWrongType(t *testing.T) {
}
}
func TestGetUserID_WithNoClaims(t *testing.T) {
func TestGetUserIDWithNoClaims(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
userID, ok := GetUserID(req)
@@ -469,7 +469,7 @@ func TestGetUserID_WithNoClaims(t *testing.T) {
}
}
func TestGetUsername_WithNoClaims(t *testing.T) {
func TestGetUsernameWithNoClaims(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
username, ok := GetUsername(req)
@@ -481,7 +481,7 @@ func TestGetUsername_WithNoClaims(t *testing.T) {
}
}
func TestGetRole_WithNoClaims(t *testing.T) {
func TestGetRoleWithNoClaims(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
role, ok := GetRole(req)
@@ -493,7 +493,7 @@ func TestGetRole_WithNoClaims(t *testing.T) {
}
}
func TestJWTAuth_MissingBearerPrefix(t *testing.T) {
func TestJWTAuthMissingBearerPrefix(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret")
defer os.Unsetenv("JWT_KEY")
@@ -516,7 +516,7 @@ func TestJWTAuth_MissingBearerPrefix(t *testing.T) {
}
}
func TestJWTAuth_ExpiredToken(t *testing.T) {
func TestJWTAuthExpiredToken(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret")
defer os.Unsetenv("JWT_KEY")
@@ -552,7 +552,7 @@ func TestJWTAuth_ExpiredToken(t *testing.T) {
}
}
func TestJWTAuth_TokenWithMissingClaims(t *testing.T) {
func TestJWTAuthTokenWithMissingClaims(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret")
defer os.Unsetenv("JWT_KEY")
@@ -625,7 +625,7 @@ func TestJWTAuth_TokenWithMissingClaims(t *testing.T) {
}
}
func TestJWTAuth_ConcurrentRequests(t *testing.T) {
func TestJWTAuthConcurrentRequests(t *testing.T) {
os.Setenv("JWT_KEY", "test-secret")
defer os.Unsetenv("JWT_KEY")
@@ -675,7 +675,7 @@ func TestJWTAuth_ConcurrentRequests(t *testing.T) {
}
}
func TestJWTAuth_TokenSignedWithWrongKey(t *testing.T) {
func TestJWTAuthTokenSignedWithWrongKey(t *testing.T) {
os.Setenv("JWT_KEY", "correct-secret")
defer os.Unsetenv("JWT_KEY")