validate args before deleting proxy defaults (#14290)
* validate args before deleting proxy defaults * add changelog * validate name when normalizing proxy defaults * add test for proxyConfigEntry * add comments
This commit is contained in:
parent
7ccf92c66b
commit
ad30192499
|
@ -0,0 +1,3 @@
|
|||
```release-note:bugfix
|
||||
envoy: validate name before deleting proxy default configurations.
|
||||
```
|
|
@ -3,12 +3,13 @@ package structs
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/miekg/dns"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/mitchellh/hashstructure"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -362,6 +363,13 @@ func (e *ProxyConfigEntry) Normalize() error {
|
|||
}
|
||||
|
||||
e.Kind = ProxyDefaults
|
||||
|
||||
// proxy default config only accepts global configs
|
||||
// this check is replicated in normalize() and validate(),
|
||||
// since validate is not called by all the endpoints (e.g., delete)
|
||||
if e.Name != "" && e.Name != ProxyConfigGlobal {
|
||||
return fmt.Errorf("invalid name (%q), only %q is supported", e.Name, ProxyConfigGlobal)
|
||||
}
|
||||
e.Name = ProxyConfigGlobal
|
||||
|
||||
e.EnterpriseMeta.Normalize()
|
||||
|
|
|
@ -2944,6 +2944,27 @@ func TestParseUpstreamConfig(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProxyConfigEntry(t *testing.T) {
|
||||
cases := map[string]configEntryTestcase{
|
||||
"proxy config name provided is not global": {
|
||||
entry: &ProxyConfigEntry{
|
||||
Name: "foo",
|
||||
},
|
||||
normalizeErr: `invalid name ("foo"), only "global" is supported`,
|
||||
},
|
||||
"proxy config has no name": {
|
||||
entry: &ProxyConfigEntry{
|
||||
Name: "",
|
||||
},
|
||||
expected: &ProxyConfigEntry{
|
||||
Name: ProxyConfigGlobal,
|
||||
Kind: ProxyDefaults,
|
||||
},
|
||||
},
|
||||
}
|
||||
testConfigEntryNormalizeAndValidate(t, cases)
|
||||
}
|
||||
|
||||
func requireContainsLower(t *testing.T, haystack, needle string) {
|
||||
t.Helper()
|
||||
require.Contains(t, strings.ToLower(haystack), strings.ToLower(needle))
|
||||
|
|
Loading…
Reference in New Issue