Home / Function/ Test_CORS_AllowOriginsFuncRejectsNonSerializedOrigins() — fiber Function Reference

Test_CORS_AllowOriginsFuncRejectsNonSerializedOrigins() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/cors/cors_test.go lines 763–860

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

	testCases := []struct {
		Name               string
		Origin             string
		Method             string
		SetPreflightMethod bool
		ExpectAllowed      bool
	}{
		{
			Name:   "UserInfoPresent",
			Origin: "http://user:pass@example.com",
			Method: fiber.MethodGet,
		},
		{
			Name:               "PathPresent",
			Origin:             "http://example.com/path",
			Method:             fiber.MethodOptions,
			SetPreflightMethod: true,
		},
		{
			Name:               "QueryPresent",
			Origin:             "http://example.com?query=1",
			Method:             fiber.MethodOptions,
			SetPreflightMethod: true,
		},
		{
			Name:   "FragmentPresent",
			Origin: "http://example.com#section",
			Method: fiber.MethodGet,
		},
		{
			Name:   "WildcardHost",
			Origin: "http://*.example.com",
			Method: fiber.MethodGet,
		},
		{
			Name:   "StandaloneWildcard",
			Origin: "*",
			Method: fiber.MethodGet,
		},
		{
			Name:   "NullOriginUppercase",
			Origin: "NULL",
			Method: fiber.MethodGet,
		},
		{
			Name:   "NullOriginMixedCase",
			Origin: "Null",
			Method: fiber.MethodGet,
		},
		{
			Name:          "NullOriginLowercase",
			Origin:        "null",
			Method:        fiber.MethodGet,
			ExpectAllowed: true,
		},
	}

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

			app := fiber.New()
			app.Use("/", New(Config{
				AllowOriginsFunc: func(string) bool { return true },
			}))
			app.All("/", func(c fiber.Ctx) error {
				return c.SendStatus(fiber.StatusOK)
			})

			handler := app.Handler()

			ctx := &fasthttp.RequestCtx{}
			ctx.Request.SetRequestURI("/")
			ctx.Request.Header.SetMethod(tc.Method)
			ctx.Request.Header.Set(fiber.HeaderOrigin, tc.Origin)
			if tc.SetPreflightMethod {
				ctx.Request.Header.Set(fiber.HeaderAccessControlRequestMethod, fiber.MethodGet)
			}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free