From 84d0919fb3f0ce36efd0b936ec8186d9354c121d Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 10 Mar 2024 15:29:23 +0800 Subject: [PATCH] test: refactor CORS tests and expand coverage - Add a new test function `TestDefaultConfig` to verify default configuration behavior in CORS tests Signed-off-by: Bo-Yi Wu --- cors_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cors_test.go b/cors_test.go index 1ff9737..05bfeee 100644 --- a/cors_test.go +++ b/cors_test.go @@ -314,6 +314,17 @@ func TestValidateTauri(t *testing.T) { assert.Nil(t, c.Validate()) } +func TestDefaultConfig(t *testing.T) { + config := DefaultConfig() + config.AllowAllOrigins = true + router := newTestRouter(config) + w := performRequest(router, "GET", "http://google.com") + assert.Equal(t, "get", w.Body.String()) + assert.Equal(t, "*", w.Header().Get("Access-Control-Allow-Origin")) + assert.Empty(t, w.Header().Get("Access-Control-Allow-Credentials")) + assert.Empty(t, w.Header().Get("Access-Control-Expose-Headers")) +} + func TestPassesAllowOrigins(t *testing.T) { router := newTestRouter(Config{ AllowOrigins: []string{"http://google.com"},