2015-03-12 22:21:11 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2016-03-09 23:59:44 +00:00
|
|
|
"strings"
|
2015-03-12 22:21:11 +00:00
|
|
|
"testing"
|
2015-07-30 17:21:41 +00:00
|
|
|
"time"
|
2016-08-19 20:45:17 +00:00
|
|
|
|
2017-08-03 11:33:06 +00:00
|
|
|
"github.com/hashicorp/hcl"
|
|
|
|
"github.com/hashicorp/hcl/hcl/ast"
|
2016-08-19 20:45:17 +00:00
|
|
|
"github.com/hashicorp/vault/helper/logformat"
|
|
|
|
log "github.com/mgutz/logxi/v1"
|
2015-03-12 22:21:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadConfigFile(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config.hcl", logger)
|
2015-03-12 22:21:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
2016-06-02 16:40:25 +00:00
|
|
|
&Listener{
|
2016-06-02 22:19:51 +00:00
|
|
|
Type: "tcp",
|
2017-06-22 19:29:53 +00:00
|
|
|
Config: map[string]interface{}{
|
2016-06-02 22:19:51 +00:00
|
|
|
"address": "127.0.0.1:443",
|
2016-06-02 16:40:25 +00:00
|
|
|
},
|
|
|
|
},
|
2015-03-12 22:21:11 +00:00
|
|
|
},
|
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
Storage: &Storage{
|
2016-08-15 13:42:42 +00:00
|
|
|
Type: "consul",
|
|
|
|
RedirectAddr: "foo",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
2015-04-17 18:21:40 +00:00
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
HAStorage: &Storage{
|
2016-08-15 13:42:42 +00:00
|
|
|
Type: "consul",
|
|
|
|
RedirectAddr: "snafu",
|
2015-12-11 20:58:10 +00:00
|
|
|
Config: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
2016-10-02 18:54:01 +00:00
|
|
|
DisableClustering: true,
|
2015-12-11 20:58:10 +00:00
|
|
|
},
|
|
|
|
|
2015-07-14 22:27:18 +00:00
|
|
|
Telemetry: &Telemetry{
|
2015-08-27 14:50:16 +00:00
|
|
|
StatsdAddr: "bar",
|
|
|
|
StatsiteAddr: "foo",
|
2015-07-14 22:27:18 +00:00
|
|
|
DisableHostname: false,
|
2017-06-17 03:51:46 +00:00
|
|
|
DogStatsDAddr: "127.0.0.1:7254",
|
|
|
|
DogStatsDTags: []string{"tag_1:val_1", "tag_2:val_2"},
|
2015-07-14 22:27:18 +00:00
|
|
|
},
|
|
|
|
|
2017-03-07 16:21:22 +00:00
|
|
|
DisableCache: true,
|
|
|
|
DisableCacheRaw: true,
|
|
|
|
DisableMlock: true,
|
|
|
|
DisableMlockRaw: true,
|
|
|
|
EnableUI: true,
|
|
|
|
EnableUIRaw: true,
|
2015-07-30 13:42:49 +00:00
|
|
|
|
2017-09-15 04:21:35 +00:00
|
|
|
EnableRawEndpoint: true,
|
|
|
|
EnableRawEndpointRaw: true,
|
|
|
|
|
2015-08-27 14:50:16 +00:00
|
|
|
MaxLeaseTTL: 10 * time.Hour,
|
|
|
|
MaxLeaseTTLRaw: "10h",
|
|
|
|
DefaultLeaseTTL: 10 * time.Hour,
|
|
|
|
DefaultLeaseTTLRaw: "10h",
|
2016-07-26 15:38:24 +00:00
|
|
|
ClusterName: "testcluster",
|
2017-09-16 21:09:37 +00:00
|
|
|
|
|
|
|
PidFile: "./pidfile",
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
2016-03-09 23:59:44 +00:00
|
|
|
t.Fatalf("expected \n\n%#v\n\n to be \n\n%#v\n\n", config, expected)
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:19:41 +00:00
|
|
|
func TestLoadConfigFile_topLevel(t *testing.T) {
|
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config2.hcl", logger)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Storage: &Storage{
|
|
|
|
Type: "consul",
|
|
|
|
RedirectAddr: "top_level_api_addr",
|
|
|
|
ClusterAddr: "top_level_cluster_addr",
|
|
|
|
Config: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
HAStorage: &Storage{
|
|
|
|
Type: "consul",
|
|
|
|
RedirectAddr: "top_level_api_addr",
|
|
|
|
ClusterAddr: "top_level_cluster_addr",
|
|
|
|
Config: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
DisableClustering: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
Telemetry: &Telemetry{
|
|
|
|
StatsdAddr: "bar",
|
|
|
|
StatsiteAddr: "foo",
|
|
|
|
DisableHostname: false,
|
|
|
|
DogStatsDAddr: "127.0.0.1:7254",
|
|
|
|
DogStatsDTags: []string{"tag_1:val_1", "tag_2:val_2"},
|
|
|
|
},
|
|
|
|
|
|
|
|
DisableCache: true,
|
|
|
|
DisableCacheRaw: true,
|
|
|
|
DisableMlock: true,
|
|
|
|
DisableMlockRaw: true,
|
|
|
|
EnableUI: true,
|
|
|
|
EnableUIRaw: true,
|
|
|
|
|
|
|
|
EnableRawEndpoint: true,
|
|
|
|
EnableRawEndpointRaw: true,
|
|
|
|
|
|
|
|
MaxLeaseTTL: 10 * time.Hour,
|
|
|
|
MaxLeaseTTLRaw: "10h",
|
|
|
|
DefaultLeaseTTL: 10 * time.Hour,
|
|
|
|
DefaultLeaseTTLRaw: "10h",
|
|
|
|
ClusterName: "testcluster",
|
|
|
|
|
|
|
|
PidFile: "./pidfile",
|
|
|
|
|
|
|
|
APIAddr: "top_level_api_addr",
|
|
|
|
ClusterAddr: "top_level_cluster_addr",
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
t.Fatalf("expected \n\n%#v\n\n to be \n\n%#v\n\n", config, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 22:21:11 +00:00
|
|
|
func TestLoadConfigFile_json(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config.hcl.json", logger)
|
2015-03-12 22:21:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2017-06-22 19:29:53 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
Storage: &Storage{
|
2015-03-12 22:21:11 +00:00
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
2016-08-15 13:42:42 +00:00
|
|
|
DisableClustering: true,
|
2015-03-12 22:21:11 +00:00
|
|
|
},
|
2015-07-14 22:27:18 +00:00
|
|
|
|
2017-08-30 20:28:23 +00:00
|
|
|
ClusterCipherSuites: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
|
|
|
|
|
2015-07-14 22:27:18 +00:00
|
|
|
Telemetry: &Telemetry{
|
2016-07-22 19:49:23 +00:00
|
|
|
StatsiteAddr: "baz",
|
|
|
|
StatsdAddr: "",
|
|
|
|
DisableHostname: false,
|
|
|
|
CirconusAPIToken: "",
|
|
|
|
CirconusAPIApp: "",
|
|
|
|
CirconusAPIURL: "",
|
|
|
|
CirconusSubmissionInterval: "",
|
|
|
|
CirconusCheckSubmissionURL: "",
|
|
|
|
CirconusCheckID: "",
|
|
|
|
CirconusCheckForceMetricActivation: "",
|
|
|
|
CirconusCheckInstanceID: "",
|
|
|
|
CirconusCheckSearchTag: "",
|
2016-11-10 21:17:55 +00:00
|
|
|
CirconusCheckDisplayName: "",
|
|
|
|
CirconusCheckTags: "",
|
2016-07-22 19:49:23 +00:00
|
|
|
CirconusBrokerID: "",
|
|
|
|
CirconusBrokerSelectTag: "",
|
2015-07-14 22:27:18 +00:00
|
|
|
},
|
2015-07-30 13:42:49 +00:00
|
|
|
|
2017-09-16 21:09:37 +00:00
|
|
|
MaxLeaseTTL: 10 * time.Hour,
|
|
|
|
MaxLeaseTTLRaw: "10h",
|
|
|
|
DefaultLeaseTTL: 10 * time.Hour,
|
|
|
|
DefaultLeaseTTLRaw: "10h",
|
|
|
|
ClusterName: "testcluster",
|
|
|
|
DisableCacheRaw: interface{}(nil),
|
|
|
|
DisableMlockRaw: interface{}(nil),
|
|
|
|
EnableUI: true,
|
|
|
|
EnableUIRaw: true,
|
|
|
|
PidFile: "./pidfile",
|
2017-09-15 04:21:35 +00:00
|
|
|
EnableRawEndpoint: true,
|
|
|
|
EnableRawEndpointRaw: true,
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
2016-03-09 23:59:44 +00:00
|
|
|
t.Fatalf("expected \n\n%#v\n\n to be \n\n%#v\n\n", config, expected)
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_json2(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config2.hcl.json", logger)
|
2015-03-12 22:21:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2017-06-22 19:29:53 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
2016-03-10 22:36:10 +00:00
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2017-06-22 19:29:53 +00:00
|
|
|
Config: map[string]interface{}{
|
2016-03-10 22:36:10 +00:00
|
|
|
"address": "127.0.0.1:444",
|
|
|
|
},
|
|
|
|
},
|
2015-03-12 22:21:11 +00:00
|
|
|
},
|
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
Storage: &Storage{
|
2015-03-12 22:21:11 +00:00
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
2016-08-15 13:42:42 +00:00
|
|
|
DisableClustering: true,
|
2015-03-12 22:21:11 +00:00
|
|
|
},
|
2015-07-14 22:27:18 +00:00
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
HAStorage: &Storage{
|
2015-12-11 20:58:10 +00:00
|
|
|
Type: "consul",
|
|
|
|
Config: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-08-26 14:27:06 +00:00
|
|
|
CacheSize: 45678,
|
|
|
|
|
2017-02-24 15:45:29 +00:00
|
|
|
EnableUI: true,
|
|
|
|
|
2017-09-15 04:21:35 +00:00
|
|
|
EnableRawEndpoint: true,
|
|
|
|
|
2015-07-14 22:27:18 +00:00
|
|
|
Telemetry: &Telemetry{
|
2016-07-22 19:49:23 +00:00
|
|
|
StatsiteAddr: "foo",
|
|
|
|
StatsdAddr: "bar",
|
|
|
|
DisableHostname: true,
|
|
|
|
CirconusAPIToken: "0",
|
|
|
|
CirconusAPIApp: "vault",
|
|
|
|
CirconusAPIURL: "http://api.circonus.com/v2",
|
|
|
|
CirconusSubmissionInterval: "10s",
|
|
|
|
CirconusCheckSubmissionURL: "https://someplace.com/metrics",
|
|
|
|
CirconusCheckID: "0",
|
|
|
|
CirconusCheckForceMetricActivation: "true",
|
|
|
|
CirconusCheckInstanceID: "node1:vault",
|
|
|
|
CirconusCheckSearchTag: "service:vault",
|
2016-11-10 21:17:55 +00:00
|
|
|
CirconusCheckDisplayName: "node1:vault",
|
|
|
|
CirconusCheckTags: "cat1:tag1,cat2:tag2",
|
2016-07-22 19:49:23 +00:00
|
|
|
CirconusBrokerID: "0",
|
|
|
|
CirconusBrokerSelectTag: "dc:sfo",
|
2015-07-14 22:27:18 +00:00
|
|
|
},
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigDir(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
|
|
|
config, err := LoadConfigDir("./test-fixtures/config-dir", logger)
|
2015-03-12 22:21:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
2015-10-12 16:55:02 +00:00
|
|
|
DisableCache: true,
|
2015-07-30 13:42:49 +00:00
|
|
|
DisableMlock: true,
|
|
|
|
|
2015-03-12 22:21:11 +00:00
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2017-06-22 19:29:53 +00:00
|
|
|
Config: map[string]interface{}{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-03-08 14:17:00 +00:00
|
|
|
Storage: &Storage{
|
2015-03-12 22:21:11 +00:00
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
2016-10-02 18:54:01 +00:00
|
|
|
DisableClustering: true,
|
2015-03-12 22:21:11 +00:00
|
|
|
},
|
2015-07-14 22:27:18 +00:00
|
|
|
|
2017-02-24 15:45:29 +00:00
|
|
|
EnableUI: true,
|
|
|
|
|
2017-09-15 04:21:35 +00:00
|
|
|
EnableRawEndpoint: true,
|
|
|
|
|
2015-07-14 22:27:18 +00:00
|
|
|
Telemetry: &Telemetry{
|
2015-08-27 14:50:16 +00:00
|
|
|
StatsiteAddr: "qux",
|
|
|
|
StatsdAddr: "baz",
|
2015-07-14 22:27:18 +00:00
|
|
|
DisableHostname: true,
|
|
|
|
},
|
2015-07-30 13:42:49 +00:00
|
|
|
|
2015-08-27 14:50:16 +00:00
|
|
|
MaxLeaseTTL: 10 * time.Hour,
|
|
|
|
DefaultLeaseTTL: 10 * time.Hour,
|
2016-07-26 15:38:24 +00:00
|
|
|
ClusterName: "testcluster",
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
2016-08-15 13:42:42 +00:00
|
|
|
t.Fatalf("expected \n\n%#v\n\n to be \n\n%#v\n\n", config, expected)
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 23:59:44 +00:00
|
|
|
|
2017-08-03 11:33:06 +00:00
|
|
|
func TestParseListeners(t *testing.T) {
|
|
|
|
obj, _ := hcl.Parse(strings.TrimSpace(`
|
|
|
|
listener "tcp" {
|
|
|
|
address = "127.0.0.1:443"
|
|
|
|
cluster_address = "127.0.0.1:8201"
|
|
|
|
tls_disable = false
|
|
|
|
tls_cert_file = "./certs/server.crt"
|
|
|
|
tls_key_file = "./certs/server.key"
|
|
|
|
tls_client_ca_file = "./certs/rootca.crt"
|
|
|
|
tls_min_version = "tls12"
|
2017-09-25 18:41:46 +00:00
|
|
|
tls_require_and_verify_client_cert = true
|
|
|
|
tls_disable_client_certs = true
|
2017-08-03 11:33:06 +00:00
|
|
|
}`))
|
|
|
|
|
|
|
|
var config Config
|
|
|
|
list, _ := obj.Node.(*ast.ObjectList)
|
|
|
|
objList := list.Filter("listener")
|
|
|
|
parseListeners(&config, objList)
|
|
|
|
listeners := config.Listeners
|
|
|
|
if len(listeners) == 0 {
|
|
|
|
t.Fatalf("expected at least one listener in the config")
|
|
|
|
}
|
|
|
|
listener := listeners[0]
|
|
|
|
if listener.Type != "tcp" {
|
|
|
|
t.Fatalf("expected tcp listener in the config")
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
"cluster_address": "127.0.0.1:8201",
|
|
|
|
"tls_disable": false,
|
|
|
|
"tls_cert_file": "./certs/server.crt",
|
|
|
|
"tls_key_file": "./certs/server.key",
|
|
|
|
"tls_client_ca_file": "./certs/rootca.crt",
|
|
|
|
"tls_min_version": "tls12",
|
|
|
|
"tls_require_and_verify_client_cert": true,
|
2017-09-25 18:41:46 +00:00
|
|
|
"tls_disable_client_certs": true,
|
2017-08-03 11:33:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(config, *expected) {
|
|
|
|
t.Fatalf("expected \n\n%#v\n\n to be \n\n%#v\n\n", config, *expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:59:44 +00:00
|
|
|
func TestParseConfig_badTopLevel(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
2016-03-09 23:59:44 +00:00
|
|
|
_, err := ParseConfig(strings.TrimSpace(`
|
|
|
|
backend {}
|
|
|
|
bad = "one"
|
|
|
|
nope = "yes"
|
2016-08-19 20:45:17 +00:00
|
|
|
`), logger)
|
2016-03-09 23:59:44 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "invalid key 'bad' on line 2") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "invalid key 'nope' on line 3") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig_badListener(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
2016-03-09 23:59:44 +00:00
|
|
|
_, err := ParseConfig(strings.TrimSpace(`
|
|
|
|
listener "tcp" {
|
|
|
|
address = "1.2.3.3"
|
|
|
|
bad = "one"
|
|
|
|
nope = "yes"
|
|
|
|
}
|
2016-08-19 20:45:17 +00:00
|
|
|
`), logger)
|
2016-03-09 23:59:44 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "listeners.tcp: invalid key 'bad' on line 3") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "listeners.tcp: invalid key 'nope' on line 4") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseConfig_badTelemetry(t *testing.T) {
|
2016-08-19 20:45:17 +00:00
|
|
|
logger := logformat.NewVaultLogger(log.LevelTrace)
|
|
|
|
|
2016-03-09 23:59:44 +00:00
|
|
|
_, err := ParseConfig(strings.TrimSpace(`
|
|
|
|
telemetry {
|
|
|
|
statsd_address = "1.2.3.3"
|
|
|
|
bad = "one"
|
|
|
|
nope = "yes"
|
|
|
|
}
|
2016-08-19 20:45:17 +00:00
|
|
|
`), logger)
|
2016-03-09 23:59:44 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "telemetry: invalid key 'bad' on line 3") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "telemetry: invalid key 'nope' on line 4") {
|
|
|
|
t.Errorf("bad error: %q", err)
|
|
|
|
}
|
|
|
|
}
|