Skip to content

Commit

Permalink
[FAB-18264] Allow cb.Config with no ACLs to be loaded (#38)
Browse files Browse the repository at this point in the history
This patch allows Config Transaction Library to load cb.Config
which does not contain any values for ACLs.

Signed-off-by: Tatsuya Sato <Tatsuya.Sato@hal.hitachi.com>
  • Loading branch information
satota2 committed Oct 8, 2020
1 parent ac4b35d commit a053a30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions configtx/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,16 @@ func (a *ApplicationOrg) RemoveAnchorPeer(anchorPeerToRemove Address) error {

// ACLs returns a map of ACLS for given config application.
func (a *ApplicationGroup) ACLs() (map[string]string, error) {
aclConfigValue, ok := a.applicationGroup.Values[ACLsKey]
if !ok {
return nil, nil
}

aclProtos := &pb.ACLs{}

err := unmarshalConfigValueAtKey(a.applicationGroup, ACLsKey, aclProtos)
err := proto.Unmarshal(aclConfigValue.Value, aclProtos)
if err != nil {
return nil, err
return nil, fmt.Errorf("unmarshaling %s: %v", ACLsKey, err)
}

retACLs := map[string]string{}
Expand Down
25 changes: 25 additions & 0 deletions configtx/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,31 @@ func TestApplicationACLs(t *testing.T) {
gt.Expect(applicationACLs).To(Equal(baseApplicationConf.ACLs))
}

func TestEmptyApplicationACLs(t *testing.T) {
t.Parallel()

gt := NewGomegaWithT(t)

baseApplicationConf, _ := baseApplication(t)
baseApplicationConf.ACLs = nil
applicationGroup, err := newApplicationGroupTemplate(baseApplicationConf)
gt.Expect(err).NotTo(HaveOccurred())

config := &cb.Config{
ChannelGroup: &cb.ConfigGroup{
Groups: map[string]*cb.ConfigGroup{
ApplicationGroupKey: applicationGroup,
},
},
}

c := New(config)

applicationACLs, err := c.Application().ACLs()
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(applicationACLs).To(BeNil())
}

func TestApplicationACLsFailure(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a053a30

Please sign in to comment.