@@ -60,6 +60,59 @@ func TestCORS(t *testing.T) {
6060 echo .HeaderAccessControlMaxAge : "3600" ,
6161 },
6262 },
63+ {
64+ name : "ok, preflight request when `Access-Control-Max-Age` is set" ,
65+ givenMW : CORSWithConfig (CORSConfig {
66+ AllowOrigins : []string {"localhost" },
67+ AllowCredentials : true ,
68+ MaxAge : 1 ,
69+ }),
70+ whenMethod : http .MethodOptions ,
71+ whenHeaders : map [string ]string {
72+ echo .HeaderOrigin : "localhost" ,
73+ echo .HeaderContentType : echo .MIMEApplicationJSON ,
74+ },
75+ expectHeaders : map [string ]string {
76+ echo .HeaderAccessControlMaxAge : "1" ,
77+ },
78+ },
79+ {
80+ name : "ok, preflight request when `Access-Control-Max-Age` is set to 0 - not to cache response" ,
81+ givenMW : CORSWithConfig (CORSConfig {
82+ AllowOrigins : []string {"localhost" },
83+ AllowCredentials : true ,
84+ MaxAge : - 1 , // forces `Access-Control-Max-Age: 0`
85+ }),
86+ whenMethod : http .MethodOptions ,
87+ whenHeaders : map [string ]string {
88+ echo .HeaderOrigin : "localhost" ,
89+ echo .HeaderContentType : echo .MIMEApplicationJSON ,
90+ },
91+ expectHeaders : map [string ]string {
92+ echo .HeaderAccessControlMaxAge : "0" ,
93+ },
94+ },
95+ {
96+ name : "ok, CORS check are skipped" ,
97+ givenMW : CORSWithConfig (CORSConfig {
98+ AllowOrigins : []string {"localhost" },
99+ AllowCredentials : true ,
100+ Skipper : func (c echo.Context ) bool {
101+ return true
102+ },
103+ }),
104+ whenMethod : http .MethodOptions ,
105+ whenHeaders : map [string ]string {
106+ echo .HeaderOrigin : "localhost" ,
107+ echo .HeaderContentType : echo .MIMEApplicationJSON ,
108+ },
109+ notExpectHeaders : map [string ]string {
110+ echo .HeaderAccessControlAllowOrigin : "localhost" ,
111+ echo .HeaderAccessControlAllowMethods : "GET,HEAD,PUT,PATCH,POST,DELETE" ,
112+ echo .HeaderAccessControlAllowCredentials : "true" ,
113+ echo .HeaderAccessControlMaxAge : "3600" ,
114+ },
115+ },
63116 {
64117 name : "ok, preflight request with wildcard `AllowOrigins` and `AllowCredentials` true" ,
65118 givenMW : CORSWithConfig (CORSConfig {
0 commit comments