Skip to content

Commit

Permalink
backport of commit 50a2bb5 (#17698)
Browse files Browse the repository at this point in the history
Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
  • Loading branch information
1 parent c85aed2 commit ed69142
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/17660.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Fixes spurious warnings being emitted relating to "unknown or unsupported fields" for JSON config
```
8 changes: 8 additions & 0 deletions command/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
31 changes: 31 additions & 0 deletions command/server/config_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions command/server/test-fixtures/config_small.hcl
Original file line number Diff line number Diff line change
@@ -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"
}
31 changes: 31 additions & 0 deletions command/server/test-fixtures/config_small.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,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=
Expand Down

0 comments on commit ed69142

Please sign in to comment.