Skip to content

Commit

Permalink
[FAB-6746] Fix modification of root config group
Browse files Browse the repository at this point in the history
A recent change was made to the configtx processing which causes a panic
when the path of a config element is empty.  This case can never happen
for any config element, except for the very root config element.  This
CR modifies the code to simply not traverse the policy manager selection
code if the path is empty, as this indicates the element is part of the
root policy manager.

Change-Id: Ibc73ad155a51b79051c83a84cd8d615d432506e2
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Oct 24, 2017
1 parent e9fb0be commit c7897ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
10 changes: 4 additions & 6 deletions common/configtx/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down
21 changes: 10 additions & 11 deletions common/configtx/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}

Expand Down

0 comments on commit c7897ee

Please sign in to comment.