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

Function TestCSRFConfig_skipper

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

Source from the content-addressed store, hash-verified

460}
461
462func TestCSRFConfig_skipper(t *testing.T) {
463 var testCases = []struct {
464 name string
465 whenSkip bool
466 expectCookies int
467 }{
468 {
469 name: "do skip",
470 whenSkip: true,
471 expectCookies: 0,
472 },
473 {
474 name: "do not skip",
475 whenSkip: false,
476 expectCookies: 1,
477 },
478 }
479
480 for _, tc := range testCases {
481 t.Run(tc.name, func(t *testing.T) {
482 e := echo.New()
483 req := httptest.NewRequest(http.MethodGet, "/", nil)
484 rec := httptest.NewRecorder()
485 c := e.NewContext(req, rec)
486
487 csrf := CSRFWithConfig(CSRFConfig{
488 Skipper: func(c *echo.Context) bool {
489 return tc.whenSkip
490 },
491 })
492
493 h := csrf(func(c *echo.Context) error {
494 return c.String(http.StatusOK, "test")
495 })
496
497 r := h(c)
498 assert.NoError(t, r)
499 cookie := rec.Header()["Set-Cookie"]
500 assert.Len(t, cookie, tc.expectCookies)
501 })
502 }
503}
504
505func TestCSRFErrorHandling(t *testing.T) {
506 cfg := CSRFConfig{

Callers

nothing calls this directly

Calls 4

StringMethod · 0.95
CSRFWithConfigFunction · 0.85
NewContextMethod · 0.80
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…