Regression: https://github.com/gofiber/fiber/issues/4348 A failing session store must result in an error response, not a panic.
(t *testing.T)
| 709 | // Regression: https://github.com/gofiber/fiber/issues/4348 |
| 710 | // A failing session store must result in an error response, not a panic. |
| 711 | func 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 | |
| 734 | func Test_Session_Middleware_StoreError_CustomErrorHandler(t *testing.T) { |
| 735 | t.Parallel() |