mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
agent: reject config with invalid options
This commit is contained in:
parent
e9615c50e6
commit
b8740b62da
@ -335,6 +335,13 @@ type Config struct {
|
|||||||
|
|
||||||
// WatchPlans contains the compiled watches
|
// WatchPlans contains the compiled watches
|
||||||
WatchPlans []*watch.WatchPlan `mapstructure:"-" json:"-"`
|
WatchPlans []*watch.WatchPlan `mapstructure:"-" json:"-"`
|
||||||
|
|
||||||
|
// Allow the following fields to be present in configuration files without
|
||||||
|
// mapstructure erroring on them.
|
||||||
|
_ interface{} `mapstructure:"services"`
|
||||||
|
_ interface{} `mapstructure:"checks"`
|
||||||
|
_ interface{} `mapstructure:"service"`
|
||||||
|
_ interface{} `mapstructure:"check"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type dirEnts []os.FileInfo
|
type dirEnts []os.FileInfo
|
||||||
@ -463,8 +470,9 @@ func DecodeConfig(r io.Reader) (*Config, error) {
|
|||||||
// Decode
|
// Decode
|
||||||
var md mapstructure.Metadata
|
var md mapstructure.Metadata
|
||||||
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
msdec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||||
Metadata: &md,
|
Metadata: &md,
|
||||||
Result: &result,
|
Result: &result,
|
||||||
|
ErrorUnused: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -591,6 +592,14 @@ func TestDecodeConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeConfig_invalidKeys(t *testing.T) {
|
||||||
|
input := `{"bad": "no way jose"}`
|
||||||
|
_, err := DecodeConfig(bytes.NewReader([]byte(input)))
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "invalid keys") {
|
||||||
|
t.Fatalf("should have rejected invalid config keys")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDecodeConfig_Services(t *testing.T) {
|
func TestDecodeConfig_Services(t *testing.T) {
|
||||||
input := `{
|
input := `{
|
||||||
"services": [
|
"services": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user