MCPcopy
hub / github.com/gofiber/fiber / Test_Session_Middleware_StoreError

Function Test_Session_Middleware_StoreError

middleware/session/middleware_test.go:711–732  ·  view source on GitHub ↗

Regression: https://github.com/gofiber/fiber/issues/4348 A failing session store must result in an error response, not a panic.

(t *testing.T)

Source from the content-addressed store, hash-verified

709// Regression: https://github.com/gofiber/fiber/issues/4348
710// A failing session store must result in an error response, not a panic.
711func Test_Session_Middleware_StoreError(t *testing.T) {
712 t.Parallel()
713
714 storage := &failingStorage{err: errors.New("storage unavailable")}
715 app := fiber.New()
716 app.Use(New(Config{Storage: storage}))
717
718 app.Get("/", func(c fiber.Ctx) error {
719 return c.SendStatus(fiber.StatusOK)
720 })
721
722 h := app.Handler()
723
724 ctx := &fasthttp.RequestCtx{}
725 ctx.Request.Header.SetMethod(fiber.MethodGet)
726 // Provide a session ID so the middleware attempts a storage lookup.
727 ctx.Request.Header.SetCookie("session_id", "some-session-id")
728 require.NotPanics(t, func() { h(ctx) })
729 require.Equal(t, fiber.StatusInternalServerError, ctx.Response.StatusCode())
730 require.Equal(t, "Internal Server Error", string(ctx.Response.Body()))
731 require.NotContains(t, string(ctx.Response.Body()), storage.err.Error())
732}
733
734func Test_Session_Middleware_StoreError_CustomErrorHandler(t *testing.T) {
735 t.Parallel()

Callers

nothing calls this directly

Calls 11

HandlerMethod · 0.80
SetMethodMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
SendStatusMethod · 0.65
BodyMethod · 0.65
ErrorMethod · 0.65
SetCookieMethod · 0.45
StatusCodeMethod · 0.45

Tested by

no test coverage detected