@@ -13,6 +13,8 @@ import (
13
13
"testing"
14
14
"time"
15
15
16
+ "strings"
17
+
16
18
"github.com/hyperledger/fabric/gossip/api"
17
19
"github.com/hyperledger/fabric/gossip/common"
18
20
"github.com/hyperledger/fabric/gossip/util"
@@ -40,6 +42,19 @@ func init() {
40
42
msgCryptoService .On ("Expiration" , api .PeerIdentityType ("invalidIdentity" )).Return (time .Now ().Add (time .Hour ), nil )
41
43
}
42
44
45
+ func (cs * naiveCryptoService ) OrgByPeerIdentity (id api.PeerIdentityType ) api.OrgIdentityType {
46
+ found := false
47
+ for _ , call := range cs .Mock .ExpectedCalls {
48
+ if call .Method == "OrgByPeerIdentity" {
49
+ found = true
50
+ }
51
+ }
52
+ if ! found {
53
+ return nil
54
+ }
55
+ return cs .Called (id ).Get (0 ).(api.OrgIdentityType )
56
+ }
57
+
43
58
func (cs * naiveCryptoService ) Expiration (peerIdentity api.PeerIdentityType ) (time.Time , error ) {
44
59
args := cs .Called (peerIdentity )
45
60
t , err := args .Get (0 ), args .Get (1 )
@@ -91,7 +106,7 @@ func (*naiveCryptoService) Verify(peerIdentity api.PeerIdentityType, signature,
91
106
}
92
107
93
108
func TestPut (t * testing.T ) {
94
- idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger )
109
+ idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger , msgCryptoService )
95
110
identity := []byte ("yacovm" )
96
111
identity2 := []byte ("not-yacovm" )
97
112
identity3 := []byte ("invalidIdentity" )
@@ -109,7 +124,7 @@ func TestPut(t *testing.T) {
109
124
}
110
125
111
126
func TestGet (t * testing.T ) {
112
- idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger )
127
+ idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger , msgCryptoService )
113
128
identity := []byte ("yacovm" )
114
129
identity2 := []byte ("not-yacovm" )
115
130
pkiID := msgCryptoService .GetPKIidOfCert (api .PeerIdentityType (identity ))
@@ -124,7 +139,7 @@ func TestGet(t *testing.T) {
124
139
}
125
140
126
141
func TestVerify (t * testing.T ) {
127
- idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger )
142
+ idStore := NewIdentityMapper (msgCryptoService , dummyID , noopPurgeTrigger , msgCryptoService )
128
143
identity := []byte ("yacovm" )
129
144
identity2 := []byte ("not-yacovm" )
130
145
pkiID := msgCryptoService .GetPKIidOfCert (api .PeerIdentityType (identity ))
@@ -152,7 +167,7 @@ func TestListInvalidIdentities(t *testing.T) {
152
167
selfPKIID := msgCryptoService .GetPKIidOfCert (dummyID )
153
168
idStore := NewIdentityMapper (msgCryptoService , dummyID , func (_ common.PKIidType , identity api.PeerIdentityType ) {
154
169
deletedIdentities <- string (identity )
155
- })
170
+ }, msgCryptoService )
156
171
identity := []byte ("yacovm" )
157
172
// Test for a revoked identity
158
173
pkiID := msgCryptoService .GetPKIidOfCert (api .PeerIdentityType (identity ))
@@ -228,7 +243,7 @@ func TestExpiration(t *testing.T) {
228
243
SetIdentityUsageThreshold (time .Second * 500 )
229
244
idStore := NewIdentityMapper (msgCryptoService , dummyID , func (_ common.PKIidType , identity api.PeerIdentityType ) {
230
245
deletedIdentities <- string (identity )
231
- })
246
+ }, msgCryptoService )
232
247
assertDeletedIdentity := func (expected string ) {
233
248
select {
234
249
case <- time .After (time .Second * 10 ):
@@ -296,6 +311,29 @@ func TestExpirationPanic(t *testing.T) {
296
311
identity3 := []byte ("invalidIdentity" )
297
312
msgCryptoService .revokedIdentities [string (identity3 )] = struct {}{}
298
313
assert .Panics (t , func () {
299
- NewIdentityMapper (msgCryptoService , identity3 , noopPurgeTrigger )
314
+ NewIdentityMapper (msgCryptoService , identity3 , noopPurgeTrigger , msgCryptoService )
300
315
})
301
316
}
317
+
318
+ func TestIdentityInfo (t * testing.T ) {
319
+ cs := & naiveCryptoService {}
320
+ alice := api .PeerIdentityType ("alicePeer" )
321
+ bob := api .PeerIdentityType ("bobPeer" )
322
+ aliceID := cs .GetPKIidOfCert (alice )
323
+ bobId := cs .GetPKIidOfCert (bob )
324
+ cs .On ("OrgByPeerIdentity" , dummyID ).Return (api .OrgIdentityType ("D" ))
325
+ cs .On ("OrgByPeerIdentity" , alice ).Return (api .OrgIdentityType ("A" ))
326
+ cs .On ("OrgByPeerIdentity" , bob ).Return (api .OrgIdentityType ("B" ))
327
+ cs .On ("Expiration" , mock .Anything ).Return (time .Now ().Add (time .Minute ), nil )
328
+ idStore := NewIdentityMapper (cs , dummyID , noopPurgeTrigger , cs )
329
+ idStore .Put (aliceID , alice )
330
+ idStore .Put (bobId , bob )
331
+ for org , id := range idStore .IdentityInfo ().ByOrg () {
332
+ identity := string (id [0 ].Identity )
333
+ pkiID := string (id [0 ].PKIId )
334
+ orgId := string (id [0 ].Organization )
335
+ assert .Equal (t , org , orgId )
336
+ assert .Equal (t , strings .ToLower (org ), string (identity [0 ]))
337
+ assert .Equal (t , strings .ToLower (org ), string (pkiID [0 ]))
338
+ }
339
+ }
0 commit comments