Home / Function/ Test_CSRF_Extractor_Error_Types() — fiber Function Reference

Test_CSRF_Extractor_Error_Types() — fiber Function Reference

Architecture documentation for the Test_CSRF_Extractor_Error_Types() function in config_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  7806f86e_19b6_7da6_39af_d3fbf8f0e0c0["Test_CSRF_Extractor_Error_Types()"]
  d4b0c76b_df58_68cc_9f01_dca309899302["config_test.go"]
  7806f86e_19b6_7da6_39af_d3fbf8f0e0c0 -->|defined in| d4b0c76b_df58_68cc_9f01_dca309899302
  style 7806f86e_19b6_7da6_39af_d3fbf8f0e0c0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/csrf/config_test.go lines 243–305

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

	testCases := []struct {
		expectedError error
		setupRequest  func(*fasthttp.RequestCtx)
		name          string
		extractor     extractors.Extractor
	}{
		{
			name:      "MissingHeader",
			extractor: extractors.FromHeader("X-Missing"),
			setupRequest: func(_ *fasthttp.RequestCtx) {
				// Don't set the header
			},
			expectedError: extractors.ErrNotFound,
		},
		{
			name:      "MissingForm",
			extractor: extractors.FromForm("_missing"),
			setupRequest: func(ctx *fasthttp.RequestCtx) {
				ctx.Request.Header.Set(fiber.HeaderContentType, fiber.MIMEApplicationForm)
				// Don't set form data
			},
			expectedError: extractors.ErrNotFound,
		},
		{
			name:      "MissingQuery",
			extractor: extractors.FromQuery("missing"),
			setupRequest: func(ctx *fasthttp.RequestCtx) {
				ctx.Request.SetRequestURI("/")
				// Don't set query param
			},
			expectedError: extractors.ErrNotFound,
		},
		{
			name:      "MissingParam",
			extractor: extractors.FromParam("missing"),
			setupRequest: func(_ *fasthttp.RequestCtx) {
				// This would need special route setup to test properly
				// For now, we'll test the extractor directly
			},
			expectedError: extractors.ErrNotFound,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			t.Parallel()
			app := fiber.New()
			ctx := &fasthttp.RequestCtx{}

			tc.setupRequest(ctx)

			c := app.AcquireCtx(ctx)

			_, err := tc.extractor.Extract(c)
			require.Error(t, err)
			require.Equal(t, tc.expectedError, err)
			app.ReleaseCtx(c)
		})
	}
}

Subdomains

Frequently Asked Questions

What does Test_CSRF_Extractor_Error_Types() do?
Test_CSRF_Extractor_Error_Types() is a function in the fiber codebase, defined in middleware/csrf/config_test.go.
Where is Test_CSRF_Extractor_Error_Types() defined?
Test_CSRF_Extractor_Error_Types() is defined in middleware/csrf/config_test.go at line 243.

Analyze Your Own Codebase

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

Try Supermodel Free