@@ -25,7 +25,7 @@ func TestHandler_ProposeAddDaRootCert(t *testing.T) {
25
25
// propose DA root certificate
26
26
proposeAddX509RootCert := utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
27
27
28
- // Check indexes
28
+ // Check state indexes
29
29
indexes := utils.TestIndexes {
30
30
Present : []utils.TestIndex {
31
31
{Key : types .ProposedCertificateKeyPrefix },
@@ -52,15 +52,14 @@ func TestHandler_ProposeAddDaRootCert(t *testing.T) {
52
52
func TestHandler_AddDaRootCert (t * testing.T ) {
53
53
setup := utils .Setup (t )
54
54
55
- rootCertificate := utils .CreateTestRootCert ()
56
-
57
55
// propose add x509 root certificate by trustee
56
+ rootCertificate := utils .CreateTestRootCert ()
58
57
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
59
58
60
59
// approve by second trustee
61
60
utils .ApproveDaRootCertificate (setup , setup .Trustee2 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
62
61
63
- // Check indexes
62
+ // Check state indexes
64
63
indexes := utils.TestIndexes {
65
64
Present : []utils.TestIndex {
66
65
{Key : types .UniqueCertificateKeyPrefix },
@@ -83,9 +82,8 @@ func TestHandler_AddDaRootCert(t *testing.T) {
83
82
func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded (t * testing.T ) {
84
83
setup := utils .Setup (t )
85
84
86
- rootCertificate := utils .CreateTestRootCert ()
87
-
88
85
// propose x509 root certificate by account without trustee role
86
+ rootCertificate := utils .CreateTestRootCert ()
89
87
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
90
88
91
89
// Create an array of trustee account from 1 to 50
@@ -98,7 +96,7 @@ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded(t *testing.T) {
98
96
for i := 1 ; i < twoThirds - 1 ; i ++ {
99
97
utils .ApproveDaRootCertificate (setup , trusteeAccounts [i ], rootCertificate .Subject , rootCertificate .SubjectKeyID )
100
98
101
- // Check indexes
99
+ // Check state indexes
102
100
indexes := utils.TestIndexes {
103
101
Present : []utils.TestIndex {
104
102
{Key : types .UniqueCertificateKeyPrefix },
@@ -121,7 +119,7 @@ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded(t *testing.T) {
121
119
// One more approval will move this to approved state from pending
122
120
utils .ApproveDaRootCertificate (setup , setup .Trustee2 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
123
121
124
- // Check indexes
122
+ // Check state indexes
125
123
indexes := utils.TestIndexes {
126
124
Present : []utils.TestIndex {
127
125
{Key : types .UniqueCertificateKeyPrefix },
@@ -140,7 +138,7 @@ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded(t *testing.T) {
140
138
}
141
139
resolvedCertificates := utils .CheckCertificateStateIndexes (t , setup , rootCertificate , indexes )
142
140
143
- // Additional check: Check all approvals are present
141
+ // Additional checks
144
142
for i := 1 ; i < twoThirds - 1 ; i ++ {
145
143
require .Equal (t , resolvedCertificates .ApprovedCertificates .Certs [0 ].HasApprovalFrom (trusteeAccounts [i ].String ()), true )
146
144
}
@@ -151,8 +149,6 @@ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded(t *testing.T) {
151
149
func TestHandler_AddDaRootCert_FourApprovalsAreNeeded_FiveTrustees (t * testing.T ) {
152
150
setup := utils .Setup (t )
153
151
154
- rootCertificate := utils .CreateTestRootCert ()
155
-
156
152
// we have 5 trustees: 1 approval comes from propose => we need 3 more approvals
157
153
158
154
// store 4th trustee
@@ -164,6 +160,7 @@ func TestHandler_AddDaRootCert_FourApprovalsAreNeeded_FiveTrustees(t *testing.T)
164
160
setup .AddAccount (fifthTrustee , []dclauthtypes.AccountRole {dclauthtypes .Trustee }, 1 )
165
161
166
162
// propose x509 root certificate by account Trustee1
163
+ rootCertificate := utils .CreateTestRootCert ()
167
164
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
168
165
169
166
// approve x509 root certificate by account Trustee2
@@ -175,19 +172,29 @@ func TestHandler_AddDaRootCert_FourApprovalsAreNeeded_FiveTrustees(t *testing.T)
175
172
// reject x509 root certificate by account Trustee4
176
173
utils .RejectDaRootCertificate (setup , fourthTrustee , rootCertificate .Subject , rootCertificate .SubjectKeyID )
177
174
178
- // Check: ProposedCertificate - present because we haven't enough approvals
175
+ // Check state indexes - certificate is in proposed state
179
176
indexes := utils.TestIndexes {
180
177
Present : []utils.TestIndex {
181
178
{Key : types .ProposedCertificateKeyPrefix },
179
+ {Key : types .UniqueCertificateKeyPrefix },
180
+ },
181
+ Missing : []utils.TestIndex {
182
+ {Key : types .RejectedCertificateKeyPrefix },
183
+ {Key : types .AllCertificatesKeyPrefix },
184
+ {Key : types .AllCertificatesBySubjectKeyPrefix },
185
+ {Key : types .AllCertificatesBySubjectKeyIDKeyPrefix },
186
+ {Key : types .ApprovedCertificatesKeyPrefix },
187
+ {Key : types .ApprovedCertificatesBySubjectKeyPrefix },
188
+ {Key : types .ApprovedCertificatesBySubjectKeyIDKeyPrefix },
189
+ {Key : types .ApprovedRootCertificatesKeyPrefix },
182
190
},
183
- Missing : []utils.TestIndex {},
184
191
}
185
192
utils .CheckCertificateStateIndexes (t , setup , rootCertificate , indexes )
186
193
187
194
// approve x509 root certificate by account Trustee5
188
195
utils .ApproveDaRootCertificate (setup , fifthTrustee , rootCertificate .Subject , rootCertificate .SubjectKeyID )
189
196
190
- // Check indexes
197
+ // Check state indexes
191
198
indexes = utils.TestIndexes {
192
199
Present : []utils.TestIndex {
193
200
{Key : types .UniqueCertificateKeyPrefix },
@@ -221,7 +228,7 @@ func TestHandler_ProposeAddX509RootCert_ForDifferentSerialNumber(t *testing.T) {
221
228
testRootCertificate := utils .CreateTestRootCert ()
222
229
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , testRootCertificate .PEM )
223
230
224
- // Check indexes
231
+ // Check state indexes
225
232
indexes := utils.TestIndexes {
226
233
Present : []utils.TestIndex {
227
234
{Key : types .ProposedCertificateKeyPrefix }, // we have both: Proposed and Approved
@@ -247,28 +254,13 @@ func TestHandler_ProposeAddX509RootCert_ForDifferentSerialNumber(t *testing.T) {
247
254
func TestHandler_AddDaRootCerts_SameSubjectKeyIdButDifferentSubject (t * testing.T ) {
248
255
setup := utils .Setup (t )
249
256
250
- testRootCertificate := utils .CreateTestRootCertWithSameSubject ()
251
- testRootCertificate2 := utils .CreateTestRootCertWithSameSubject2 ()
252
-
253
257
// add Certificate1
254
- rootCertOptions := & utils.RootCertOptions {
255
- PemCert : testRootCertificate .PEM ,
256
- Subject : testRootCertificate .Subject ,
257
- SubjectKeyID : testRootCertificate .SubjectKeyID ,
258
- Info : testconstants .Info ,
259
- Vid : testconstants .Vid ,
260
- }
261
- utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
258
+ testRootCertificate := utils .CreateTestRootCertWithSameSubject ()
259
+ utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , & testRootCertificate )
262
260
263
261
// add Certificate2
264
- rootCert2Options := & utils.RootCertOptions {
265
- PemCert : testRootCertificate2 .PEM ,
266
- Subject : testRootCertificate2 .Subject ,
267
- SubjectKeyID : testRootCertificate2 .SubjectKeyID ,
268
- Info : testconstants .Info ,
269
- Vid : testconstants .Vid ,
270
- }
271
- utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCert2Options )
262
+ testRootCertificate2 := utils .CreateTestRootCertWithSameSubject2 ()
263
+ utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , & testRootCertificate2 )
272
264
273
265
// Check indexes by subject + subject key id
274
266
allApprovedCertificates , _ := utils .QueryAllApprovedCertificates (setup )
@@ -277,7 +269,7 @@ func TestHandler_AddDaRootCerts_SameSubjectKeyIdButDifferentSubject(t *testing.T
277
269
allCertificates , _ := utils .QueryAllCertificatesAll (setup )
278
270
require .Equal (t , 2 , len (allCertificates ))
279
271
280
- // Check indexes
272
+ // Check state indexes
281
273
indexes := utils.TestIndexes {
282
274
Present : []utils.TestIndex {
283
275
{Key : types .UniqueCertificateKeyPrefix },
@@ -308,9 +300,8 @@ func TestHandler_AddDaRootCerts_SameSubjectKeyIdButDifferentSubject(t *testing.T
308
300
func TestHandler_RejectAddDaRootCert (t * testing.T ) {
309
301
setup := utils .Setup (t )
310
302
311
- testRootCertificate := utils .CreateTestRootCert ()
312
-
313
303
// propose x509 root certificate by account Trustee1
304
+ testRootCertificate := utils .CreateTestRootCert ()
314
305
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , testRootCertificate .PEM )
315
306
316
307
// reject x509 root certificate by account Trustee2
@@ -377,9 +368,8 @@ func TestHandler_RejectAddDaRootCert(t *testing.T) {
377
368
func TestHandler_ApproveX509RootCertAndRejectX509RootCert_FromTheSameTrustee (t * testing.T ) {
378
369
setup := utils .Setup (t )
379
370
380
- rootCertificate := utils .CreateTestRootCert ()
381
-
382
371
// propose add x509 root certificate
372
+ rootCertificate := utils .CreateTestRootCert ()
383
373
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
384
374
385
375
for _ , role := range []dclauthtypes.AccountRole {
@@ -413,9 +403,8 @@ func TestHandler_ApproveX509RootCertAndRejectX509RootCert_FromTheSameTrustee(t *
413
403
func TestHandler_RejectX509RootCertAndApproveX509RootCert_FromTheSameTrustee (t * testing.T ) {
414
404
setup := utils .Setup (t )
415
405
416
- rootCertificate := utils .CreateTestRootCert ()
417
-
418
406
// propose add x509 root certificate
407
+ rootCertificate := utils .CreateTestRootCert ()
419
408
utils .ProposeDaRootCertificate (setup , setup .Trustee1 , rootCertificate .PEM )
420
409
421
410
for _ , role := range []dclauthtypes.AccountRole {
@@ -467,6 +456,7 @@ func TestHandler_RejectX509RootCert_TwoRejectApprovalsAreNeeded_FiveTrustees(t *
467
456
// reject x509 root certificate by account Trustee2
468
457
utils .RejectDaRootCertificate (setup , setup .Trustee2 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
469
458
459
+ // Check state indexes
470
460
indexes := utils.TestIndexes {
471
461
Present : []utils.TestIndex {
472
462
{Key : types .ProposedCertificateKeyPrefix },
@@ -488,6 +478,7 @@ func TestHandler_RejectX509RootCert_TwoRejectApprovalsAreNeeded_FiveTrustees(t *
488
478
// reject x509 root certificate by account Trustee3
489
479
utils .RejectDaRootCertificate (setup , setup .Trustee3 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
490
480
481
+ // Check state indexes
491
482
indexes = utils.TestIndexes {
492
483
Present : []utils.TestIndex {
493
484
{Key : types .RejectedCertificateKeyPrefix }, // certificate is rejected now
@@ -517,7 +508,7 @@ func TestHandler_ProposeAddAndRejectX509RootCert_ByTrustee(t *testing.T) {
517
508
// reject x509 root certificate
518
509
utils .RejectDaRootCertificate (setup , setup .Trustee1 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
519
510
520
- // check state indexes
511
+ // Check state indexes
521
512
indexes := utils.TestIndexes {
522
513
Present : []utils.TestIndex {},
523
514
Missing : []utils.TestIndex {
@@ -546,7 +537,7 @@ func TestHandler_ProposeAddAndRejectX509RootCert_ByAnotherTrustee(t *testing.T)
546
537
// reject x509 root certificate
547
538
utils .RejectDaRootCertificate (setup , setup .Trustee2 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
548
539
549
- // check state indexes
540
+ // Check state indexes
550
541
indexes := utils.TestIndexes {
551
542
Present : []utils.TestIndex {
552
543
{Key : types .UniqueCertificateKeyPrefix },
@@ -582,7 +573,7 @@ func TestHandler_ProposeAddAndRejectX509RootCertWithApproval_ByTrustee(t *testin
582
573
// reject x509 root certificate
583
574
utils .RejectDaRootCertificate (setup , setup .Trustee1 , rootCertificate .Subject , rootCertificate .SubjectKeyID )
584
575
585
- // check state indexes
576
+ // Check state indexes
586
577
indexes := utils.TestIndexes {
587
578
Present : []utils.TestIndex {
588
579
{Key : types .UniqueCertificateKeyPrefix },
0 commit comments