MCPcopy Index your code
hub / github.com/labstack/echo / TestKeyAuth_errorHandlerSwallowsError

Function TestKeyAuth_errorHandlerSwallowsError

middleware/key_auth_test.go:346–375  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

344}
345
346func 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}

Callers

nothing calls this directly

Calls 5

GetMethod · 0.95
StringMethod · 0.95
SetMethod · 0.95
KeyAuthWithConfigFunction · 0.85
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…