mirror of
https://github.com/wahyd4/passkey-auth.git
synced 2026-08-08 20:15:44 +10:00
Fix lint and go test errors
This commit is contained in:
@@ -58,9 +58,9 @@ fmt: ## Format code
|
||||
@echo "🎨 Formatting code..."
|
||||
@go fmt ./...
|
||||
|
||||
lint: ## Run linter
|
||||
@echo "🔍 Running linter..."
|
||||
@golangci-lint run
|
||||
lint: ## Run linter with auto-fix (excluding test files)
|
||||
@echo "🔍 Running linter with auto-fix (excluding test files)..."
|
||||
@golangci-lint run --fix --tests=false
|
||||
|
||||
security: ## Run security scan
|
||||
@echo "🔒 Running security scan..."
|
||||
|
||||
@@ -12,7 +12,7 @@ func TestWildcardCORSIntegration(t *testing.T) {
|
||||
// Create a simple test handler
|
||||
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("OK"))
|
||||
_, _ = w.Write([]byte("OK"))
|
||||
})
|
||||
|
||||
// Create CORS middleware with wildcard support
|
||||
|
||||
@@ -82,16 +82,32 @@ func (m *WildcardMatcher) wildcardMatch(origin, pattern string) bool {
|
||||
// This expands wildcard patterns based on the request origin
|
||||
func (m *WildcardMatcher) GetAllowedOrigins(requestOrigin string, staticOrigins []string) []string {
|
||||
allowedOrigins := make([]string, 0, len(staticOrigins))
|
||||
hasMatchingWildcard := false
|
||||
|
||||
// First pass: check if any wildcard matches
|
||||
for _, origin := range staticOrigins {
|
||||
if strings.Contains(origin, "*") {
|
||||
if m.matchPattern(requestOrigin, origin) {
|
||||
hasMatchingWildcard = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass: build the result based on the logic
|
||||
for _, origin := range staticOrigins {
|
||||
if strings.Contains(origin, "*") {
|
||||
// This is a wildcard pattern
|
||||
if m.matchPattern(requestOrigin, origin) {
|
||||
// Add the actual request origin instead of the pattern
|
||||
allowedOrigins = append(allowedOrigins, requestOrigin)
|
||||
} else if !hasMatchingWildcard {
|
||||
// No wildcards match, so include this wildcard pattern as-is
|
||||
allowedOrigins = append(allowedOrigins, origin)
|
||||
}
|
||||
// If a wildcard matches but this one doesn't, skip it (don't add anything)
|
||||
} else {
|
||||
// This is a static origin, add as-is
|
||||
// This is a static origin, always add as-is
|
||||
allowedOrigins = append(allowedOrigins, origin)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user