Skip to content

Commit

Permalink
Merge a4824c8 into backport/fix/gh-15210/sockaddr-template-parsing-wh…
Browse files Browse the repository at this point in the history
…en-needed/gladly-immense-gar
  • Loading branch information
hc-github-team-secure-vault-core committed Apr 29, 2022
2 parents 88d17de + a4824c8 commit 3a9c429
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog/15210.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
core/config: Handle case where config contains a non-template format value, only parse when it follows the format:
{{ ... }}
```
6 changes: 6 additions & 0 deletions internalshared/configutil/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,13 @@ func ParseListeners(result *SharedConfig, list *ast.ObjectList) error {

// ParseSingleIPTemplate is used as a helper function to parse out a single IP
// address from a config parameter.
// If the input doesn't appear to be 'template' format,
// it will return the specified input.
func ParseSingleIPTemplate(ipTmpl string) (string, error) {
if !(strings.HasPrefix(ipTmpl, "{{") && strings.HasSuffix(ipTmpl, "}}")) {
return ipTmpl, nil
}

out, err := template.Parse(ipTmpl)
if err != nil {
return "", fmt.Errorf("unable to parse address template %q: %v", ipTmpl, err)
Expand Down
49 changes: 49 additions & 0 deletions internalshared/configutil/listener_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package configutil

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseSingleIPTemplate(t *testing.T) {
type args struct {
ipTmpl string
}
tests := []struct {
name string
args args
want string
wantErr assert.ErrorAssertionFunc
}{
{
name: "test non-template addr",
args: args{"vaultproject.io"},
want: "vaultproject.io",
wantErr: assert.NoError,
},
{
name: "test invalid template func",
args: args{"{{FooBar}}"},
want: "",
wantErr: assert.Error,
},
{
name: "test partial template",
args: args{"{{FooBar"},
want: "{{FooBar",
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseSingleIPTemplate(tt.args.ipTmpl)
if !tt.wantErr(t, err, fmt.Sprintf("ParseSingleIPTemplate(%v)", tt.args.ipTmpl)) {
return
}

assert.Equalf(t, tt.want, got, "ParseSingleIPTemplate(%v)", tt.args.ipTmpl)
})
}
}
1 change: 0 additions & 1 deletion sdk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ github.com/hashicorp/go-secure-stdlib/base62 v0.1.1 h1:6KMBnfEv0/kLAz0O76sliN5mX
github.com/hashicorp/go-secure-stdlib/base62 v0.1.1/go.mod h1:EdWO6czbmthiwZ3/PUsDV+UD1D5IRU4ActiaWGwt0Yw=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.1 h1:cCRo8gK7oq6A2L6LICkUZ+/a5rLiRXFMf1Qd4xSwxTc=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.1/go.mod h1:zq93CJChV6L9QTfGKtfBxKqD7BqqXx5O04A/ns2p5+I=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1 h1:78ki3QBevHwYrVxnyVeaEz+7WtifHhauYF23es/0KlI=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.4 h1:hrIH/qrOTHfG9a1Jz6Z2jQf7Xe77AaD464W1fCFLwPQ=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.4/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8=
Expand Down

0 comments on commit 3a9c429

Please sign in to comment.