(t *testing.T)
| 460 | } |
| 461 | |
| 462 | func 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 | |
| 505 | func TestCSRFErrorHandling(t *testing.T) { |
| 506 | cfg := CSRFConfig{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…