diff --git a/changelog/17660.txt b/changelog/17660.txt new file mode 100644 index 000000000..59ac66456 --- /dev/null +++ b/changelog/17660.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fixes spurious warnings being emitted relating to "unknown or unsupported fields" for JSON config +``` diff --git a/command/server/config_test.go b/command/server/config_test.go index e8e80cc99..073d52a7f 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -56,6 +56,14 @@ func TestUnknownFieldValidation(t *testing.T) { testUnknownFieldValidation(t) } +func TestUnknownFieldValidationJson(t *testing.T) { + testUnknownFieldValidationJson(t) +} + +func TestUnknownFieldValidationHcl(t *testing.T) { + testUnknownFieldValidationHcl(t) +} + func TestUnknownFieldValidationListenerAndStorage(t *testing.T) { testUnknownFieldValidationStorageAndListener(t) } diff --git a/command/server/config_test_helpers.go b/command/server/config_test_helpers.go index c45919826..bb6e273a6 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -534,6 +534,37 @@ func testUnknownFieldValidation(t *testing.T) { } } +// testUnknownFieldValidationJson tests that this valid json config does not result in +// errors. Prior to VAULT-8519, it reported errors even with a valid config that was +// parsed properly. +func testUnknownFieldValidationJson(t *testing.T) { + config, err := LoadConfigFile("./test-fixtures/config_small.json") + if err != nil { + t.Fatalf("err: %s", err) + } + + errors := config.Validate("./test-fixtures/config_small.json") + if errors != nil { + t.Fatal(errors) + } +} + +// testUnknownFieldValidationHcl tests that this valid hcl config does not result in +// errors. Prior to VAULT-8519, the json version of this config reported errors even +// with a valid config that was parsed properly. +// In short, this ensures the same for HCL as we test in testUnknownFieldValidationJson +func testUnknownFieldValidationHcl(t *testing.T) { + config, err := LoadConfigFile("./test-fixtures/config_small.hcl") + if err != nil { + t.Fatalf("err: %s", err) + } + + errors := config.Validate("./test-fixtures/config_small.hcl") + if errors != nil { + t.Fatal(errors) + } +} + func testLoadConfigFile_json(t *testing.T) { config, err := LoadConfigFile("./test-fixtures/config.hcl.json") if err != nil { diff --git a/command/server/test-fixtures/config_small.hcl b/command/server/test-fixtures/config_small.hcl new file mode 100644 index 000000000..cfbc28db8 --- /dev/null +++ b/command/server/test-fixtures/config_small.hcl @@ -0,0 +1,15 @@ +storage "raft" { + path = "/path/to/raft" + node_id = "raft_node_1" +} +listener "tcp" { + address = "127.0.0.1:8200" + tls_cert_file = "/path/to/cert.pem" + tls_key_file = "/path/to/key.key" +} +seal "awskms" { + kms_key_id = "alias/kms-unseal-key" +} +service_registration "consul" { + address = "127.0.0.1:8500" +} diff --git a/command/server/test-fixtures/config_small.json b/command/server/test-fixtures/config_small.json new file mode 100644 index 000000000..b9366bd08 --- /dev/null +++ b/command/server/test-fixtures/config_small.json @@ -0,0 +1,31 @@ +{ + "listener": { + "tcp": { + "address": "0.0.0.0:8200", + "tls_cert_file": "/path/to/cert.pem", + "tls_key_file": "/path/to/key.key" + } + }, + + "seal": { + "awskms": { + "kms_key_id": "alias/kms-unseal-key" + } + }, + + "storage": { + "raft": { + "path": "/path/to/raft", + "node_id": "raft_node_1" + } + }, + + "cluster_addr": "http://127.0.0.1:8201", + "api_addr": "http://127.0.0.1:8200", + + "service_registration": { + "consul": { + "address": "127.0.0.1:8500" + } + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index 5064ce9d7..3c8203b94 100644 --- a/go.mod +++ b/go.mod @@ -97,7 +97,7 @@ require ( github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/hashicorp/hcl v1.0.1-vault-3 + github.com/hashicorp/hcl v1.0.1-vault-5 github.com/hashicorp/hcp-sdk-go v0.22.0 github.com/hashicorp/nomad/api v0.0.0-20220707195938-75f4c2237b28 github.com/hashicorp/raft v1.3.10 diff --git a/go.sum b/go.sum index 3ba19416b..1ccbcf7a5 100644 --- a/go.sum +++ b/go.sum @@ -1066,8 +1066,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl v1.0.1-vault-3 h1:V95v5KSTu6DB5huDSKiq4uAfILEuNigK/+qPET6H/Mg= -github.com/hashicorp/hcl v1.0.1-vault-3/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM= +github.com/hashicorp/hcl v1.0.1-vault-5 h1:kI3hhbbyzr4dldA8UdTb7ZlVVlI2DACdCfz31RPDgJM= +github.com/hashicorp/hcl v1.0.1-vault-5/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM= github.com/hashicorp/hcp-sdk-go v0.22.0 h1:LWkLOkJFYWSojBM3IkwvYK6nrwrL+p4Fw8zEaoCQG10= github.com/hashicorp/hcp-sdk-go v0.22.0/go.mod h1:mM3nYdVHuv2X2tv88MGVKRf/o2k3zF8jUZSMkwICQ28= github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d h1:9ARUJJ1VVynB176G1HCwleORqCaXm/Vx0uUi0dL26I0=