Home / Function/ TestSubdomainMatch() — fiber Function Reference

TestSubdomainMatch() — fiber Function Reference

Architecture documentation for the TestSubdomainMatch() function in helpers_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  7559b3d7_6e88_5b96_922f_477ec0e253ff["TestSubdomainMatch()"]
  ce76a6de_702b_f385_2421_4a80229c068f["helpers_test.go"]
  7559b3d7_6e88_5b96_922f_477ec0e253ff -->|defined in| ce76a6de_702b_f385_2421_4a80229c068f
  style 7559b3d7_6e88_5b96_922f_477ec0e253ff fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/csrf/helpers_test.go lines 114–199

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

	tests := []struct {
		name     string
		sub      subdomain
		origin   string
		expected bool
	}{
		{
			name:     "match with different scheme",
			sub:      subdomain{prefix: "http://api.", suffix: "example.com"},
			origin:   "https://api.service.example.com",
			expected: false,
		},
		{
			name:     "match with different scheme",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "http://api.service.example.com",
			expected: false,
		},
		{
			name:     "match with valid subdomain",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://api.service.example.com",
			expected: true,
		},
		{
			name:     "match with valid nested subdomain",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://1.2.api.service.example.com",
			expected: true,
		},

		{
			name:     "no match with invalid prefix",
			sub:      subdomain{prefix: "https://abc.", suffix: "example.com"},
			origin:   "https://service.example.com",
			expected: false,
		},
		{
			name:     "no match with invalid suffix",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://api.example.org",
			expected: false,
		},
		{
			name:     "no match with empty origin",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "",
			expected: false,
		},
		{
			name:     "no match with malformed subdomain",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://evil.comexample.com",
			expected: false,
		},
		{
			name:     "partial match not considered a match",
			sub:      subdomain{prefix: "https://service.", suffix: "example.com"},
			origin:   "https://api.example.com",
			expected: false,
		},
		{
			name:     "no match with empty host label",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://.example.com",
			expected: false,
		},
		{
			name:     "no match with malformed host label",
			sub:      subdomain{prefix: "https://", suffix: "example.com"},
			origin:   "https://..example.com",
			expected: false,
		},
	}

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

Subdomains

Frequently Asked Questions

What does TestSubdomainMatch() do?
TestSubdomainMatch() is a function in the fiber codebase, defined in middleware/csrf/helpers_test.go.
Where is TestSubdomainMatch() defined?
TestSubdomainMatch() is defined in middleware/csrf/helpers_test.go at line 114.

Analyze Your Own Codebase

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

Try Supermodel Free