@@ -18,15 +18,13 @@ import (
18
18
func TestHandler_AddNocIntermediateCert (t * testing.T ) {
19
19
setup := utils .Setup (t )
20
20
21
- accAddress := setup .CreateVendorAccount (testconstants .Vid )
22
-
23
21
// add NOC root certificate
24
22
rootCertificate := utils .CreateTestNocRoot1Cert ()
25
- utils .AddNocRootCertificate (setup , accAddress , rootCertificate .PEM )
23
+ utils .AddNocRootCertificate (setup , setup . Vendor1 , rootCertificate .PEM )
26
24
27
25
// add NOC ICA certificate
28
26
icaCertificate := utils .CreateTestNocIca1Cert ()
29
- utils .AddNocIntermediateCertificate (setup , accAddress , icaCertificate .PEM )
27
+ utils .AddNocIntermediateCertificate (setup , setup . Vendor1 , icaCertificate .PEM )
30
28
31
29
// Check indexes
32
30
indexes := utils.TestIndexes {
@@ -38,7 +36,7 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
38
36
{Key : types .NocCertificatesBySubjectKeyPrefix },
39
37
{Key : types .NocCertificatesBySubjectKeyIDKeyPrefix },
40
38
{Key : types .NocCertificatesByVidAndSkidKeyPrefix },
41
- {Key : types .NocRootCertificatesKeyPrefix , Count : 1 }, // we create root certificate as well but ica should not be there
39
+ {Key : types .NocRootCertificatesKeyPrefix , Count : 1 }, // we created root certificate with same vid
42
40
{Key : types .NocIcaCertificatesKeyPrefix },
43
41
{Key : types .UniqueCertificateKeyPrefix },
44
42
{Key : types .ChildCertificatesKeyPrefix },
@@ -59,25 +57,18 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
59
57
func TestHandler_AddNocIntermediateCert_SameSubjectAndSkid_DifferentSerialNumber (t * testing.T ) {
60
58
setup := utils .Setup (t )
61
59
62
- accAddress := setup .CreateVendorAccount (testconstants .Vid )
63
-
64
60
// add NOC root certificate
65
61
rootCertificate := utils .CreateTestNocRoot1Cert ()
66
- utils .AddNocRootCertificate (setup , accAddress , rootCertificate .PEM )
62
+ utils .AddNocRootCertificate (setup , setup . Vendor1 , rootCertificate .PEM )
67
63
68
- // Store the NOC certificate
69
- icaCertificate := utils .CreateTestNocIca1Cert ()
70
- intermediateCertificate := utils .NocIntermediateCertificate (accAddress )
64
+ // Store the NOC certificate with different serial number
65
+ intermediateCertificate := utils .NocIntermediateCertificate (setup .Vendor1 )
71
66
intermediateCertificate .SerialNumber = testconstants .TestSerialNumber
72
67
utils .AddMokedNocCertificate (setup , intermediateCertificate , false )
73
68
74
69
// add the new NOC certificate
75
- addNocX509Cert := types .NewMsgAddNocX509IcaCert (
76
- accAddress .String (),
77
- icaCertificate .PEM ,
78
- testconstants .CertSchemaVersion )
79
- _ , err := setup .Handler (setup .Ctx , addNocX509Cert )
80
- require .NoError (t , err )
70
+ icaCertificate := utils .CreateTestNocIca1Cert ()
71
+ utils .AddNocIntermediateCertificate (setup , setup .Vendor1 , icaCertificate .PEM )
81
72
82
73
// query noc certificate by Subject and SKID
83
74
indexes := utils.TestIndexes {
@@ -119,15 +110,10 @@ func TestHandler_AddNocX509Cert_SenderNotVendor(t *testing.T) {
119
110
func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
120
111
setup := utils .Setup (t )
121
112
122
- accAddress := utils .GenerateAccAddress ()
123
- vid := testconstants .Vid
124
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
125
-
126
113
// add NOC root certificate
127
- utils .AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
114
+ utils .AddNocRootCertificate (setup , setup . Vendor1 , testconstants .NocRootCert1 )
128
115
129
- newAccAddress := utils .GenerateAccAddress ()
130
- setup .AddAccount (newAccAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, 1111 )
116
+ newAccAddress := setup .CreateVendorAccount (1111 )
131
117
132
118
// try to add NOC certificate
133
119
nocX509Cert := types .NewMsgAddNocX509IcaCert (newAccAddress .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
@@ -138,36 +124,24 @@ func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID(t *testing
138
124
func TestHandler_AddNocX509Cert_ForInvalidCertificate (t * testing.T ) {
139
125
setup := utils .Setup (t )
140
126
141
- accAddress := utils .GenerateAccAddress ()
142
- vid := testconstants .Vid
143
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
144
-
145
127
// add x509 certificate
146
- addX509Cert := types .NewMsgAddNocX509IcaCert (accAddress .String (), testconstants .StubCertPem , testconstants .CertSchemaVersion )
128
+ addX509Cert := types .NewMsgAddNocX509IcaCert (setup . Vendor1 .String (), testconstants .StubCertPem , testconstants .CertSchemaVersion )
147
129
_ , err := setup .Handler (setup .Ctx , addX509Cert )
148
130
require .ErrorIs (t , err , pkitypes .ErrInvalidCertificate )
149
131
}
150
132
151
133
func TestHandler_AddXNoc509Cert_ForNocRootCertificate (t * testing.T ) {
152
134
setup := utils .Setup (t )
153
135
154
- accAddress := utils .GenerateAccAddress ()
155
- vid := testconstants .Vid
156
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
157
-
158
136
// try to add root certificate x509 certificate
159
- addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .NocRootCert1 , testconstants .CertSchemaVersion )
137
+ addX509Cert := types .NewMsgAddX509Cert (setup . Vendor1 .String (), testconstants .NocRootCert1 , testconstants .CertSchemaVersion )
160
138
_ , err := setup .Handler (setup .Ctx , addX509Cert )
161
139
require .ErrorIs (t , err , pkitypes .ErrNonRootCertificateSelfSigned )
162
140
}
163
141
164
142
func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate (t * testing.T ) {
165
143
setup := utils .Setup (t )
166
144
167
- accAddress := utils .GenerateAccAddress ()
168
- vid := testconstants .Vid
169
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
170
-
171
145
// store root certificate
172
146
rootCertOptions := & utils.RootCertOptions {
173
147
PemCert : testconstants .RootCertWithVid ,
@@ -179,20 +153,16 @@ func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate(t *testing.T) {
179
153
utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
180
154
181
155
// try to add root certificate x509 certificate
182
- addX509Cert := types .NewMsgAddNocX509IcaCert (accAddress .String (), testconstants .IntermediateCertWithVid1 , testconstants .CertSchemaVersion )
156
+ addX509Cert := types .NewMsgAddNocX509IcaCert (setup . Vendor1 .String (), testconstants .IntermediateCertWithVid1 , testconstants .CertSchemaVersion )
183
157
_ , err := setup .Handler (setup .Ctx , addX509Cert )
184
158
require .ErrorIs (t , err , pkitypes .ErrInappropriateCertificateType )
185
159
}
186
160
187
161
func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent (t * testing.T ) {
188
162
setup := utils .Setup (t )
189
163
190
- accAddress := utils .GenerateAccAddress ()
191
- vid := testconstants .Vid
192
- setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
193
-
194
164
// add the new NOC certificate
195
- addNocX509Cert := types .NewMsgAddNocX509IcaCert (accAddress .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
165
+ addNocX509Cert := types .NewMsgAddNocX509IcaCert (setup . Vendor1 .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
196
166
_ , err := setup .Handler (setup .Ctx , addNocX509Cert )
197
167
198
168
require .ErrorIs (t , err , pkitypes .ErrCertificateDoesNotExist )
0 commit comments