@@ -21,107 +21,88 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
21
21
accAddress := setup .CreateVendorAccount (testconstants .Vid )
22
22
23
23
// add NOC root certificate
24
- utils .AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
24
+ rootCertificate := utils .CreateTestNocRoot1Cert ()
25
+ utils .AddNocRootCertificate (setup , accAddress , rootCertificate .PEM )
25
26
26
27
// add NOC ICA certificate
27
28
icaCertificate := utils .CreateTestNocIca1Cert ()
28
- utils .AddNocIntermediateCertificate (setup , accAddress , testconstants . NocCert1 )
29
+ utils .AddNocIntermediateCertificate (setup , accAddress , icaCertificate . PEM )
29
30
30
31
// Check indexes
31
- indexes := []utils.TestIndex {
32
- {Key : types .AllCertificatesKeyPrefix , Exist : true },
33
- {Key : types .AllCertificatesBySubjectKeyPrefix , Exist : true },
34
- {Key : types .AllCertificatesBySubjectKeyIDKeyPrefix , Exist : true },
35
- {Key : types .NocCertificatesKeyPrefix , Exist : true },
36
- {Key : types .NocCertificatesBySubjectKeyPrefix , Exist : true },
37
- {Key : types .NocCertificatesBySubjectKeyIDKeyPrefix , Exist : true },
38
- {Key : types .NocCertificatesByVidAndSkidKeyPrefix , Exist : true },
39
- {Key : types .NocRootCertificatesKeyPrefix , Exist : true , Count : 1 }, // we create root certificate as well but ica should not get there
40
- {Key : types .NocIcaCertificatesKeyPrefix , Exist : true },
41
- {Key : types .UniqueCertificateKeyPrefix , Exist : true },
42
- {Key : types .ChildCertificatesKeyPrefix , Exist : true },
43
- {Key : types .ProposedCertificateKeyPrefix , Exist : false },
44
- {Key : types .ApprovedCertificatesKeyPrefix , Exist : false },
45
- {Key : types .ApprovedCertificatesBySubjectKeyPrefix , Exist : false },
46
- {Key : types .ApprovedCertificatesBySubjectKeyIDKeyPrefix , Exist : false },
47
- {Key : types .ApprovedRootCertificatesKeyPrefix , Exist : false },
32
+ indexes := utils.TestIndexes {
33
+ Present : []utils.TestIndex {
34
+ {Key : types .AllCertificatesKeyPrefix },
35
+ {Key : types .AllCertificatesBySubjectKeyPrefix },
36
+ {Key : types .AllCertificatesBySubjectKeyIDKeyPrefix },
37
+ {Key : types .NocCertificatesKeyPrefix },
38
+ {Key : types .NocCertificatesBySubjectKeyPrefix },
39
+ {Key : types .NocCertificatesBySubjectKeyIDKeyPrefix },
40
+ {Key : types .NocCertificatesByVidAndSkidKeyPrefix },
41
+ {Key : types .NocRootCertificatesKeyPrefix , Count : 1 }, // we create root certificate as well but ica should not be there
42
+ {Key : types .NocIcaCertificatesKeyPrefix },
43
+ {Key : types .UniqueCertificateKeyPrefix },
44
+ {Key : types .ChildCertificatesKeyPrefix },
45
+ },
46
+ Missing : []utils.TestIndex {
47
+ {Key : types .ProposedCertificateKeyPrefix },
48
+ {Key : types .ApprovedCertificatesKeyPrefix },
49
+ {Key : types .ApprovedCertificatesBySubjectKeyPrefix },
50
+ {Key : types .ApprovedCertificatesBySubjectKeyIDKeyPrefix },
51
+ {Key : types .ApprovedRootCertificatesKeyPrefix },
52
+ },
48
53
}
49
54
utils .CheckCertificateStateIndexes (t , setup , icaCertificate , indexes )
50
55
}
51
56
52
57
// Extra cases
53
58
54
- func TestHandler_AddNocX509Cert_Renew (t * testing.T ) {
59
+ func TestHandler_AddNocIntermediateCert_SameSubjectAndSkid_DifferentSerialNumber (t * testing.T ) {
55
60
setup := utils .Setup (t )
56
61
57
- accAddress := utils .GenerateAccAddress ()
58
- vid := testconstants .Vid
59
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, testconstants .Vid )
62
+ accAddress := setup .CreateVendorAccount (testconstants .Vid )
60
63
61
64
// add NOC root certificate
62
- utils .AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
65
+ rootCertificate := utils .CreateTestNocRoot1Cert ()
66
+ utils .AddNocRootCertificate (setup , accAddress , rootCertificate .PEM )
63
67
64
68
// Store the NOC certificate
65
- newNocCertificate := types .NewNocCertificate (
66
- testconstants .NocCert1 ,
67
- testconstants .NocCert1Subject ,
68
- testconstants .NocCert1SubjectAsText ,
69
- testconstants .NocCert1SubjectKeyID ,
70
- testconstants .NocCert1SerialNumber ,
71
- testconstants .NocRootCert1Subject ,
72
- testconstants .NocRootCert1SubjectKeyID ,
73
- testconstants .NocRootCert1Subject ,
74
- testconstants .NocRootCert1SubjectKeyID ,
75
- accAddress .String (),
76
- vid ,
77
- testconstants .SchemaVersion ,
78
- )
79
- newNocCertificate .SerialNumber = testconstants .TestSerialNumber
80
-
81
- setup .Keeper .AddAllCertificate (setup .Ctx , newNocCertificate )
82
- setup .Keeper .AddNocCertificate (setup .Ctx , newNocCertificate )
83
- setup .Keeper .AddNocCertificateBySubjectKeyID (setup .Ctx , newNocCertificate )
84
- setup .Keeper .AddNocCertificateBySubject (setup .Ctx , newNocCertificate )
85
- setup .Keeper .AddNocIcaCertificate (setup .Ctx , newNocCertificate )
86
- uniqueCertificate := types.UniqueCertificate {
87
- Issuer : newNocCertificate .Issuer ,
88
- SerialNumber : newNocCertificate .SerialNumber ,
89
- Present : true ,
90
- }
91
- setup .Keeper .SetUniqueCertificate (setup .Ctx , uniqueCertificate )
69
+ icaCertificate := utils .CreateTestNocIca1Cert ()
70
+ intermediateCertificate := utils .NocIntermediateCertificate (accAddress )
71
+ intermediateCertificate .SerialNumber = testconstants .TestSerialNumber
72
+ utils .AddMokedNocCertificate (setup , intermediateCertificate , false )
92
73
93
74
// add the new NOC certificate
94
- addNocX509Cert := types .NewMsgAddNocX509IcaCert (accAddress .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
75
+ addNocX509Cert := types .NewMsgAddNocX509IcaCert (
76
+ accAddress .String (),
77
+ icaCertificate .PEM ,
78
+ testconstants .CertSchemaVersion )
95
79
_ , err := setup .Handler (setup .Ctx , addNocX509Cert )
96
80
require .NoError (t , err )
97
81
98
82
// query noc certificate by Subject and SKID
99
- nocCertificates , err := utils .QueryNocCertificates (setup , newNocCertificate .Subject , newNocCertificate .SubjectKeyId )
100
- require .NoError (t , err )
101
- require .Equal (t , len (nocCertificates .Certs ), 2 )
102
- require .Equal (t , & newNocCertificate , nocCertificates .Certs [0 ])
103
-
104
- // query noc certificate by Subject
105
- nocCertificatesBySubject , err := utils .QueryNocCertificatesBySubject (setup , newNocCertificate .Subject )
106
- require .NoError (t , err )
107
- require .Equal (t , 1 , len (nocCertificatesBySubject .SubjectKeyIds ))
108
-
109
- // query noc certificate by SKID
110
- nocCertificatesBySubjectKeyID , err := utils .QueryNocCertificatesBySubjectKeyID (setup , newNocCertificate .SubjectKeyId )
111
- require .NoError (t , err )
112
- require .Equal (t , 1 , len (nocCertificatesBySubjectKeyID ))
113
- require .Equal (t , 2 , len (nocCertificatesBySubjectKeyID [0 ].Certs ))
114
- require .Equal (t , testconstants .NocCert1Subject , nocCertificatesBySubjectKeyID [0 ].Certs [0 ].Subject )
115
- require .Equal (t , testconstants .NocCert1SubjectKeyID , nocCertificatesBySubjectKeyID [0 ].Certs [0 ].SubjectKeyId )
116
- require .Equal (t , vid , nocCertificatesBySubjectKeyID [0 ].Certs [0 ].Vid )
117
-
118
- // query noc certificate by VID
119
- nocCertificatesByVid , err := utils .QueryNocIcaCertificatesByVid (setup , testconstants .Vid )
120
- require .NoError (t , err )
121
- require .Equal (t , len (nocCertificatesByVid .Certs ), 2 )
122
- require .Equal (t , testconstants .NocCert1Subject , nocCertificatesByVid .Certs [0 ].Subject )
123
- require .Equal (t , testconstants .NocCert1SubjectKeyID , nocCertificatesByVid .Certs [0 ].SubjectKeyId )
124
- require .Equal (t , vid , nocCertificatesByVid .Certs [0 ].Vid )
83
+ indexes := utils.TestIndexes {
84
+ Present : []utils.TestIndex {
85
+ {Key : types .AllCertificatesKeyPrefix , Count : 2 },
86
+ {Key : types .AllCertificatesBySubjectKeyPrefix },
87
+ {Key : types .AllCertificatesBySubjectKeyIDKeyPrefix , Count : 2 },
88
+ {Key : types .NocCertificatesKeyPrefix , Count : 2 },
89
+ {Key : types .NocCertificatesBySubjectKeyPrefix },
90
+ {Key : types .NocCertificatesBySubjectKeyIDKeyPrefix , Count : 2 },
91
+ {Key : types .NocCertificatesByVidAndSkidKeyPrefix , Count : 2 },
92
+ {Key : types .NocRootCertificatesKeyPrefix , Count : 1 }, // we create root certificate as well but ica should not be there
93
+ {Key : types .NocIcaCertificatesKeyPrefix , Count : 2 },
94
+ {Key : types .UniqueCertificateKeyPrefix },
95
+ {Key : types .ChildCertificatesKeyPrefix },
96
+ },
97
+ Missing : []utils.TestIndex {
98
+ {Key : types .ProposedCertificateKeyPrefix },
99
+ {Key : types .ApprovedCertificatesKeyPrefix },
100
+ {Key : types .ApprovedCertificatesBySubjectKeyPrefix },
101
+ {Key : types .ApprovedCertificatesBySubjectKeyIDKeyPrefix },
102
+ {Key : types .ApprovedRootCertificatesKeyPrefix },
103
+ },
104
+ }
105
+ utils .CheckCertificateStateIndexes (t , setup , icaCertificate , indexes )
125
106
}
126
107
127
108
// Error cases
0 commit comments