Skip to content

Commit

Permalink
[FAB-17059] Add missing mspID when init MembershipProvider.
Browse files Browse the repository at this point in the history
Signed-off-by: Hongbin Mao <hello2mao@gmail.com>
  • Loading branch information
hello2mao authored and sykesm committed May 28, 2020
1 parent 5b036f1 commit 41f8b0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/common/privdata/membershipinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type MembershipProvider struct {

// NewMembershipInfoProvider returns MembershipProvider
func NewMembershipInfoProvider(mspID string, selfSignedData protoutil.SignedData, identityDeserializerFunc func(chainID string) msp.IdentityDeserializer) *MembershipProvider {
return &MembershipProvider{selfSignedData: selfSignedData, IdentityDeserializerFactory: identityDeserializerFunc}
return &MembershipProvider{mspID: mspID, selfSignedData: selfSignedData, IdentityDeserializerFactory: identityDeserializerFunc}
}

// AmMemberOf checks whether the current peer is a member of the given collection config.
Expand Down
19 changes: 16 additions & 3 deletions core/common/privdata/membershipinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ func TestMembershipInfoProvider(t *testing.T) {
Signature: []byte{1, 2, 3},
Data: []byte{4, 5, 6},
}
emptyPeerSelfSignedData := protoutil.SignedData{}

identityDeserializer := func(chainID string) msp.IdentityDeserializer {
return &mockDeserializer{}
}

// verify membership provider returns true
membershipProvider := NewMembershipInfoProvider(mspID, peerSelfSignedData, identityDeserializer)
// verify membership provider pass simple check returns true
membershipProvider := NewMembershipInfoProvider(mspID, emptyPeerSelfSignedData, identityDeserializer)
res, err := membershipProvider.AmMemberOf("test1", getAccessPolicy([]string{"peer0", "peer1"}))
assert.True(t, res)
assert.Nil(t, err)

// verify membership provider returns false
// verify membership provider fall back to default access policy evaluation returns false
membershipProvider = NewMembershipInfoProvider(mspID, peerSelfSignedData, identityDeserializer)
res, err = membershipProvider.AmMemberOf("test1", getAccessPolicy([]string{"peer2", "peer3"}))
assert.False(t, res)
assert.Nil(t, err)
Expand All @@ -48,6 +50,17 @@ func TestMembershipInfoProvider(t *testing.T) {
res, err = membershipProvider.AmMemberOf("test1", getBadAccessPolicy([]string{"signer0"}, 1))
assert.False(t, res)
assert.Nil(t, err)

// verify membership provider with empty mspID and fall back to default access policy evaluation returns true
membershipProvider = NewMembershipInfoProvider("", peerSelfSignedData, identityDeserializer)
res, err = membershipProvider.AmMemberOf("test1", getAccessPolicy([]string{"peer0", "peer1"}))
assert.True(t, res)
assert.Nil(t, err)

// verify membership provider with empty mspID and fall back to default access policy evaluation returns false
res, err = membershipProvider.AmMemberOf("test1", getAccessPolicy([]string{"peer2", "peer3"}))
assert.False(t, res)
assert.Nil(t, err)
}

func getAccessPolicy(signers []string) *peer.CollectionPolicyConfig {
Expand Down

0 comments on commit 41f8b0a

Please sign in to comment.