@@ -112,6 +112,9 @@ func (cs *cryptoService) VerifyByChannel(channel common.ChainID, identity api.Pe
112112 return nil
113113 }
114114 args := cs .Called (identity )
115+ if args .Get (0 ) == nil {
116+ return nil
117+ }
115118 return args .Get (0 ).(error )
116119}
117120
@@ -222,6 +225,9 @@ func (ga *gossipAdapterMock) GetOrgOfPeer(PKIIID common.PKIidType) api.OrgIdenti
222225}
223226
224227func (ga * gossipAdapterMock ) GetIdentityByPKIID (pkiID common.PKIidType ) api.PeerIdentityType {
228+ if ga .wasMocked ("GetIdentityByPKIID" ) {
229+ return ga .Called (pkiID ).Get (0 ).(api.PeerIdentityType )
230+ }
225231 return api .PeerIdentityType (pkiID )
226232}
227233
@@ -676,10 +682,12 @@ func TestChannelPeerNotInChannel(t *testing.T) {
676682
677683 // Now for a more advanced scenario- the peer claims to be in the right org, and also claims to be in the channel
678684 // but the MSP declares it is not eligible for the channel
679- // pkiIDInOrg1ButNotEligible
680685 gc .HandleMessage (& receivedMsg {msg : createStateInfoMsg (10 , pkiIDInOrg1ButNotEligible , channelA ), PKIID : pkiIDInOrg1ButNotEligible })
686+ // configure MSP
681687 cs .On ("VerifyByChannel" , mock .Anything ).Return (errors .New ("Not eligible" ))
682688 cs .mocked = true
689+ // Simulate a config update
690+ gc .ConfigureChannel (& joinChanMsg {})
683691 helloMsg = createHelloMsg (pkiIDInOrg1ButNotEligible )
684692 helloMsg .On ("Respond" , mock .Anything ).Run (messageRelayer )
685693 gc .HandleMessage (helloMsg )
@@ -1400,6 +1408,110 @@ func TestChannelNoAnchorPeers(t *testing.T) {
14001408 assert .True (t , gc .IsOrgInChannel (orgInChannelA ))
14011409}
14021410
1411+ func TestGossipChannelEligibility (t * testing.T ) {
1412+ t .Parallel ()
1413+
1414+ // Scenario: We have a peer in an org that joins a channel with org1 and org2.
1415+ // and it receives StateInfo messages of other peers and the eligibility
1416+ // of these peers of being in the channel is checked.
1417+ // During the test, the channel is reconfigured, and the expiration
1418+ // of the peer identities is simulated.
1419+
1420+ cs := & cryptoService {}
1421+ selfPKIID := common .PKIidType ("p" )
1422+ adapter := new (gossipAdapterMock )
1423+ pkiIDinOrg3 := common .PKIidType ("pkiIDinOrg3" )
1424+ members := []discovery.NetworkMember {
1425+ {PKIid : pkiIDInOrg1 },
1426+ {PKIid : pkiIDInOrg1ButNotEligible },
1427+ {PKIid : pkiIDinOrg2 },
1428+ }
1429+ adapter .On ("GetMembership" ).Return (members )
1430+ adapter .On ("Gossip" , mock .Anything )
1431+ adapter .On ("Send" , mock .Anything , mock .Anything )
1432+ adapter .On ("DeMultiplex" , mock .Anything )
1433+ adapter .On ("GetConf" ).Return (conf )
1434+
1435+ // At first, all peers are in the channel except pkiIDinOrg3
1436+ org1 := api .OrgIdentityType ("ORG1" )
1437+ org2 := api .OrgIdentityType ("ORG2" )
1438+ org3 := api .OrgIdentityType ("ORG3" )
1439+
1440+ adapter .On ("GetOrgOfPeer" , selfPKIID ).Return (org1 )
1441+ adapter .On ("GetOrgOfPeer" , pkiIDInOrg1 ).Return (org1 )
1442+ adapter .On ("GetOrgOfPeer" , pkiIDinOrg2 ).Return (org2 )
1443+ adapter .On ("GetOrgOfPeer" , pkiIDInOrg1ButNotEligible ).Return (org1 )
1444+ adapter .On ("GetOrgOfPeer" , pkiIDinOrg3 ).Return (org3 )
1445+
1446+ gc := NewGossipChannel (selfPKIID , orgInChannelA , cs , channelA , adapter , & joinChanMsg {
1447+ members2AnchorPeers : map [string ][]api.AnchorPeer {
1448+ string (org1 ): {},
1449+ string (org2 ): {},
1450+ },
1451+ })
1452+ // Every peer sends a StateInfo message
1453+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDInOrg1 , channelA )})
1454+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDinOrg2 , channelA )})
1455+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDInOrg1ButNotEligible , channelA )})
1456+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDinOrg3 , channelA )})
1457+
1458+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1 }))
1459+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg2 }))
1460+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1ButNotEligible }))
1461+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg3 }))
1462+
1463+ // Remove org2 from the channel
1464+ gc .ConfigureChannel (& joinChanMsg {
1465+ members2AnchorPeers : map [string ][]api.AnchorPeer {
1466+ string (org1 ): {},
1467+ },
1468+ })
1469+
1470+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1 }))
1471+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg2 }))
1472+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1ButNotEligible }))
1473+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg3 }))
1474+
1475+ // Now simulate a config update that removed pkiIDInOrg1ButNotEligible from the channel readers
1476+ cs .mocked = true
1477+ cs .On ("VerifyByChannel" , api .PeerIdentityType (pkiIDInOrg1ButNotEligible )).Return (errors .New ("Not a channel reader" ))
1478+ cs .On ("VerifyByChannel" , mock .Anything ).Return (nil )
1479+ gc .ConfigureChannel (& joinChanMsg {
1480+ members2AnchorPeers : map [string ][]api.AnchorPeer {
1481+ string (org1 ): {},
1482+ },
1483+ })
1484+ assert .True (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1 }))
1485+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg2 }))
1486+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1ButNotEligible }))
1487+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg3 }))
1488+
1489+ // Now Simulate a certificate expiration of pkiIDInOrg1.
1490+ // This is done by asking the adapter to lookup the identity by PKI-ID, but if the certificate
1491+ // is expired, the mapping is deleted and hence the lookup yields nothing.
1492+ adapter .On ("GetIdentityByPKIID" , pkiIDInOrg1 ).Return (api .PeerIdentityType (nil ))
1493+ adapter .On ("GetIdentityByPKIID" , pkiIDinOrg2 ).Return (api .PeerIdentityType (pkiIDinOrg2 ))
1494+ adapter .On ("GetIdentityByPKIID" , pkiIDInOrg1ButNotEligible ).Return (api .PeerIdentityType (pkiIDInOrg1ButNotEligible ))
1495+ adapter .On ("GetIdentityByPKIID" , pkiIDinOrg3 ).Return (api .PeerIdentityType (pkiIDinOrg3 ))
1496+
1497+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1 }))
1498+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg2 }))
1499+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1ButNotEligible }))
1500+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg3 }))
1501+
1502+ // Now make another update of StateInfo messages, this time with updated ledger height (to overwrite earlier messages)
1503+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (2 , pkiIDInOrg1 , channelA )})
1504+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (2 , pkiIDinOrg2 , channelA )})
1505+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (2 , pkiIDInOrg1ButNotEligible , channelA )})
1506+ gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (2 , pkiIDinOrg3 , channelA )})
1507+
1508+ // Ensure the access control resolution hasn't changed
1509+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1 }))
1510+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg2 }))
1511+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDInOrg1ButNotEligible }))
1512+ assert .False (t , gc .EligibleForChannel (discovery.NetworkMember {PKIid : pkiIDinOrg3 }))
1513+ }
1514+
14031515func TestChannelGetPeers (t * testing.T ) {
14041516 t .Parallel ()
14051517
@@ -1420,7 +1532,7 @@ func TestChannelGetPeers(t *testing.T) {
14201532 {PKIid : pkiIDinOrg2 },
14211533 }
14221534 configureAdapter (adapter , members ... )
1423- gc := NewGossipChannel (pkiIDInOrg1 , orgInChannelA , cs , channelA , adapter , & joinChanMsg {})
1535+ gc := NewGossipChannel (common . PKIidType ( "p0" ) , orgInChannelA , cs , channelA , adapter , & joinChanMsg {})
14241536 gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDInOrg1 , channelA )})
14251537 gc .HandleMessage (& receivedMsg {PKIID : pkiIDInOrg1 , msg : createStateInfoMsg (1 , pkiIDinOrg2 , channelA )})
14261538 assert .Len (t , gc .GetPeers (), 1 )
@@ -1429,6 +1541,8 @@ func TestChannelGetPeers(t *testing.T) {
14291541 gc .HandleMessage (& receivedMsg {msg : createStateInfoMsg (10 , pkiIDInOrg1ButNotEligible , channelA ), PKIID : pkiIDInOrg1ButNotEligible })
14301542 cs .On ("VerifyByChannel" , mock .Anything ).Return (errors .New ("Not eligible" ))
14311543 cs .mocked = true
1544+ // Simulate a config update
1545+ gc .ConfigureChannel (& joinChanMsg {})
14321546 assert .Len (t , gc .GetPeers (), 0 )
14331547
14341548 // Now recreate gc and corrupt the MAC
0 commit comments