mirror of https://github.com/hashicorp/consul
Reject inbound Prop Override patch with Services
Services filtering is only supported for outbound TrafficDirection patches.pull/17759/head
parent
fdde92c8c2
commit
97c779b5a2
|
@ -191,6 +191,10 @@ func (f *ResourceFilter) validate() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if len(f.Services) > 0 && f.TrafficDirection != extensioncommon.TrafficDirectionOutbound {
|
||||
return fmt.Errorf("patch contains non-empty ResourceFilter.Services but ResourceFilter.TrafficDirection is not %q",
|
||||
extensioncommon.TrafficDirectionOutbound)
|
||||
}
|
||||
for i := range f.Services {
|
||||
sn := f.Services[i]
|
||||
sn.normalize()
|
||||
|
|
|
@ -229,6 +229,20 @@ func TestConstructor(t *testing.T) {
|
|||
ok: false,
|
||||
errMsg: "service name is required",
|
||||
},
|
||||
"non-empty services with invalid traffic direction": {
|
||||
arguments: makeArguments(map[string]any{"Patches": []map[string]any{
|
||||
makePatch(map[string]any{
|
||||
"ResourceFilter": makeResourceFilter(map[string]any{
|
||||
"TrafficDirection": extensioncommon.TrafficDirectionInbound,
|
||||
"Services": []map[string]any{
|
||||
{"Name:": "foo"},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}}),
|
||||
ok: false,
|
||||
errMsg: "patch contains non-empty ResourceFilter.Services but ResourceFilter.TrafficDirection is not \"outbound\"",
|
||||
},
|
||||
// See decode.HookWeakDecodeFromSlice for more details. In practice, we can end up
|
||||
// with a "Patches" field decoded to the single "Patch" value contained in the
|
||||
// serialized slice (raised from the containing slice). Using WeakDecode solves
|
||||
|
|
Loading…
Reference in New Issue