| 979 | } |
| 980 | |
| 981 | func Test_Integration_Domain_ErrorHandling(t *testing.T) { |
| 982 | t.Parallel() |
| 983 | |
| 984 | app := fiber.New(fiber.Config{ |
| 985 | ErrorHandler: func(c fiber.Ctx, err error) error { |
| 986 | c.Set("X-Error-Handled", "true") |
| 987 | return c.Status(fiber.StatusInternalServerError).SendString("error: " + err.Error()) |
| 988 | }, |
| 989 | }) |
| 990 | app.Use(helmet.New()) |
| 991 | |
| 992 | app.Domain("api.example.com").Get("/error", func(_ fiber.Ctx) error { |
| 993 | return fiber.NewError(fiber.StatusInternalServerError, "domain error") |
| 994 | }) |
| 995 | |
| 996 | req := httptest.NewRequest(http.MethodGet, "/error", http.NoBody) |
| 997 | req.Host = "api.example.com" |
| 998 | resp, err := app.Test(req) |
| 999 | require.NoError(t, err) |
| 1000 | require.Equal(t, fiber.StatusInternalServerError, resp.StatusCode) |
| 1001 | require.Equal(t, "true", resp.Header.Get("X-Error-Handled")) |
| 1002 | require.Equal(t, "nosniff", resp.Header.Get(fiber.HeaderXContentTypeOptions)) |
| 1003 | body, err := io.ReadAll(resp.Body) |
| 1004 | require.NoError(t, err) |
| 1005 | require.Contains(t, string(body), "domain error") |
| 1006 | } |
| 1007 | |
| 1008 | func Test_Integration_Domain_WithLimiter(t *testing.T) { |
| 1009 | t.Parallel() |