Make sure IngressHosts isn't parsed during JSON decode
This commit is contained in:
parent
c30a7bfdfe
commit
26533dcb09
|
@ -249,7 +249,8 @@ type Upstream struct {
|
||||||
MeshGateway MeshGatewayConfig `json:",omitempty"`
|
MeshGateway MeshGatewayConfig `json:",omitempty"`
|
||||||
|
|
||||||
// IngressHosts are a list of hosts that should route to this upstream from
|
// IngressHosts are a list of hosts that should route to this upstream from
|
||||||
// an ingress gateway
|
// an ingress gateway. This cannot and should not be set by a user, it is
|
||||||
|
// used internally to store the association of hosts to an upstream service.
|
||||||
IngressHosts []string `json:"-" bexpr:"-"`
|
IngressHosts []string `json:"-" bexpr:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,8 @@ func TestUpstream_MarshalJSON(t *testing.T) {
|
||||||
DestinationName: "foo",
|
DestinationName: "foo",
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
LocalBindPort: 1234,
|
LocalBindPort: 1234,
|
||||||
|
// Test IngressHosts does not marshal
|
||||||
|
IngressHosts: []string{"test.example.com"},
|
||||||
},
|
},
|
||||||
want: `{
|
want: `{
|
||||||
"DestinationType": "service",
|
"DestinationType": "service",
|
||||||
|
@ -179,6 +181,22 @@ func TestUpstream_UnmarshalJSON(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "ingress-hosts-do-not-unmarshal",
|
||||||
|
json: `{
|
||||||
|
"DestinationType": "service",
|
||||||
|
"DestinationName": "foo",
|
||||||
|
"Datacenter": "dc1",
|
||||||
|
"IngressHosts": ["asdf"]
|
||||||
|
}`,
|
||||||
|
want: Upstream{
|
||||||
|
DestinationType: UpstreamDestTypeService,
|
||||||
|
DestinationName: "foo",
|
||||||
|
Datacenter: "dc1",
|
||||||
|
IngressHosts: nil, // Make sure this doesn't get parsed
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue