File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cors
22
33import (
4+ "bytes"
45 "net/http/httptest"
6+ "os"
57 "strings"
68 "testing"
79
810 "github.com/gofiber/fiber/v3"
11+ "github.com/gofiber/fiber/v3/log"
912 "github.com/stretchr/testify/require"
1013 "github.com/valyala/fasthttp"
1114)
@@ -261,6 +264,21 @@ func Test_CORS_Wildcard_AllowCredentials_Panic(t *testing.T) {
261264 }
262265}
263266
267+ // Test that a warning is logged when AllowOrigins allows all origins and
268+ // AllowOriginsFunc is also provided.
269+ func Test_CORS_Warn_AllowAllOrigins_WithFunc (t * testing.T ) {
270+ var buf bytes.Buffer
271+ log .SetOutput (& buf )
272+ t .Cleanup (func () { log .SetOutput (os .Stderr ) })
273+
274+ fiber .New ().Use (New (Config {
275+ AllowOrigins : []string {"*" },
276+ AllowOriginsFunc : func (string ) bool { return true },
277+ }))
278+
279+ require .Contains (t , buf .String (), "AllowOriginsFunc' will not be used" )
280+ }
281+
264282// go test -run -v Test_CORS_Invalid_Origin_Panic
265283func Test_CORS_Invalid_Origins_Panic (t * testing.T ) {
266284 t .Parallel ()
You can’t perform that action at this time.
0 commit comments