File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,21 @@ func TestCSRFMiddlewareRejectsPostWithoutToken(t *testing.T) {
2727 assert .Equal (t , http .StatusBadRequest , rec .Code )
2828}
2929
30+ func TestCSRFMiddlewareSkipsNonHTMXPostWithoutToken (t * testing.T ) {
31+ e := echo .New ()
32+ e .Use (CSRF ())
33+ e .POST ("/submit" , func (c echo.Context ) error {
34+ return c .String (http .StatusOK , "ok" )
35+ })
36+
37+ req := httptest .NewRequest (http .MethodPost , "/submit" , strings .NewReader ("x=1" ))
38+ req .Header .Set (echo .HeaderContentType , echo .MIMEApplicationForm )
39+ rec := httptest .NewRecorder ()
40+ e .ServeHTTP (rec , req )
41+
42+ assert .Equal (t , http .StatusOK , rec .Code )
43+ }
44+
3045func TestCSRFMiddlewareAllowsPostWithTokenHeaderAndCookie (t * testing.T ) {
3146 e := echo .New ()
3247 e .Use (CSRF ())
You can’t perform that action at this time.
0 commit comments