(t *testing.T)
| 344 | } |
| 345 | |
| 346 | func TestKeyAuth_errorHandlerSwallowsError(t *testing.T) { |
| 347 | handlerCalled := false |
| 348 | var authValue string |
| 349 | handler := func(c *echo.Context) error { |
| 350 | handlerCalled = true |
| 351 | authValue = c.Get("auth").(string) |
| 352 | return c.String(http.StatusOK, "test") |
| 353 | } |
| 354 | middlewareChain := KeyAuthWithConfig(KeyAuthConfig{ |
| 355 | Validator: testKeyValidator, |
| 356 | ErrorHandler: func(c *echo.Context, err error) error { |
| 357 | // could check error to decide if we can swallow the error |
| 358 | c.Set("auth", "public") |
| 359 | return nil |
| 360 | }, |
| 361 | ContinueOnIgnoredError: true, |
| 362 | })(handler) |
| 363 | |
| 364 | e := echo.New() |
| 365 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 366 | // no auth header this time |
| 367 | rec := httptest.NewRecorder() |
| 368 | c := e.NewContext(req, rec) |
| 369 | |
| 370 | err := middlewareChain(c) |
| 371 | |
| 372 | assert.NoError(t, err) |
| 373 | assert.True(t, handlerCalled) |
| 374 | assert.Equal(t, "public", authValue) |
| 375 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…