Skip to content

Commit ab837c1

Browse files
author
Jason Yellick
committed
[FAB-8027] Check for empty channel group
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>
1 parent 30dd68f commit ab837c1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

common/tools/configtxlator/update/update.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ func computeGroupUpdate(original, updated *cb.ConfigGroup) (readSet, writeSet *c
223223
}
224224

225225
func Compute(original, updated *cb.Config) (*cb.ConfigUpdate, error) {
226+
if original.ChannelGroup == nil {
227+
return nil, fmt.Errorf("no channel group included for original config")
228+
}
229+
230+
if updated.ChannelGroup == nil {
231+
return nil, fmt.Errorf("no channel group included for updated config")
232+
}
233+
226234
readSet, writeSet, groupUpdated := computeGroupUpdate(original.ChannelGroup, updated.ChannelGroup)
227235
if !groupUpdated {
228236
return nil, fmt.Errorf("no differences detected between original and updated config")

common/tools/configtxlator/update/update_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ func TestNoUpdate(t *testing.T) {
3939
assert.Error(t, err)
4040
}
4141

42+
func TestMissingGroup(t *testing.T) {
43+
group := &cb.ConfigGroup{}
44+
t.Run("MissingOriginal", func(t *testing.T) {
45+
_, err := Compute(&cb.Config{}, &cb.Config{ChannelGroup: group})
46+
47+
assert.Error(t, err)
48+
assert.Regexp(t, "no channel group included for original config", err.Error())
49+
})
50+
t.Run("MissingOriginal", func(t *testing.T) {
51+
_, err := Compute(&cb.Config{ChannelGroup: group}, &cb.Config{})
52+
53+
assert.Error(t, err)
54+
assert.Regexp(t, "no channel group included for updated config", err.Error())
55+
})
56+
}
57+
4258
func TestGroupModPolicyUpdate(t *testing.T) {
4359
original := &cb.ConfigGroup{
4460
Version: 7,

0 commit comments

Comments
 (0)