MCPcopy
hub / github.com/labstack/echo / TestCSRFErrorHandling

Function TestCSRFErrorHandling

middleware/csrf_test.go:505–525  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

503}
504
505func TestCSRFErrorHandling(t *testing.T) {
506 cfg := CSRFConfig{
507 ErrorHandler: func(c *echo.Context, err error) error {
508 return echo.NewHTTPError(http.StatusTeapot, "error_handler_executed")
509 },
510 }
511
512 e := echo.New()
513 e.POST("/", func(c *echo.Context) error {
514 return c.String(http.StatusNotImplemented, "should not end up here")
515 })
516
517 e.Use(CSRFWithConfig(cfg))
518
519 req := httptest.NewRequest(http.MethodPost, "/", nil)
520 res := httptest.NewRecorder()
521 e.ServeHTTP(res, req)
522
523 assert.Equal(t, http.StatusTeapot, res.Code)
524 assert.Equal(t, "{\"message\":\"error_handler_executed\"}\n", res.Body.String())
525}
526
527func TestCSRFConfig_checkSecFetchSiteRequest(t *testing.T) {
528 var testCases = []struct {

Callers

nothing calls this directly

Calls 5

CSRFWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
POSTMethod · 0.45
StringMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…