Skip to content

Commit

Permalink
[FAB-8027] Check for empty channel group
Browse files Browse the repository at this point in the history
Although any well formed channel config will have a non-empty channel
group, the config update computation code should not assume that it is
well formed.  This CR simply adds nil checking over the channel group
fields.

Change-Id: I9a470d5cf6a559be1bcbbbdf919ac5670c90da1a
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 1, 2018
1 parent 30dd68f commit ab837c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/tools/configtxlator/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ func computeGroupUpdate(original, updated *cb.ConfigGroup) (readSet, writeSet *c
}

func Compute(original, updated *cb.Config) (*cb.ConfigUpdate, error) {
if original.ChannelGroup == nil {
return nil, fmt.Errorf("no channel group included for original config")
}

if updated.ChannelGroup == nil {
return nil, fmt.Errorf("no channel group included for updated config")
}

readSet, writeSet, groupUpdated := computeGroupUpdate(original.ChannelGroup, updated.ChannelGroup)
if !groupUpdated {
return nil, fmt.Errorf("no differences detected between original and updated config")
Expand Down
16 changes: 16 additions & 0 deletions common/tools/configtxlator/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func TestNoUpdate(t *testing.T) {
assert.Error(t, err)
}

func TestMissingGroup(t *testing.T) {
group := &cb.ConfigGroup{}
t.Run("MissingOriginal", func(t *testing.T) {
_, err := Compute(&cb.Config{}, &cb.Config{ChannelGroup: group})

assert.Error(t, err)
assert.Regexp(t, "no channel group included for original config", err.Error())
})
t.Run("MissingOriginal", func(t *testing.T) {
_, err := Compute(&cb.Config{ChannelGroup: group}, &cb.Config{})

assert.Error(t, err)
assert.Regexp(t, "no channel group included for updated config", err.Error())
})
}

func TestGroupModPolicyUpdate(t *testing.T) {
original := &cb.ConfigGroup{
Version: 7,
Expand Down

0 comments on commit ab837c1

Please sign in to comment.