package middleware import ( "net/http" "net/http/httptest" "testing" "github.com/gin-gonic/gin" ) func TestCORSWildcardOriginAllowsProductionPreflight(t *testing.T) { gin.SetMode(gin.TestMode) router := gin.New() router.Use(CORS([]string{"*"}, false)) router.GET("/emby/System/Info/Public", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"ok": true}) }) req := httptest.NewRequest(http.MethodOptions, "/emby/System/Info/Public", nil) req.Header.Set("Origin", "http://senplayer.local") req.Header.Set("Access-Control-Request-Method", "POST") w := httptest.NewRecorder() router.ServeHTTP(w, req) if w.Code != http.StatusNoContent { t.Fatalf("status = %d, want 204", w.Code) } if got := w.Header().Get("Access-Control-Allow-Origin"); got != "*" { t.Fatalf("Access-Control-Allow-Origin = %q, want *", got) } }