@@ -95,7 +95,7 @@ func TestProxySamplingRate(t *testing.T) {
9595 }
9696}
9797
98- func TestIsOverlappingHostname (t * testing.T ) {
98+ func TestAreOverlappingHostnames (t * testing.T ) {
9999 tests := []struct {
100100 name string
101101 hostname1 * gwapiv1.Hostname
@@ -115,10 +115,10 @@ func TestIsOverlappingHostname(t *testing.T) {
115115 want : true ,
116116 },
117117 {
118- name : "two wildcards matches subdomain" ,
118+ name : "two wildcards with subdomain does not match " ,
119119 hostname1 : ptr .To (gwapiv1 .Hostname ("*.example.com" )),
120120 hostname2 : ptr .To (gwapiv1 .Hostname ("*.test.example.com" )),
121- want : true ,
121+ want : false ,
122122 },
123123 {
124124 name : "nil hostname matches all" ,
@@ -139,22 +139,22 @@ func TestIsOverlappingHostname(t *testing.T) {
139139 want : true ,
140140 },
141141 {
142- name : "wildcard matches exact " ,
142+ name : "wildcard matches exactly one level of subdomain " ,
143143 hostname1 : ptr .To (gwapiv1 .Hostname ("*.example.com" )),
144144 hostname2 : ptr .To (gwapiv1 .Hostname ("test.example.com" )),
145145 want : true ,
146146 },
147147 {
148- name : "wildcard matches subdomain" ,
148+ name : "wildcard matches only one level of subdomain" ,
149149 hostname1 : ptr .To (gwapiv1 .Hostname ("*.example.com" )),
150150 hostname2 : ptr .To (gwapiv1 .Hostname ("sub.test.example.com" )),
151- want : true ,
151+ want : false ,
152152 },
153153 {
154- name : "wildcard matches empty subdomain" ,
154+ name : "wildcard does not match empty subdomain" ,
155155 hostname1 : ptr .To (gwapiv1 .Hostname ("*.example.com" )),
156156 hostname2 : ptr .To (gwapiv1 .Hostname ("example.com" )),
157- want : true ,
157+ want : false ,
158158 },
159159 {
160160 name : "different domains" ,
@@ -180,15 +180,21 @@ func TestIsOverlappingHostname(t *testing.T) {
180180 hostname2 : ptr .To (gwapiv1 .Hostname ("testing-api.foo.dev" )),
181181 want : false ,
182182 },
183+ {
184+ name : "sub domain does not match with parent domain" ,
185+ hostname1 : ptr .To (gwapiv1 .Hostname ("api.foo.dev" )),
186+ hostname2 : ptr .To (gwapiv1 .Hostname ("foo.dev" )),
187+ want : false ,
188+ },
183189 }
184190
185191 for _ , tt := range tests {
186192 t .Run (tt .name , func (t * testing.T ) {
187- if got := isOverlappingHostname (tt .hostname1 , tt .hostname2 ); got != tt .want {
193+ if got := areOverlappingHostnames (tt .hostname1 , tt .hostname2 ); got != tt .want {
188194 t .Errorf ("isOverlappingHostname(%q, %q) = %v, want %v" , ptr .Deref (tt .hostname1 , "" ), ptr .Deref (tt .hostname2 , "" ), got , tt .want )
189195 }
190196 // Test should be symmetric
191- if got := isOverlappingHostname (tt .hostname2 , tt .hostname1 ); got != tt .want {
197+ if got := areOverlappingHostnames (tt .hostname2 , tt .hostname1 ); got != tt .want {
192198 t .Errorf ("isOverlappingHostname(%q, %q) = %v, want %v" , ptr .Deref (tt .hostname2 , "" ), ptr .Deref (tt .hostname1 , "" ), got , tt .want )
193199 }
194200 })
@@ -301,15 +307,14 @@ func TestCheckOverlappingHostnames(t *testing.T) {
301307 Name : "listener-3" ,
302308 Protocol : gwapiv1 .HTTPSProtocolType ,
303309 Port : 443 ,
304- Hostname : ptr .To (gwapiv1 .Hostname ("sub.test.example.com" )),
310+ Hostname : ptr .To (gwapiv1 .Hostname ("sub.test.example.com" )), // sub domain does not match with parent domain
305311 },
306312 },
307313 },
308314 },
309315 expected : map [int ]string {
310316 0 : "test.example.com" ,
311317 1 : "*.example.com" ,
312- 2 : "*.example.com" ,
313318 },
314319 },
315320 {
0 commit comments