From 2f5e67534d0b52540122bdc33c9c6d6077e3e5bf Mon Sep 17 00:00:00 2001
From: Pierre Souchay
Date: Wed, 18 Apr 2018 22:57:33 +0200
Subject: [PATCH] Added unit tests for bad meta values
---
agent/config/builder.go | 2 +-
agent/config/runtime_test.go | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/agent/config/builder.go b/agent/config/builder.go
index 7b99b49602..d0a3a353de 100644
--- a/agent/config/builder.go
+++ b/agent/config/builder.go
@@ -999,7 +999,7 @@ func (b *Builder) serviceVal(v *ServiceDefinition) *structs.ServiceDefinition {
meta := make(map[string]string)
if err := structs.ValidateMetadata(v.Meta, false); err != nil {
- b.err = multierror.Append(fmt.Errorf("invalid meta for service %v: %v", v.Name, err))
+ b.err = multierror.Append(fmt.Errorf("invalid meta for service %s: %v", *v.Name, err))
} else {
meta = v.Meta
}
diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go
index 511ebc4a80..4306ce6ad9 100644
--- a/agent/config/runtime_test.go
+++ b/agent/config/runtime_test.go
@@ -1939,6 +1939,32 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
rt.DataDir = dataDir
},
},
+ {
+ desc: "service with wrong meta: too long",
+ args: []string{
+ `-data-dir=` + dataDir,
+ },
+ json: []string{
+ `{ "service": { "name": "a", "port": 80, "meta": { "a": "` + randomString(520) + `" } } }`,
+ },
+ hcl: []string{
+ `service = { name = "a" port = 80, meta={a="` + randomString(520) + `"} }`,
+ },
+ err: `Value is too long`,
+ },
+ {
+ desc: "service with wrong meta: too many meta",
+ args: []string{
+ `-data-dir=` + dataDir,
+ },
+ json: []string{
+ `{ "service": { "name": "a", "port": 80, "meta": { ` + metaPairs(70, "json") + `} } }`,
+ },
+ hcl: []string{
+ `service = { name = "a" port = 80 meta={` + metaPairs(70, "hcl") + `} }`,
+ },
+ err: `invalid meta for service a: Node metadata cannot contain more than 64 key`,
+ },
{
desc: "translated keys",
args: []string{