Skip to content

Commit

Permalink
test(subdomain): add tests for extracting tenant from subdomain
Browse files Browse the repository at this point in the history
This commit adds additional tests for the ExtractSubdomain function to ensure it correctly extracts the tenant from the subdomain. These tests enhance the reliability of our multi-tenancy handling.
  • Loading branch information
bartventer committed Feb 22, 2024
1 parent 8134cfa commit 7db5f3d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,58 @@ func TestDefaultTenantFromSubdomain(t *testing.T) {
},
wantErr: true,
},
{
name: "valid:test-from-subdomain-with-port",
args: args{
r: &http.Request{
Method: http.MethodGet,
Header: map[string][]string{},
Host: "tenant1.example.com:8080",
URL: &url.URL{Path: "/"},
TLS: &tls.ConnectionState{}, // Simulate an https request
},
},
want: "tenant1",
wantErr: false,
},
{
name: "valid:test-from-subdomain-with-multiple-subdomains",
args: args{
r: &http.Request{
Method: http.MethodGet,
Header: map[string][]string{},
Host: "tenant1.sub.example.com",
URL: &url.URL{Path: "/"},
TLS: &tls.ConnectionState{}, // Simulate an https request
},
},
want: "tenant1",
wantErr: false,
},
{
name: "invalid:no-subdomain",
args: args{
r: &http.Request{
Method: http.MethodGet,
Header: map[string][]string{},
Host: "example.com",
URL: &url.URL{Path: "/"},
},
},
wantErr: true,
},
{
name: "invalid:host-is-ip",
args: args{
r: &http.Request{
Method: http.MethodGet,
Header: map[string][]string{},
Host: "192.168.1.1",
URL: &url.URL{Path: "/"},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 7db5f3d

Please sign in to comment.