Make sure IngressHosts isn't parsed during JSON decode

This commit is contained in:
Kyle Havlovitz 2020-04-30 17:51:41 -07:00 committed by Chris Piraino
parent c30a7bfdfe
commit 26533dcb09
2 changed files with 20 additions and 1 deletions

View File

@ -249,7 +249,8 @@ type Upstream struct {
MeshGateway MeshGatewayConfig `json:",omitempty"`
// 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:"-"`
}

View File

@ -100,6 +100,8 @@ func TestUpstream_MarshalJSON(t *testing.T) {
DestinationName: "foo",
Datacenter: "dc1",
LocalBindPort: 1234,
// Test IngressHosts does not marshal
IngressHosts: []string{"test.example.com"},
},
want: `{
"DestinationType": "service",
@ -179,6 +181,22 @@ func TestUpstream_UnmarshalJSON(t *testing.T) {
},
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 {
t.Run(tt.name, func(t *testing.T) {