mirror of
https://github.com/traefik/traefik.git
synced 2026-06-17 19:09:29 +03:00
Fix incorrect hostname matching between listener and route
This commit is contained in:
@@ -1093,24 +1093,13 @@ func findMatchingHostname(h1, h2 gatev1.Hostname) gatev1.Hostname {
|
||||
}
|
||||
|
||||
trimmedH1 := strings.TrimPrefix(string(h1), "*")
|
||||
// root domain doesn't match subdomain wildcard.
|
||||
if trimmedH1 == string(h2) {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(string(h2), trimmedH1) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return lessWildcards(h1, h2)
|
||||
}
|
||||
|
||||
func lessWildcards(h1, h2 gatev1.Hostname) gatev1.Hostname {
|
||||
if strings.Count(string(h1), "*") > strings.Count(string(h2), "*") {
|
||||
return h2
|
||||
}
|
||||
|
||||
return h1
|
||||
// since h1 is a suffix of h2, we know h2 is the more specific host
|
||||
return h2
|
||||
}
|
||||
|
||||
func allowRoute(listener gatewayListener, routeNamespace, routeKind string) bool {
|
||||
|
||||
@@ -7630,6 +7630,13 @@ func Test_findMatchingHostnames(t *testing.T) {
|
||||
want: []gatev1.Hostname{"toto.foo.com", "test.foo.com"},
|
||||
wantOk: true,
|
||||
},
|
||||
{
|
||||
desc: "Matching wildcard subsubdomain with listener wildcard subdomain",
|
||||
listenerHostname: ptr.To(gatev1.Hostname("*.foo.com")),
|
||||
routeHostnames: []gatev1.Hostname{"*.bar.foo.com"},
|
||||
want: []gatev1.Hostname{"*.bar.foo.com"},
|
||||
wantOk: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user