Home / Function/ Test_CSRF_Param_Extractor_Missing() — fiber Function Reference

Test_CSRF_Param_Extractor_Missing() — fiber Function Reference

Architecture documentation for the Test_CSRF_Param_Extractor_Missing() function in csrf_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  2cc10801_ec02_5af9_8b00_1b05407b0d76["Test_CSRF_Param_Extractor_Missing()"]
  306a0c68_f5a5_b368_f37a_1419425a8fea["csrf_test.go"]
  2cc10801_ec02_5af9_8b00_1b05407b0d76 -->|defined in| 306a0c68_f5a5_b368_f37a_1419425a8fea
  style 2cc10801_ec02_5af9_8b00_1b05407b0d76 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/csrf/csrf_test.go lines 2386–2416

func Test_CSRF_Param_Extractor_Missing(t *testing.T) {
	t.Parallel()

	// Test the case where no param is provided (should get 403 from CSRF middleware on the catch-all route)
	app := fiber.New()

	// Add a catch-all route with CSRF middleware for missing param case
	app.Use(New(Config{Extractor: extractors.FromParam("csrf")}))
	app.Post("/", func(c fiber.Ctx) error {
		return c.SendStatus(fiber.StatusOK)
	})

	h := app.Handler()
	ctx := &fasthttp.RequestCtx{}

	// Generate CSRF token
	ctx.Request.Header.SetMethod(fiber.MethodGet)
	ctx.Request.SetRequestURI("/")
	h(ctx)
	token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
	token = strings.Split(strings.Split(token, ";")[0], "=")[1]

	// Test missing param (accessing "/" instead of "/:csrf")
	ctx.Request.Reset()
	ctx.Response.Reset()
	ctx.Request.Header.SetMethod(fiber.MethodPost)
	ctx.Request.SetRequestURI("/")
	ctx.Request.Header.SetCookie(ConfigDefault.CookieName, token)
	h(ctx)
	require.Equal(t, 403, ctx.Response.StatusCode(), "Missing param should return 403")
}

Subdomains

Frequently Asked Questions

What does Test_CSRF_Param_Extractor_Missing() do?
Test_CSRF_Param_Extractor_Missing() is a function in the fiber codebase, defined in middleware/csrf/csrf_test.go.
Where is Test_CSRF_Param_Extractor_Missing() defined?
Test_CSRF_Param_Extractor_Missing() is defined in middleware/csrf/csrf_test.go at line 2386.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free