mirror of https://github.com/status-im/consul.git
Merge pull request #8537 from hashicorp/dnephin/fix-panic-on-connect-nil
Fix panic when decoding 'Connect: null'
This commit is contained in:
commit
01745feec0
|
@ -1056,10 +1056,12 @@ func (t *ServiceConnect) UnmarshalJSON(data []byte) (err error) {
|
||||||
}{
|
}{
|
||||||
Alias: (*Alias)(t),
|
Alias: (*Alias)(t),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(data, &aux); err != nil {
|
if err = json.Unmarshal(data, &aux); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if t.SidecarService == nil {
|
|
||||||
|
if t.SidecarService == nil && aux != nil {
|
||||||
t.SidecarService = aux.SidecarServiceSnake
|
t.SidecarService = aux.SidecarServiceSnake
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/cache"
|
"github.com/hashicorp/consul/agent/cache"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
|
"github.com/hashicorp/consul/lib"
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -173,6 +174,46 @@ func testServiceNode(t *testing.T) *ServiceNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegisterRequest_UnmarshalJSON_WithConnectNilDoesNotPanic(t *testing.T) {
|
||||||
|
in := `
|
||||||
|
{
|
||||||
|
"ID": "",
|
||||||
|
"Node": "k8s-sync",
|
||||||
|
"Address": "127.0.0.1",
|
||||||
|
"TaggedAddresses": null,
|
||||||
|
"NodeMeta": {
|
||||||
|
"external-source": "kubernetes"
|
||||||
|
},
|
||||||
|
"Datacenter": "",
|
||||||
|
"Service": {
|
||||||
|
"Kind": "",
|
||||||
|
"ID": "test-service-f8fd5f0f4e6c",
|
||||||
|
"Service": "test-service",
|
||||||
|
"Tags": [
|
||||||
|
"k8s"
|
||||||
|
],
|
||||||
|
"Meta": {
|
||||||
|
"external-k8s-ns": "",
|
||||||
|
"external-source": "kubernetes",
|
||||||
|
"port-stats": "18080"
|
||||||
|
},
|
||||||
|
"Port": 8080,
|
||||||
|
"Address": "192.0.2.10",
|
||||||
|
"EnableTagOverride": false,
|
||||||
|
"CreateIndex": 0,
|
||||||
|
"ModifyIndex": 0,
|
||||||
|
"Connect": null
|
||||||
|
},
|
||||||
|
"Check": null,
|
||||||
|
"SkipNodeUpdate": true
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var req RegisterRequest
|
||||||
|
err := lib.DecodeJSON(strings.NewReader(in), &req)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNode_IsSame(t *testing.T) {
|
func TestNode_IsSame(t *testing.T) {
|
||||||
id := types.NodeID("e62f3b31-9284-4e26-ab14-2a59dea85b55")
|
id := types.NodeID("e62f3b31-9284-4e26-ab14-2a59dea85b55")
|
||||||
node := "mynode1"
|
node := "mynode1"
|
||||||
|
|
Loading…
Reference in New Issue