1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-27 22:38:25 +02:00

CORS middleware should compile allowOrigin regexp at creation.

This commit is contained in:
toimtoimtoim
2024-11-21 21:53:07 +02:00
committed by Martti T.
parent a973e3bc43
commit 118c1632f2
3 changed files with 29 additions and 5 deletions

View File

@@ -31,6 +31,18 @@ func TestCORS(t *testing.T) {
name: "ok, wildcard AllowedOrigin with no Origin header in request",
notExpectHeaders: map[string]string{echo.HeaderAccessControlAllowOrigin: ""},
},
{
name: "ok, invalid pattern is ignored",
givenMW: CORSWithConfig(CORSConfig{
AllowOrigins: []string{
"\xff", // Invalid UTF-8 makes regexp.Compile to error
"*.example.com",
},
}),
whenMethod: http.MethodOptions,
whenHeaders: map[string]string{echo.HeaderOrigin: "http://aaa.example.com"},
expectHeaders: map[string]string{echo.HeaderAccessControlAllowOrigin: "http://aaa.example.com"},
},
{
name: "ok, specific AllowOrigins and AllowCredentials",
givenMW: CORSWithConfig(CORSConfig{