Home / Function/ Test_CORS_AllowOriginsFunc() — fiber Function Reference

Test_CORS_AllowOriginsFunc() — fiber Function Reference

Architecture documentation for the Test_CORS_AllowOriginsFunc() function in cors_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  2249d084_3071_7ff1_1c66_49c7ce6d6935["Test_CORS_AllowOriginsFunc()"]
  e59a43fd_cfa4_0f6b_1938_4a08e36ad74e["cors_test.go"]
  2249d084_3071_7ff1_1c66_49c7ce6d6935 -->|defined in| e59a43fd_cfa4_0f6b_1938_4a08e36ad74e
  style 2249d084_3071_7ff1_1c66_49c7ce6d6935 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cors/cors_test.go lines 722–761

func Test_CORS_AllowOriginsFunc(t *testing.T) {
	t.Parallel()
	// New fiber instance
	app := fiber.New()
	app.Use("/", New(Config{
		AllowOriginsFunc: func(origin string) bool {
			return strings.Contains(origin, "example-2")
		},
	}))

	// Get handler pointer
	handler := app.Handler()

	// Make request with disallowed origin
	ctx := &fasthttp.RequestCtx{}
	ctx.Request.SetRequestURI("/")
	ctx.Request.Header.SetMethod(fiber.MethodOptions)
	ctx.Request.Header.Set(fiber.HeaderOrigin, "http://google.com")

	// Perform request
	handler(ctx)

	// Allow-Origin header should be empty because http://google.com does not satisfy 'strings.Contains(origin, "example-2")'
	// and AllowOrigins has not been set
	require.Empty(t, string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))

	ctx.Request.Reset()
	ctx.Response.Reset()

	// Make request with allowed origin
	ctx.Request.SetRequestURI("/")
	ctx.Request.Header.SetMethod(fiber.MethodOptions)
	ctx.Request.Header.Set(fiber.HeaderAccessControlRequestMethod, fiber.MethodGet)
	ctx.Request.Header.Set(fiber.HeaderOrigin, "http://example-2.com")

	handler(ctx)

	// Allow-Origin header should be "http://example-2.com"
	require.Equal(t, "http://example-2.com", string(ctx.Response.Header.Peek(fiber.HeaderAccessControlAllowOrigin)))
}

Domain

Subdomains

Frequently Asked Questions

What does Test_CORS_AllowOriginsFunc() do?
Test_CORS_AllowOriginsFunc() is a function in the fiber codebase, defined in middleware/cors/cors_test.go.
Where is Test_CORS_AllowOriginsFunc() defined?
Test_CORS_AllowOriginsFunc() is defined in middleware/cors/cors_test.go at line 722.

Analyze Your Own Codebase

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

Try Supermodel Free