Skip to content

Commit

Permalink
[FAB-2699] ConfigGroup mod policy resolve error
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2699

The ConfigGroup mod policy is currently resolved like the ConfigValue
and ConfigPolicy mod policies.  For ConfigValue and ConfigPolicy mod
policies, they look for the policy manager managing their config path.

However, ConfigGroups represents nodes in the config path, and therefore
they must resolve their policy manager by looking at their config path
plus their key value.

For example, the group /Channel/Orderer should resolve a mod policy of
Admins to /Channel/Orderer/Admins but it currently resolves it to
/Channel/Admins.

While on the other hand the value /Channel/Orderer/foo should resolve a
mod policy of Admins to /Channel/Orderer/Admins and not
/Channel/Orderer/foo/Admins (because foo is not a group node in the
config).

This CR fixes this mistake, enhances logging slightly, and adds a test
case.

Change-Id: I0d8b58f8ca21f78a8a2d7331e330fea4768ab973
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 8, 2017
1 parent f086f8b commit ae01f15
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/config/standardvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewStandardValues(protosStructs ...interface{}) (*standardValues, error) {
func (sv *standardValues) Deserialize(key string, value []byte) (proto.Message, error) {
msg, ok := sv.lookup[key]
if !ok {
return nil, fmt.Errorf("Not found")
return nil, fmt.Errorf("Unexpected key %s", key)
}

err := proto.Unmarshal(value, msg)
Expand Down
2 changes: 1 addition & 1 deletion common/configtx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func proposeGroup(result *configResult) error {
msg, err := valueDeserializer.Deserialize(key, value.Value)
if err != nil {
result.rollback()
return err
return fmt.Errorf("Error deserializing key %s for group %s: %s", key, result.groupName, err)
}
result.deserializedValues[key] = msg
}
Expand Down
8 changes: 8 additions & 0 deletions common/configtx/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func (cm *configManager) policyForItem(item comparable) (policies.Policy, bool)
if !ok {
return nil, ok
}

// In the case of the group type, its key is part of its path for the purposes of finding the policy manager
if item.ConfigGroup != nil {
manager, ok = manager.Manager([]string{item.key})
}
if !ok {
return nil, ok
}
return manager.GetPolicy(item.modPolicy())
}

Expand Down
10 changes: 10 additions & 0 deletions common/configtx/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,14 @@ func TestPolicyForItem(t *testing.T) {
})
assert.True(t, ok)
assert.Equal(t, policy, fooPolicy, "Should not have found relative foo policy the foo manager")

policy, ok = cm.policyForItem(comparable{
key: "foo",
path: []string{"root"},
ConfigGroup: &cb.ConfigGroup{
ModPolicy: "foo",
},
})
assert.True(t, ok)
assert.Equal(t, policy, fooPolicy, "Should have found relative foo policy for foo group")
}

0 comments on commit ae01f15

Please sign in to comment.