@@ -63,23 +63,27 @@ func TestSetup(t *testing.T) {
63
63
func TestSetupBad (t * testing.T ) {
64
64
_ , err := setup ("testdata/idemix/badpath" , "MSPID" )
65
65
assert .Error (t , err )
66
+ assert .Contains (t , err .Error (), "Getting MSP config failed" )
66
67
67
68
msp1 , err := newIdemixMsp ()
68
69
assert .NoError (t , err )
69
70
70
71
// Setup with nil config
71
72
err = msp1 .Setup (nil )
72
73
assert .Error (t , err )
74
+ assert .Contains (t , err .Error (), "setup error: nil conf reference" )
73
75
74
76
// Setup with incorrect MSP type
75
77
conf := & msp.MSPConfig {Type : 1234 , Config : nil }
76
78
err = msp1 .Setup (conf )
77
79
assert .Error (t , err )
80
+ assert .Contains (t , err .Error (), "setup error: config is not of type IDEMIX" )
78
81
79
82
// Setup with bad idemix config bytes
80
83
conf = & msp.MSPConfig {Type : int32 (IDEMIX ), Config : []byte ("barf" )}
81
84
err = msp1 .Setup (conf )
82
85
assert .Error (t , err )
86
+ assert .Contains (t , err .Error (), "failed unmarshalling idemix msp config" )
83
87
84
88
conf , err = GetIdemixMspConfig ("testdata/idemix/MSP1OU1" , "IdemixMSP1" )
85
89
idemixconfig := & msp.IdemixMSPConfig {}
@@ -101,6 +105,7 @@ func TestSetupBad(t *testing.T) {
101
105
102
106
err = msp1 .Setup (conf )
103
107
assert .Error (t , err )
108
+ assert .Contains (t , err .Error (), "issuer public key must have have attributes OU, Role, EnrollmentId, and RevocationHandle" )
104
109
105
110
// Create MSP config with bad IPK bytes
106
111
ipkBytes = []byte ("barf" )
@@ -112,6 +117,7 @@ func TestSetupBad(t *testing.T) {
112
117
113
118
err = msp1 .Setup (conf )
114
119
assert .Error (t , err )
120
+ assert .Contains (t , err .Error (), "failed to unmarshal ipk from idemix msp config" )
115
121
}
116
122
117
123
func TestSigning (t * testing.T ) {
@@ -130,13 +136,15 @@ func TestSigning(t *testing.T) {
130
136
131
137
err = id .Verify ([]byte ("OtherMessage" ), sig )
132
138
assert .Error (t , err )
139
+ assert .Contains (t , err .Error (), "pseudonym signature invalid: zero-knowledge proof is invalid" )
133
140
134
141
verMsp , err := setup ("testdata/idemix/MSP1Verifier" , "MSP1" )
135
142
assert .NoError (t , err )
136
143
err = verMsp .Validate (id )
137
144
assert .NoError (t , err )
138
145
_ , err = verMsp .GetDefaultSigningIdentity ()
139
146
assert .Error (t , err )
147
+ assert .Contains (t , err .Error (), "no default signer setup" )
140
148
}
141
149
142
150
func TestSigningBad (t * testing.T ) {
@@ -151,6 +159,7 @@ func TestSigningBad(t *testing.T) {
151
159
152
160
err = id .Verify (msg , sig )
153
161
assert .Error (t , err )
162
+ assert .Contains (t , err .Error (), "error unmarshalling signature" )
154
163
}
155
164
156
165
func TestIdentitySerialization (t * testing.T ) {
@@ -179,6 +188,7 @@ func TestIdentitySerializationBad(t *testing.T) {
179
188
180
189
_ , err = msp .DeserializeIdentity ([]byte ("barf" ))
181
190
assert .Error (t , err , "DeserializeIdentity should have failed for bad input" )
191
+ assert .Contains (t , err .Error (), "could not deserialize a SerializedIdentity" )
182
192
}
183
193
184
194
func TestIdentitySerializationWrongMSP (t * testing.T ) {
@@ -194,6 +204,7 @@ func TestIdentitySerializationWrongMSP(t *testing.T) {
194
204
195
205
_ , err = msp1 .DeserializeIdentity (idBytes )
196
206
assert .Error (t , err , "DeserializeIdentity should have failed for ID of other MSP" )
207
+ assert .Contains (t , err .Error (), "expected MSP ID MSP1OU1, received MSP2OU1" )
197
208
}
198
209
199
210
func TestPrincipalIdentity (t * testing.T ) {
@@ -236,6 +247,8 @@ func TestPrincipalIdentityWrongIdentity(t *testing.T) {
236
247
237
248
err = id2 .SatisfiesPrincipal (principal )
238
249
assert .Error (t , err , "Identity MSP principal for different user should fail" )
250
+ assert .Contains (t , err .Error (), "the identities do not match" )
251
+
239
252
}
240
253
241
254
func TestPrincipalIdentityBadIdentity (t * testing.T ) {
@@ -253,6 +266,44 @@ func TestPrincipalIdentityBadIdentity(t *testing.T) {
253
266
254
267
err = id1 .SatisfiesPrincipal (principal )
255
268
assert .Error (t , err , "Identity MSP principal for a bad principal should fail" )
269
+ assert .Contains (t , err .Error (), "the identities do not match" )
270
+ }
271
+
272
+ func TestAnonymityPrincipal (t * testing.T ) {
273
+ msp1 , err := setup ("testdata/idemix/MSP1OU1" , "MSP1OU1" )
274
+ assert .NoError (t , err )
275
+
276
+ id1 , err := getDefaultSigner (msp1 )
277
+ assert .NoError (t , err )
278
+
279
+ principalBytes , err := proto .Marshal (& msp.MSPIdentityAnonymity {AnonymityType : msp .MSPIdentityAnonymity_ANONYMOUS })
280
+ assert .NoError (t , err )
281
+
282
+ principal := & msp.MSPPrincipal {
283
+ PrincipalClassification : msp .MSPPrincipal_ANONYMITY ,
284
+ Principal : principalBytes }
285
+
286
+ err = id1 .SatisfiesPrincipal (principal )
287
+ assert .NoError (t , err )
288
+ }
289
+
290
+ func TestAnonymityPrincipalBad (t * testing.T ) {
291
+ msp1 , err := setup ("testdata/idemix/MSP1OU1" , "MSP1OU1" )
292
+ assert .NoError (t , err )
293
+
294
+ id1 , err := getDefaultSigner (msp1 )
295
+ assert .NoError (t , err )
296
+
297
+ principalBytes , err := proto .Marshal (& msp.MSPIdentityAnonymity {AnonymityType : msp .MSPIdentityAnonymity_NOMINAL })
298
+ assert .NoError (t , err )
299
+
300
+ principal := & msp.MSPPrincipal {
301
+ PrincipalClassification : msp .MSPPrincipal_ANONYMITY ,
302
+ Principal : principalBytes }
303
+
304
+ err = id1 .SatisfiesPrincipal (principal )
305
+ assert .Error (t , err , "Idemix identity is anonymous and should not pass NOMINAL anonymity principal" )
306
+ assert .Contains (t , err .Error (), "principal is nominal, but idemix MSP is anonymous" )
256
307
}
257
308
258
309
func TestIdemixIsWellFormed (t * testing.T ) {
@@ -319,6 +370,8 @@ func TestPrincipalOUWrongOU(t *testing.T) {
319
370
320
371
err = id1 .SatisfiesPrincipal (principal )
321
372
assert .Error (t , err , "OU MSP principal should have failed for user of different OU" )
373
+ assert .Contains (t , err .Error (), "user is not part of the desired organizational unit" )
374
+
322
375
}
323
376
324
377
func TestPrincipalOUWrongMSP (t * testing.T ) {
@@ -342,6 +395,8 @@ func TestPrincipalOUWrongMSP(t *testing.T) {
342
395
343
396
err = id1 .SatisfiesPrincipal (principal )
344
397
assert .Error (t , err , "OU MSP principal should have failed for user of different MSP" )
398
+ assert .Contains (t , err .Error (), "the identity is a member of a different MSP" )
399
+
345
400
}
346
401
347
402
func TestPrincipalOUBad (t * testing.T ) {
@@ -360,6 +415,7 @@ func TestPrincipalOUBad(t *testing.T) {
360
415
361
416
err = id1 .SatisfiesPrincipal (principal )
362
417
assert .Error (t , err , "OU MSP principal should have failed for a bad OU principal" )
418
+ assert .Contains (t , err .Error (), "could not unmarshal OU from principal" )
363
419
}
364
420
365
421
func TestPrincipalRoleMember (t * testing.T ) {
@@ -425,6 +481,7 @@ func TestPrincipalRoleNotAdmin(t *testing.T) {
425
481
426
482
err = id1 .SatisfiesPrincipal (principal )
427
483
assert .Error (t , err , "Member should not satisfy Admin principal" )
484
+ assert .Contains (t , err .Error (), "user is not an admin" )
428
485
}
429
486
430
487
func TestPrincipalRoleWrongMSP (t * testing.T ) {
@@ -443,6 +500,7 @@ func TestPrincipalRoleWrongMSP(t *testing.T) {
443
500
444
501
err = id1 .SatisfiesPrincipal (principal )
445
502
assert .Error (t , err , "Role MSP principal should have failed for user of different MSP" )
503
+ assert .Contains (t , err .Error (), "the identity is a member of a different MSP" )
446
504
}
447
505
448
506
func TestPrincipalRoleBadRole (t * testing.T ) {
@@ -462,6 +520,7 @@ func TestPrincipalRoleBadRole(t *testing.T) {
462
520
463
521
err = id1 .SatisfiesPrincipal (principal )
464
522
assert .Error (t , err , "Role MSP principal should have failed for a bad Role" )
523
+ assert .Contains (t , err .Error (), "invalid MSP role type" )
465
524
}
466
525
467
526
func TestPrincipalBad (t * testing.T ) {
@@ -477,4 +536,85 @@ func TestPrincipalBad(t *testing.T) {
477
536
478
537
err = id1 .SatisfiesPrincipal (principal )
479
538
assert .Error (t , err , "Principal with bad Classification should fail" )
539
+ assert .Contains (t , err .Error (), "invalid principal type" )
540
+ }
541
+
542
+ func TestPrincipalCombined (t * testing.T ) {
543
+ msp1 , err := setup ("testdata/idemix/MSP1OU1" , "MSP1OU1" )
544
+ assert .NoError (t , err )
545
+
546
+ id1 , err := getDefaultSigner (msp1 )
547
+ assert .NoError (t , err )
548
+
549
+ ou := & msp.OrganizationUnit {
550
+ OrganizationalUnitIdentifier : id1 .GetOrganizationalUnits ()[0 ].OrganizationalUnitIdentifier ,
551
+ MspIdentifier : id1 .GetMSPIdentifier (),
552
+ CertifiersIdentifier : nil ,
553
+ }
554
+ principalBytes , err := proto .Marshal (ou )
555
+ assert .NoError (t , err )
556
+
557
+ principalOU := & msp.MSPPrincipal {
558
+ PrincipalClassification : msp .MSPPrincipal_ORGANIZATION_UNIT ,
559
+ Principal : principalBytes }
560
+
561
+ principalBytes , err = proto .Marshal (& msp.MSPRole {Role : msp .MSPRole_MEMBER , MspIdentifier : id1 .GetMSPIdentifier ()})
562
+ assert .NoError (t , err )
563
+
564
+ principalRole := & msp.MSPPrincipal {
565
+ PrincipalClassification : msp .MSPPrincipal_ROLE ,
566
+ Principal : principalBytes }
567
+
568
+ principals := []* msp.MSPPrincipal {principalOU , principalRole }
569
+
570
+ combinedPrincipal := & msp.CombinedPrincipal {Principals : principals }
571
+ combinedPrincipalBytes , err := proto .Marshal (combinedPrincipal )
572
+
573
+ assert .NoError (t , err )
574
+
575
+ principalsCombined := & msp.MSPPrincipal {PrincipalClassification : msp .MSPPrincipal_COMBINED , Principal : combinedPrincipalBytes }
576
+
577
+ err = id1 .SatisfiesPrincipal (principalsCombined )
578
+ assert .NoError (t , err )
579
+ }
580
+
581
+ func TestPrincipalCombinedBad (t * testing.T ) {
582
+ msp1 , err := setup ("testdata/idemix/MSP1OU1" , "MSP1OU1" )
583
+ assert .NoError (t , err )
584
+
585
+ id1 , err := getDefaultSigner (msp1 )
586
+ assert .NoError (t , err )
587
+
588
+ // create combined principal requiring membership of OU1 in MSP1 and requiring admin role
589
+ ou := & msp.OrganizationUnit {
590
+ OrganizationalUnitIdentifier : id1 .GetOrganizationalUnits ()[0 ].OrganizationalUnitIdentifier ,
591
+ MspIdentifier : id1 .GetMSPIdentifier (),
592
+ CertifiersIdentifier : nil ,
593
+ }
594
+ principalBytes , err := proto .Marshal (ou )
595
+ assert .NoError (t , err )
596
+
597
+ principalOU := & msp.MSPPrincipal {
598
+ PrincipalClassification : msp .MSPPrincipal_ORGANIZATION_UNIT ,
599
+ Principal : principalBytes }
600
+
601
+ principalBytes , err = proto .Marshal (& msp.MSPRole {Role : msp .MSPRole_ADMIN , MspIdentifier : id1 .GetMSPIdentifier ()})
602
+ assert .NoError (t , err )
603
+
604
+ principalRole := & msp.MSPPrincipal {
605
+ PrincipalClassification : msp .MSPPrincipal_ROLE ,
606
+ Principal : principalBytes }
607
+
608
+ principals := []* msp.MSPPrincipal {principalOU , principalRole }
609
+
610
+ combinedPrincipal := & msp.CombinedPrincipal {Principals : principals }
611
+ combinedPrincipalBytes , err := proto .Marshal (combinedPrincipal )
612
+
613
+ assert .NoError (t , err )
614
+
615
+ principalsCombined := & msp.MSPPrincipal {PrincipalClassification : msp .MSPPrincipal_COMBINED , Principal : combinedPrincipalBytes }
616
+
617
+ err = id1 .SatisfiesPrincipal (principalsCombined )
618
+ assert .Error (t , err , "non-admin member of OU1 in MSP1 should not satisfy principal admin and OU1 in MSP1" )
619
+ assert .Contains (t , err .Error (), "user is not an admin" )
480
620
}
0 commit comments