feat: simplify SOP to immediate-effect configuration
This commit is contained in:
@@ -30,3 +30,34 @@ func TestRequestLoggerUsesStatusLevelAndDurationMilliseconds(t *testing.T) {
|
||||
t.Fatalf("duration_ms is missing from request log")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCORSAllowsAllOriginsAndAnswersPreflight(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
router := gin.New()
|
||||
router.Use(CORS())
|
||||
router.GET("/ping", func(c *gin.Context) { c.Status(http.StatusOK) })
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/ping", nil)
|
||||
req.Header.Set("Origin", "https://crm.example.com")
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, req)
|
||||
|
||||
if got := rec.Header().Get("Access-Control-Allow-Origin"); got != "*" {
|
||||
t.Fatalf("Access-Control-Allow-Origin = %q, want *", got)
|
||||
}
|
||||
if got := rec.Header().Get("Access-Control-Allow-Headers"); got != "*" {
|
||||
t.Fatalf("Access-Control-Allow-Headers = %q, want *", got)
|
||||
}
|
||||
|
||||
preflight := httptest.NewRequest(http.MethodOptions, "/ping", nil)
|
||||
preflight.Header.Set("Origin", "https://crm.example.com")
|
||||
preflightRec := httptest.NewRecorder()
|
||||
router.ServeHTTP(preflightRec, preflight)
|
||||
|
||||
if preflightRec.Code != http.StatusNoContent {
|
||||
t.Fatalf("preflight status = %d, want %d", preflightRec.Code, http.StatusNoContent)
|
||||
}
|
||||
if got := preflightRec.Header().Get("Access-Control-Allow-Origin"); got != "*" {
|
||||
t.Fatalf("preflight Access-Control-Allow-Origin = %q, want *", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user