@@ -52,8 +52,6 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
52
52
utils .CheckCertificateStateIndexes (t , setup , icaCertificate , indexes )
53
53
}
54
54
55
- // Extra cases
56
-
57
55
func TestHandler_AddNocIntermediateCert_SameSubjectAndSkid_DifferentSerialNumber (t * testing.T ) {
58
56
setup := utils .Setup (t )
59
57
@@ -96,18 +94,68 @@ func TestHandler_AddNocIntermediateCert_SameSubjectAndSkid_DifferentSerialNumber
96
94
utils .CheckCertificateStateIndexes (t , setup , icaCertificate , indexes )
97
95
}
98
96
97
+ func TestHandler_AddNocIntermediateCert_ByNotOwnerButSameVendor (t * testing.T ) {
98
+ setup := utils .Setup (t )
99
+
100
+ // add two vendors with the same VID
101
+ vendorAccAddress1 := setup .CreateVendorAccount (testconstants .Vid )
102
+ vendorAccAddress2 := setup .CreateVendorAccount (testconstants .Vid )
103
+
104
+ // add NOC root certificate
105
+ rootCertificate := utils .RootNocCertificate1 (vendorAccAddress1 )
106
+ utils .AddNocRootCertificate (setup , rootCertificate )
107
+
108
+ // add the new NOC certificate by first vendor
109
+ icaCertificate := utils .IntermediateNocCertificate1 (vendorAccAddress1 )
110
+ utils .AddNocIntermediateCertificate (setup , icaCertificate )
111
+
112
+ // add the new NOC certificate by second vendor
113
+ icaCertificate2 := utils .IntermediateNocCertificate1Copy (vendorAccAddress2 )
114
+ utils .AddNocIntermediateCertificate (setup , icaCertificate2 )
115
+
116
+ // Check state indexes
117
+ indexes := utils.TestIndexes {
118
+ Present : []utils.TestIndex {
119
+ {Key : types .AllCertificatesKeyPrefix , Count : 2 },
120
+ {Key : types .AllCertificatesBySubjectKeyPrefix },
121
+ {Key : types .AllCertificatesBySubjectKeyIDKeyPrefix , Count : 2 },
122
+ {Key : types .NocCertificatesKeyPrefix , Count : 2 },
123
+ {Key : types .NocCertificatesBySubjectKeyPrefix },
124
+ {Key : types .NocCertificatesBySubjectKeyIDKeyPrefix , Count : 2 },
125
+ {Key : types .NocCertificatesByVidAndSkidKeyPrefix , Count : 2 },
126
+ {Key : types .NocRootCertificatesKeyPrefix , Count : 1 }, // we create root certificate as well but ica should not be there
127
+ {Key : types .NocIcaCertificatesKeyPrefix , Count : 2 },
128
+ {Key : types .UniqueCertificateKeyPrefix },
129
+ {Key : types .ChildCertificatesKeyPrefix },
130
+ },
131
+ Missing : []utils.TestIndex {
132
+ {Key : types .ProposedCertificateKeyPrefix },
133
+ {Key : types .ApprovedCertificatesKeyPrefix },
134
+ {Key : types .ApprovedCertificatesBySubjectKeyPrefix },
135
+ {Key : types .ApprovedCertificatesBySubjectKeyIDKeyPrefix },
136
+ {Key : types .ApprovedRootCertificatesKeyPrefix },
137
+ },
138
+ }
139
+ utils .CheckCertificateStateIndexes (t , setup , icaCertificate , indexes )
140
+ utils .CheckCertificateStateIndexes (t , setup , icaCertificate2 , indexes )
141
+ }
142
+
99
143
// Error cases
100
144
101
- func TestHandler_AddNocX509Cert_SenderNotVendor (t * testing.T ) {
145
+ func TestHandler_AddNocIntermediateCert_SenderNotVendor (t * testing.T ) {
102
146
setup := utils .Setup (t )
103
147
148
+ // add NOC root certificate
149
+ rootCertificate := utils .RootNocCertificate1 (setup .Vendor1 )
150
+ utils .AddNocRootCertificate (setup , rootCertificate )
151
+
104
152
addNocX509Cert := types .NewMsgAddNocX509IcaCert (setup .Trustee1 .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
105
153
_ , err := setup .Handler (setup .Ctx , addNocX509Cert )
106
154
107
155
require .ErrorIs (t , err , sdkerrors .ErrUnauthorized )
108
156
}
109
157
110
- func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
158
+ func TestHandler_AddNocIntermediateCert_Root_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
111
159
setup := utils .Setup (t )
112
160
113
161
// add NOC root certificate
@@ -122,7 +170,7 @@ func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID(t *testing
122
170
require .ErrorIs (t , err , pkitypes .ErrCertVidNotEqualAccountVid )
123
171
}
124
172
125
- func TestHandler_AddNocX509Cert_ForInvalidCertificate (t * testing.T ) {
173
+ func TestHandler_AddNocIntermediateCert_ForInvalidCertificate (t * testing.T ) {
126
174
setup := utils .Setup (t )
127
175
128
176
// add x509 certificate
@@ -131,7 +179,7 @@ func TestHandler_AddNocX509Cert_ForInvalidCertificate(t *testing.T) {
131
179
require .ErrorIs (t , err , pkitypes .ErrInvalidCertificate )
132
180
}
133
181
134
- func TestHandler_AddXNoc509Cert_ForNocRootCertificate (t * testing.T ) {
182
+ func TestHandler_AddNocIntermediateCert_ForNocRootCertificate (t * testing.T ) {
135
183
setup := utils .Setup (t )
136
184
137
185
// try to add root certificate x509 certificate
@@ -140,11 +188,10 @@ func TestHandler_AddXNoc509Cert_ForNocRootCertificate(t *testing.T) {
140
188
require .ErrorIs (t , err , pkitypes .ErrNonRootCertificateSelfSigned )
141
189
}
142
190
143
- func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate (t * testing.T ) {
191
+ func TestHandler_AddNocIntermediateCert_ForRootNonNocCertificate (t * testing.T ) {
144
192
setup := utils .Setup (t )
145
193
146
194
// store root certificate
147
-
148
195
rootCert := utils .RootDaCertificateWithVid (setup .Trustee1 )
149
196
utils .ProposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCert )
150
197
@@ -154,7 +201,7 @@ func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate(t *testing.T) {
154
201
require .ErrorIs (t , err , pkitypes .ErrInappropriateCertificateType )
155
202
}
156
203
157
- func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent (t * testing.T ) {
204
+ func TestHandler_AddNocIntermediateCert_WhenNocRootCertIsAbsent (t * testing.T ) {
158
205
setup := utils .Setup (t )
159
206
160
207
// add the new NOC certificate
@@ -164,7 +211,7 @@ func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent(t *testing.T) {
164
211
require .ErrorIs (t , err , pkitypes .ErrCertificateDoesNotExist )
165
212
}
166
213
167
- func TestHandler_AddNocX509Cert_CertificateExist (t * testing.T ) {
214
+ func TestHandler_AddNocIntermediateCert_CertificateExist (t * testing.T ) {
168
215
accAddress := utils .GenerateAccAddress ()
169
216
170
217
cases := []struct {
0 commit comments