ui: Remove any trailing fullstop/period DNS characters from Gateways UI API (#9752)
Previous to this commit, the API response would include Gateway Addresses in the form `domain.name.:8080`, which due to the addition of the port is probably not the expected response. This commit rightTrims any `.` characters from the end of the domain before formatting the address to include the port resulting in `domain.name:8080`
This commit is contained in:
parent
4336d522c1
commit
2d500d24b8
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
api: Remove trailing periods from the gateway internal HTTP API endpoint
|
||||||
|
```
|
|
@ -454,8 +454,11 @@ func (g *GatewayService) Addresses(defaultHosts []string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var addresses []string
|
var addresses []string
|
||||||
|
// loop through the hosts and format that into domain.name:port format,
|
||||||
|
// ensuring we trim any trailing DNS . characters from the domain name as we
|
||||||
|
// go
|
||||||
for _, h := range hosts {
|
for _, h := range hosts {
|
||||||
addresses = append(addresses, fmt.Sprintf("%s:%d", h, g.Port))
|
addresses = append(addresses, fmt.Sprintf("%s:%d", strings.TrimRight(h, "."), g.Port))
|
||||||
}
|
}
|
||||||
return addresses
|
return addresses
|
||||||
}
|
}
|
||||||
|
|
|
@ -663,23 +663,25 @@ func TestGatewayService_Addresses(t *testing.T) {
|
||||||
argument: []string{
|
argument: []string{
|
||||||
"service.ingress.dc.domain",
|
"service.ingress.dc.domain",
|
||||||
"service.ingress.dc.alt.domain",
|
"service.ingress.dc.alt.domain",
|
||||||
|
"service.ingress.dc.alt.domain.",
|
||||||
},
|
},
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"service.ingress.dc.domain:8080",
|
"service.ingress.dc.domain:8080",
|
||||||
"service.ingress.dc.alt.domain:8080",
|
"service.ingress.dc.alt.domain:8080",
|
||||||
|
"service.ingress.dc.alt.domain:8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "user-defined hosts",
|
name: "user-defined hosts",
|
||||||
input: GatewayService{
|
input: GatewayService{
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
Hosts: []string{"*.test.example.com", "other.example.com"},
|
Hosts: []string{"*.test.example.com", "other.example.com", "other.example.com."},
|
||||||
},
|
},
|
||||||
argument: []string{
|
argument: []string{
|
||||||
"service.ingress.dc.domain",
|
"service.ingress.dc.domain",
|
||||||
"service.ingress.alt.domain",
|
"service.ingress.alt.domain",
|
||||||
},
|
},
|
||||||
expected: []string{"*.test.example.com:8080", "other.example.com:8080"},
|
expected: []string{"*.test.example.com:8080", "other.example.com:8080", "other.example.com:8080"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -832,11 +832,13 @@ func TestUIGatewayServiceNodes_Ingress(t *testing.T) {
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assertIndex(t, resp)
|
assertIndex(t, resp)
|
||||||
|
|
||||||
// Construct expected addresses so that differences between OSS/Ent are handled by code
|
// Construct expected addresses so that differences between OSS/Ent are
|
||||||
webDNS := serviceIngressDNSName("web", "dc1", "consul.", structs.DefaultEnterpriseMeta())
|
// handled by code. We specifically don't include the trailing DNS . here as
|
||||||
webDNSAlt := serviceIngressDNSName("web", "dc1", "alt.consul.", structs.DefaultEnterpriseMeta())
|
// we are constructing what we are expecting, not the actual value
|
||||||
dbDNS := serviceIngressDNSName("db", "dc1", "consul.", structs.DefaultEnterpriseMeta())
|
webDNS := serviceIngressDNSName("web", "dc1", "consul", structs.DefaultEnterpriseMeta())
|
||||||
dbDNSAlt := serviceIngressDNSName("db", "dc1", "alt.consul.", structs.DefaultEnterpriseMeta())
|
webDNSAlt := serviceIngressDNSName("web", "dc1", "alt.consul", structs.DefaultEnterpriseMeta())
|
||||||
|
dbDNS := serviceIngressDNSName("db", "dc1", "consul", structs.DefaultEnterpriseMeta())
|
||||||
|
dbDNSAlt := serviceIngressDNSName("db", "dc1", "alt.consul", structs.DefaultEnterpriseMeta())
|
||||||
|
|
||||||
dump := obj.([]*ServiceSummary)
|
dump := obj.([]*ServiceSummary)
|
||||||
expect := []*ServiceSummary{
|
expect := []*ServiceSummary{
|
||||||
|
|
Loading…
Reference in New Issue