Skip to content

Commit 42b837e

Browse files
committed
Refactoring PKI unit tests
1 parent df955b9 commit 42b837e

18 files changed

+358
-348
lines changed

integration_tests/constants/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ eujhLsD51w==
760760
PAACertWithSameSubjectID1Subject = "MFoxCzAJBgNVBAYTAlVaMQwwCgYDVQQIDANUU0gxETAPBgNVBAcMCFRBU0hLRU5UMQwwCgYDVQQKDANEU1IxCzAJBgNVBAsMAkRDMQ8wDQYDVQQDDAZNQVRURVI="
761761
PAACertWithSameSubjectID1SubjectAsText = "C=UZ,ST=TSH,L=TASHKENT,O=DSR,OU=DC,CN=MATTER"
762762
PAACertWithSameSubjectID2Subject = "MGAxCzAJBgNVBAYTAlVaMQwwCgYDVQQIDANUU0gxETAPBgNVBAcMCFRBU0hLRU5UMQwwCgYDVQQKDANEU1IxEDAOBgNVBAsMB01BVFRFUjIxEDAOBgNVBAMMB01BVFRFUjI="
763-
PAACertWithSameSubjectIDSubjectID = "7F:C5:4C:61:A7:2A:40:02:DA:B3:73:FB:A8:A0:AC:42:2C:44:77:05"
763+
PAACertWithSameSubjectIDSubjectKeyID = "7F:C5:4C:61:A7:2A:40:02:DA:B3:73:FB:A8:A0:AC:42:2C:44:77:05"
764764
PAACertWithSameSubjectIssuer = "MFoxCzAJBgNVBAYTAlVaMQwwCgYDVQQIDANUU0gxETAPBgNVBAcMCFRBU0hLRU5UMQwwCgYDVQQKDANEU1IxCzAJBgNVBAsMAkRDMQ8wDQYDVQQDDAZNQVRURVI="
765765
PAACertWithSameSubjectSerialNumber = "52395954309929518473720319596322683729415766451"
766766
PAACertWithSameSubject2Issuer = "MGAxCzAJBgNVBAYTAlVaMQwwCgYDVQQIDANUU0gxETAPBgNVBAcMCFRBU0hLRU5UMQwwCgYDVQQKDANEU1IxEDAOBgNVBAsMB01BVFRFUjIxEDAOBgNVBAMMB01BVFRFUjI="

x/pki/tests/handler_add_noc_ica_cert_test.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
1919
setup := utils.Setup(t)
2020

2121
// add NOC root certificate
22-
rootCertificate := utils.NocRootCert1(setup.Vendor1)
23-
utils.AddNocRootCertificate(setup, setup.Vendor1, rootCertificate.PemCert)
22+
rootCertificate := utils.RootNocCertificate1(setup.Vendor1)
23+
utils.AddNocRootCertificate(setup, rootCertificate)
2424

2525
// add NOC ICA certificate
26-
icaCertificate := utils.NocCertIca1(setup.Vendor1)
27-
utils.AddNocIntermediateCertificate(setup, setup.Vendor1, icaCertificate.PemCert)
26+
icaCertificate := utils.IntermediateNocCertificate1(setup.Vendor1)
27+
utils.AddNocIntermediateCertificate(setup, icaCertificate)
2828

2929
// Check state indexes
3030
indexes := utils.TestIndexes{
@@ -58,17 +58,17 @@ func TestHandler_AddNocIntermediateCert_SameSubjectAndSkid_DifferentSerialNumber
5858
setup := utils.Setup(t)
5959

6060
// add NOC root certificate
61-
rootCertificate := utils.NocRootCert1(setup.Vendor1)
62-
utils.AddNocRootCertificate(setup, setup.Vendor1, rootCertificate.PemCert)
61+
rootCertificate := utils.RootNocCertificate1(setup.Vendor1)
62+
utils.AddNocRootCertificate(setup, rootCertificate)
6363

6464
// Store the NOC certificate with different serial number
65-
intermediateCertificate := utils.NocCertIca1(setup.Vendor1)
65+
intermediateCertificate := utils.IntermediateNocCertificate1(setup.Vendor1)
6666
intermediateCertificate.SerialNumber = testconstants.TestSerialNumber
67-
utils.AddMokedNocCertificate(setup, intermediateCertificate, false)
67+
utils.AddMokedNocCertificate(setup, intermediateCertificate)
6868

6969
// add the new NOC certificate
70-
icaCertificate := utils.NocCertIca1(setup.Vendor1)
71-
utils.AddNocIntermediateCertificate(setup, setup.Vendor1, icaCertificate.PemCert)
70+
icaCertificate := utils.IntermediateNocCertificate1(setup.Vendor1)
71+
utils.AddNocIntermediateCertificate(setup, icaCertificate)
7272

7373
// Check state indexes
7474
indexes := utils.TestIndexes{
@@ -111,7 +111,8 @@ func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID(t *testing
111111
setup := utils.Setup(t)
112112

113113
// add NOC root certificate
114-
utils.AddNocRootCertificate(setup, setup.Vendor1, testconstants.NocRootCert1)
114+
rootCertificate := utils.RootNocCertificate1(setup.Vendor1)
115+
utils.AddNocRootCertificate(setup, rootCertificate)
115116

116117
newAccAddress := setup.CreateVendorAccount(1111)
117118

@@ -144,7 +145,7 @@ func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate(t *testing.T) {
144145

145146
// store root certificate
146147

147-
rootCert := utils.RootCertWithVid(setup.Trustee1)
148+
rootCert := utils.RootDaCertificateWithVid(setup.Trustee1)
148149
utils.ProposeAndApproveRootCertificate(setup, setup.Trustee1, rootCert)
149150

150151
// try to add root certificate x509 certificate
@@ -277,7 +278,8 @@ func TestHandler_AddNocX509Cert_CertificateExist(t *testing.T) {
277278
setup.AddAccount(accAddress, []dclauthtypes.AccountRole{dclauthtypes.Vendor}, vid)
278279

279280
// add NOC root certificate
280-
utils.AddNocRootCertificate(setup, accAddress, testconstants.NocRootCert1)
281+
rootCertificate := utils.RootNocCertificate1(accAddress)
282+
utils.AddNocRootCertificate(setup, rootCertificate)
281283

282284
// add the existing certificate
283285
setup.Keeper.AddAllCertificate(setup.Ctx, *tc.existingCert)

x/pki/tests/handler_add_noc_root_cert_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func TestHandler_AddNocRootCert(t *testing.T) {
1818
setup := utils.Setup(t)
1919

2020
// add NOC root certificate
21-
rootCertificate := utils.NocRootCert1(setup.Vendor1)
22-
utils.AddNocRootCertificate(setup, setup.Vendor1, rootCertificate.PemCert)
21+
rootCertificate := utils.RootNocCertificate1(setup.Vendor1)
22+
utils.AddNocRootCertificate(setup, rootCertificate)
2323

2424
// Check state indexes
2525
indexes := utils.TestIndexes{
@@ -52,12 +52,12 @@ func TestHandler_AddNocRootCert_SameSubjectAndSkid_DifferentSerialNumber(t *test
5252
setup := utils.Setup(t)
5353

5454
// Store the NOC root certificate
55-
rootCertificate1 := utils.NocRootCert1(setup.Vendor1)
56-
utils.AddNocRootCertificate(setup, setup.Vendor1, rootCertificate1.PemCert)
55+
rootCertificate1 := utils.RootNocCertificate1(setup.Vendor1)
56+
utils.AddNocRootCertificate(setup, rootCertificate1)
5757

5858
// add the new NOC root certificate
59-
rootCertificate2 := utils.NocRootCert1Copy(setup.Vendor1)
60-
utils.AddNocRootCertificate(setup, setup.Vendor1, rootCertificate2.PemCert)
59+
rootCertificate2 := utils.RootNocCertificate1Copy(setup.Vendor1)
60+
utils.AddNocRootCertificate(setup, rootCertificate2)
6161

6262
// Check state indexes
6363
indexes := utils.TestIndexes{

x/pki/tests/handler_add_paa_cert_test.go

+31-32
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import (
2020
func TestHandler_ProposeAddDaRootCert(t *testing.T) {
2121
setup := utils.Setup(t)
2222

23-
rootCertificate := utils.RootCertificate(setup.Trustee1)
24-
2523
// propose DA root certificate
26-
proposeAddX509RootCert := utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
24+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
25+
proposeAddX509RootCert := utils.ProposeDaRootCertificate(setup, rootCertificate)
2726

2827
// Check state indexes
2928
indexes := utils.TestIndexes{
@@ -53,8 +52,8 @@ func TestHandler_AddDaRootCert(t *testing.T) {
5352
setup := utils.Setup(t)
5453

5554
// propose add x509 root certificate by trustee
56-
rootCertificate := utils.RootCertificate(setup.Trustee1)
57-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
55+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
56+
utils.ProposeDaRootCertificate(setup, rootCertificate)
5857

5958
// approve by second trustee
6059
utils.ApproveDaRootCertificate(setup, setup.Trustee2, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -83,8 +82,8 @@ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded(t *testing.T) {
8382
setup := utils.Setup(t)
8483

8584
// propose x509 root certificate by account without trustee role
86-
rootCertificate := utils.RootCertificate(setup.Trustee1)
87-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
85+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
86+
utils.ProposeDaRootCertificate(setup, rootCertificate)
8887

8988
// Create an array of trustee account from 1 to 50
9089
trusteeAccounts, totalAdditionalTrustees := setup.CreateNTrusteeAccounts()
@@ -160,8 +159,8 @@ func TestHandler_AddDaRootCert_FourApprovalsAreNeeded_FiveTrustees(t *testing.T)
160159
setup.AddAccount(fifthTrustee, []dclauthtypes.AccountRole{dclauthtypes.Trustee}, 1)
161160

162161
// propose x509 root certificate by account Trustee1
163-
rootCertificate := utils.RootCertificate(setup.Trustee1)
164-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
162+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
163+
utils.ProposeDaRootCertificate(setup, rootCertificate)
165164

166165
// approve x509 root certificate by account Trustee2
167166
utils.ApproveDaRootCertificate(setup, setup.Trustee2, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -220,13 +219,13 @@ func TestHandler_ProposeAddX509RootCert_ForDifferentSerialNumber(t *testing.T) {
220219
setup := utils.Setup(t)
221220

222221
// store root certificate with different serial number
223-
rootCertificate := utils.RootCertificate(setup.Trustee1)
222+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
224223
rootCertificate.SerialNumber = utils.SerialNumber
225-
utils.AddMokedDaCertificate(setup, rootCertificate, true)
224+
utils.AddMokedDaCertificate(setup, rootCertificate)
226225

227226
// propose second root certificate
228-
testRootCertificate := utils.RootCertificate(setup.Trustee1)
229-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, testRootCertificate.PemCert)
227+
testRootCertificate := utils.RootDaCertificate(setup.Trustee1)
228+
utils.ProposeDaRootCertificate(setup, testRootCertificate)
230229

231230
// Check state indexes
232231
indexes := utils.TestIndexes{
@@ -255,11 +254,11 @@ func TestHandler_AddDaRootCerts_SameSubjectKeyIdButDifferentSubject(t *testing.T
255254
setup := utils.Setup(t)
256255

257256
// add Certificate1
258-
testRootCertificate := utils.PAACertWithSameSubjectID1(setup.Trustee1)
257+
testRootCertificate := utils.RootDaCertWithSameSubjectKeyID1(setup.Trustee1)
259258
utils.ProposeAndApproveRootCertificate(setup, setup.Trustee1, testRootCertificate)
260259

261260
// add Certificate2
262-
testRootCertificate2 := utils.PAACertWithSameSubjectID2(setup.Trustee1)
261+
testRootCertificate2 := utils.RootDaCertificateWithSameSubjectKeyID2(setup.Trustee1)
263262
utils.ProposeAndApproveRootCertificate(setup, setup.Trustee1, testRootCertificate2)
264263

265264
// Check indexes by subject + subject key id
@@ -301,8 +300,8 @@ func TestHandler_RejectAddDaRootCert(t *testing.T) {
301300
setup := utils.Setup(t)
302301

303302
// propose x509 root certificate by account Trustee1
304-
testRootCertificate := utils.RootCertificate(setup.Trustee1)
305-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, testRootCertificate.PemCert)
303+
testRootCertificate := utils.RootDaCertificate(setup.Trustee1)
304+
utils.ProposeDaRootCertificate(setup, testRootCertificate)
306305

307306
// reject x509 root certificate by account Trustee2
308307
utils.RejectDaRootCertificate(setup, setup.Trustee2, testRootCertificate.Subject, testRootCertificate.SubjectKeyId)
@@ -369,8 +368,8 @@ func TestHandler_ApproveX509RootCertAndRejectX509RootCert_FromTheSameTrustee(t *
369368
setup := utils.Setup(t)
370369

371370
// propose add x509 root certificate
372-
rootCertificate := utils.RootCertificate(setup.Trustee1)
373-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
371+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
372+
utils.ProposeDaRootCertificate(setup, rootCertificate)
374373

375374
for _, role := range []dclauthtypes.AccountRole{
376375
dclauthtypes.Trustee,
@@ -404,8 +403,8 @@ func TestHandler_RejectX509RootCertAndApproveX509RootCert_FromTheSameTrustee(t *
404403
setup := utils.Setup(t)
405404

406405
// propose add x509 root certificate
407-
rootCertificate := utils.RootCertificate(setup.Trustee1)
408-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
406+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
407+
utils.ProposeDaRootCertificate(setup, rootCertificate)
409408

410409
for _, role := range []dclauthtypes.AccountRole{
411410
dclauthtypes.Trustee,
@@ -450,8 +449,8 @@ func TestHandler_RejectX509RootCert_TwoRejectApprovalsAreNeeded_FiveTrustees(t *
450449
setup.AddAccount(fifthTrustee, []dclauthtypes.AccountRole{dclauthtypes.Trustee}, 1)
451450

452451
// propose x509 root certificate by account Trustee1
453-
rootCertificate := utils.RootCertificate(setup.Trustee1)
454-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
452+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
453+
utils.ProposeDaRootCertificate(setup, rootCertificate)
455454

456455
// reject x509 root certificate by account Trustee2
457456
utils.RejectDaRootCertificate(setup, setup.Trustee2, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -502,8 +501,8 @@ func TestHandler_ProposeAddAndRejectX509RootCert_ByTrustee(t *testing.T) {
502501
setup := utils.Setup(t)
503502

504503
// propose x509 root certificate
505-
rootCertificate := utils.RootCertificate(setup.Trustee1)
506-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
504+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
505+
utils.ProposeDaRootCertificate(setup, rootCertificate)
507506

508507
// reject x509 root certificate
509508
utils.RejectDaRootCertificate(setup, setup.Trustee1, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -531,8 +530,8 @@ func TestHandler_ProposeAddAndRejectX509RootCert_ByAnotherTrustee(t *testing.T)
531530
setup := utils.Setup(t)
532531

533532
// propose x509 root certificate
534-
rootCertificate := utils.RootCertificate(setup.Trustee1)
535-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
533+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
534+
utils.ProposeDaRootCertificate(setup, rootCertificate)
536535

537536
// reject x509 root certificate
538537
utils.RejectDaRootCertificate(setup, setup.Trustee2, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -564,8 +563,8 @@ func TestHandler_ProposeAddAndRejectX509RootCertWithApproval_ByTrustee(t *testin
564563
setup.CreateTrusteeAccount(1)
565564

566565
// propose x509 root certificate
567-
rootCertificate := utils.RootCertificate(setup.Trustee1)
568-
utils.ProposeDaRootCertificate(setup, setup.Trustee1, rootCertificate.PemCert)
566+
rootCertificate := utils.RootDaCertificate(setup.Trustee1)
567+
utils.ProposeDaRootCertificate(setup, rootCertificate)
569568

570569
// approve
571570
utils.ApproveDaRootCertificate(setup, setup.Trustee2, rootCertificate.Subject, rootCertificate.SubjectKeyId)
@@ -660,7 +659,7 @@ func TestHandler_ProposeAddX509RootCert_CertificateAlreadyExists(t *testing.T) {
660659
setup := utils.Setup(t)
661660

662661
// store x509 root certificate
663-
rootCertificate := utils.RootCertificate(testconstants.Address1)
662+
rootCertificate := utils.RootDaCertificate(testconstants.Address1)
664663
setup.Keeper.SetUniqueCertificate(
665664
setup.Ctx,
666665
utils.UniqueCertificate(rootCertificate.Subject, rootCertificate.SerialNumber),
@@ -678,7 +677,7 @@ func TestHandler_ProposeAddX509RootCert_ForNocCertificate(t *testing.T) {
678677
setup := utils.Setup(t)
679678

680679
// Store the NOC root certificate
681-
nocRootCertificate := utils.RootCertificate(setup.Vendor1)
680+
nocRootCertificate := utils.RootDaCertificate(setup.Vendor1)
682681
nocRootCertificate.SerialNumber = testconstants.TestSerialNumber
683682
nocRootCertificate.CertificateType = types.CertificateType_OperationalPKI
684683
nocRootCertificate.Approvals = nil
@@ -704,7 +703,7 @@ func TestHandler_ProposeAddX509RootCert_ForDifferentSerialNumberDifferentSigner(
704703
setup := utils.Setup(t)
705704

706705
// store root certificate with different serial number
707-
rootCertificate := utils.RootCertificate(testconstants.Address1)
706+
rootCertificate := utils.RootDaCertificate(testconstants.Address1)
708707
rootCertificate.SerialNumber = utils.SerialNumber
709708
setup.Keeper.SetUniqueCertificate(
710709
setup.Ctx,

0 commit comments

Comments
 (0)