Home / Function/ Test_CSRF_Extractors_ErrorTypes() — fiber Function Reference

Test_CSRF_Extractors_ErrorTypes() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/csrf/csrf_test.go lines 2418–2477

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

	// Test all extractor error types
	testCases := []struct {
		expected  error
		setupCtx  func(ctx *fasthttp.RequestCtx) // Add setup function
		name      string
		extractor extractors.Extractor
	}{
		{
			name:      "Missing header",
			extractor: extractors.FromHeader("X-Missing-Header"),
			expected:  extractors.ErrNotFound,
			setupCtx:  func(_ *fasthttp.RequestCtx) {}, // No setup needed for headers
		},
		{
			name:      "Missing query",
			extractor: extractors.FromQuery("missing_param"),
			expected:  extractors.ErrNotFound,
			setupCtx: func(ctx *fasthttp.RequestCtx) {
				ctx.Request.SetRequestURI("/") // Set URI for query parsing
			},
		},
		{
			name:      "Missing param",
			extractor: extractors.FromParam("missing_param"),
			expected:  extractors.ErrNotFound,
			setupCtx:  func(_ *fasthttp.RequestCtx) {}, // Params are handled by router
		},
		{
			name:      "Missing form",
			extractor: extractors.FromForm("missing_field"),
			expected:  extractors.ErrNotFound,
			setupCtx: func(ctx *fasthttp.RequestCtx) {
				// Properly initialize request for form parsing
				ctx.Request.Header.SetMethod(fiber.MethodPost)
				ctx.Request.Header.SetContentType(fiber.MIMEApplicationForm)
				ctx.Request.SetBodyString("") // Empty form body
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()

			app := fiber.New()
			requestCtx := &fasthttp.RequestCtx{}
			tc.setupCtx(requestCtx) // Set up the context properly

			ctx := app.AcquireCtx(requestCtx)
			defer app.ReleaseCtx(ctx)

			token, err := tc.extractor.Extract(ctx)
			require.Empty(t, token)
			require.Equal(t, tc.expected, err)
		})
	}
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free