Commit c9097f58 authored by Yacov Manevich's avatar Yacov Manevich Committed by Gerrit Code Review
Browse files

Merge "[FAB-6746] Fix modification of root config group"

parents d558e44c c7897ee1
......@@ -176,13 +176,11 @@ func (cm *configManager) policyForItem(item comparable) (policies.Policy, bool)
logger.Debugf("Getting policy for item %s with mod_policy %s", item.key, modPolicy)
// If the mod_policy path is relative, get the right manager for the context
// if the mod_policy path is absolute (starts with /) evaluate at the root
if len(modPolicy) > 0 && modPolicy[0] != policies.PathSeparator[0] {
// path should always be at least length 1, panic if not
if len(item.path) == 0 {
logger.Panicf("Empty path for item %s", item.key)
}
// If the item has a zero length path, it is the root group, use the base policy manager
// if the mod_policy path is absolute (starts with /) also use the base policy manager
if len(modPolicy) > 0 && modPolicy[0] != policies.PathSeparator[0] && len(item.path) != 0 {
var ok bool
manager, ok = manager.Manager(item.path[1:])
if !ok {
logger.Debugf("Could not find manager at path: %v", item.path[1:])
......
......@@ -196,17 +196,16 @@ func TestPolicyForItem(t *testing.T) {
assert.Equal(t, policy, fooPolicy, "Should have found relative foo policy for foo group")
})
t.Run("Empty item path", func(t *testing.T) {
policyForItemEmptyPath := func() {
cm.policyForItem(comparable{
key: "foo",
path: []string{},
ConfigGroup: &cb.ConfigGroup{
ModPolicy: "foo",
},
})
}
assert.Panics(t, policyForItemEmptyPath)
t.Run("Root group manager", func(t *testing.T) {
policy, ok := cm.policyForItem(comparable{
path: []string{},
key: "root",
ConfigGroup: &cb.ConfigGroup{
ModPolicy: "rootPolicy",
},
})
assert.True(t, ok)
assert.Equal(t, policy, rootPolicy, "Should have found relative policy off the root manager")
})
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment