1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * test_comcrlselparams.c
40 * Test ComCRLSelParams Type
45 #include "testutil_nss.h"
47 void *plContext
= NULL
;
50 testIssuer(PKIX_ComCRLSelParams
*goodObject
)
52 PKIX_PL_String
*issuer1String
= NULL
;
53 PKIX_PL_String
*issuer2String
= NULL
;
54 PKIX_PL_String
*issuer3String
= NULL
;
55 PKIX_PL_X500Name
*issuerName1
= NULL
;
56 PKIX_PL_X500Name
*issuerName2
= NULL
;
57 PKIX_PL_X500Name
*issuerName3
= NULL
;
58 PKIX_List
*setIssuerList
= NULL
;
59 PKIX_List
*getIssuerList
= NULL
;
60 PKIX_PL_String
*issuerListString
= NULL
;
61 char *name1
= "CN=yassir,OU=bcn,OU=east,O=sun,C=us";
62 char *name2
= "CN=richard,OU=bcn,OU=east,O=sun,C=us";
63 char *name3
= "CN=hanfei,OU=bcn,OU=east,O=sun,C=us";
65 PKIX_Boolean result
= PKIX_FALSE
;
67 "(CN=yassir,OU=bcn,OU=east,O=sun,"
68 "C=us, CN=richard,OU=bcn,OU=east,O=sun,C=us, "
69 "CN=hanfei,OU=bcn,OU=east,O=sun,C=us)";
73 subTest("PKIX_ComCRLSelParams Create Issuers");
75 length
= PL_strlen(name1
);
77 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
84 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create(issuer1String
,
88 length
= PL_strlen(name2
);
90 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
97 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create(issuer2String
,
101 length
= PL_strlen(name3
);
103 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
110 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create
115 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&setIssuerList
, plContext
));
117 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
119 (PKIX_PL_Object
*)issuerName1
,
122 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
124 (PKIX_PL_Object
*)issuerName2
,
127 subTest("PKIX_ComCRLSelParams_AddIssuerName");
129 /* Test adding an issuer to an empty list */
130 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_AddIssuerName
131 (goodObject
, issuerName3
, plContext
));
133 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
135 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
136 (goodObject
, &getIssuerList
, plContext
));
138 /* DECREF for GetIssuerNames */
139 PKIX_TEST_DECREF_BC(getIssuerList
);
140 /* DECREF for AddIssuerName so next SetIssuerName start clean */
141 PKIX_TEST_DECREF_BC(getIssuerList
);
143 /* Test setting issuer names on the list */
144 subTest("PKIX_ComCRLSelParams_SetIssuerNames");
146 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetIssuerNames
147 (goodObject
, setIssuerList
, plContext
));
149 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
151 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
152 (goodObject
, &getIssuerList
, plContext
));
154 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
155 ((PKIX_PL_Object
*)setIssuerList
,
156 (PKIX_PL_Object
*)getIssuerList
,
160 if (result
!= PKIX_TRUE
) {
161 pkixTestErrorMsg
= "unexpected Issuers mismatch";
164 /* Test adding an issuer to existing list */
165 subTest("PKIX_ComCRLSelParams_AddIssuerName");
167 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_AddIssuerName
168 (goodObject
, issuerName3
, plContext
));
170 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
171 PKIX_TEST_DECREF_BC(getIssuerList
);
173 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
174 (goodObject
, &getIssuerList
, plContext
));
177 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
178 ((PKIX_PL_Object
*)getIssuerList
,
182 testToStringHelper((PKIX_PL_Object
*)getIssuerList
,
183 expectedAscii
, plContext
);
187 PKIX_TEST_DECREF_AC(issuer1String
);
188 PKIX_TEST_DECREF_AC(issuer2String
);
189 PKIX_TEST_DECREF_AC(issuer3String
);
190 PKIX_TEST_DECREF_AC(issuerListString
);
191 PKIX_TEST_DECREF_AC(issuerName1
);
192 PKIX_TEST_DECREF_AC(issuerName2
);
193 PKIX_TEST_DECREF_AC(issuerName3
);
194 PKIX_TEST_DECREF_AC(setIssuerList
);
195 PKIX_TEST_DECREF_AC(getIssuerList
);
201 void testCertificateChecking(
202 char *dataCentralDir
,
204 PKIX_ComCRLSelParams
*goodObject
)
206 PKIX_PL_Cert
*setCert
= NULL
;
207 PKIX_PL_Cert
*getCert
= NULL
;
208 PKIX_Boolean result
= PKIX_FALSE
;
210 PKIX_TEST_STD_VARS();
212 subTest("Test CertificateChecking Cert Create");
213 setCert
= createCert(dataCentralDir
, goodInput
, plContext
);
214 if (setCert
== NULL
) {
215 pkixTestErrorMsg
= "create certificate failed";
219 subTest("PKIX_ComCRLSelParams_SetCertificateChecking");
221 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetCertificateChecking
222 (goodObject
, setCert
, plContext
));
224 subTest("PKIX_ComCRLSelParams_GetCertificateChecking");
226 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetCertificateChecking
227 (goodObject
, &getCert
, plContext
));
229 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
230 ((PKIX_PL_Object
*)setCert
,
231 (PKIX_PL_Object
*)getCert
,
232 &result
, plContext
));
234 if (result
!= PKIX_TRUE
) {
235 pkixTestErrorMsg
= "unexpected Cert mismatch";
240 PKIX_TEST_DECREF_AC(setCert
);
241 PKIX_TEST_DECREF_AC(getCert
);
246 void testDateAndTime(PKIX_ComCRLSelParams
*goodObject
){
248 PKIX_PL_Date
*setDate
= NULL
;
249 PKIX_PL_Date
*getDate
= NULL
;
250 char *asciiDate
= "040329134847Z";
251 PKIX_Boolean result
= PKIX_FALSE
;
253 PKIX_TEST_STD_VARS();
255 subTest("PKIX_ComCRLSelParams_Date Create");
256 setDate
= createDate(asciiDate
, plContext
);
258 subTest("PKIX_ComCRLSelParams_SetDateAndTime");
259 PKIX_TEST_EXPECT_NO_ERROR
260 (PKIX_ComCRLSelParams_SetDateAndTime
261 (goodObject
, setDate
, plContext
));
263 subTest("PKIX_ComCRLSelParams_GetDateAndTime");
264 PKIX_TEST_EXPECT_NO_ERROR
265 (PKIX_ComCRLSelParams_GetDateAndTime
266 (goodObject
, &getDate
, plContext
));
268 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
269 ((PKIX_PL_Object
*)setDate
,
270 (PKIX_PL_Object
*)getDate
,
271 &result
, plContext
));
273 if (result
!= PKIX_TRUE
) {
274 pkixTestErrorMsg
= "unexpected DateAndTime mismatch";
279 PKIX_TEST_DECREF_AC(setDate
);
280 PKIX_TEST_DECREF_AC(getDate
);
285 void testMaxMinCRLNumbers(PKIX_ComCRLSelParams
*goodObject
){
286 PKIX_PL_BigInt
*setMaxCrlNumber
= NULL
;
287 PKIX_PL_BigInt
*getMaxCrlNumber
= NULL
;
288 PKIX_PL_BigInt
*setMinCrlNumber
= NULL
;
289 PKIX_PL_BigInt
*getMinCrlNumber
= NULL
;
290 char *asciiCrlNumber1
= "01";
291 char *asciiCrlNumber99999
= "0909090909";
292 PKIX_PL_String
*crlNumber1String
= NULL
;
293 PKIX_PL_String
*crlNumber99999String
= NULL
;
295 PKIX_Boolean result
= PKIX_FALSE
;
297 PKIX_TEST_STD_VARS();
299 subTest("PKIX_ComCRLSelParams_SetMinCRLNumber");
301 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
304 PL_strlen(asciiCrlNumber1
),
308 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create
309 (crlNumber1String
, &setMinCrlNumber
, NULL
));
311 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetMinCRLNumber
312 (goodObject
, setMinCrlNumber
, NULL
));
314 subTest("PKIX_ComCRLSelParams_GetMinCRLNumber");
316 PKIX_TEST_EXPECT_NO_ERROR
317 (PKIX_ComCRLSelParams_GetMinCRLNumber
318 (goodObject
, &getMinCrlNumber
, NULL
));
320 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
321 ((PKIX_PL_Object
*)setMinCrlNumber
,
322 (PKIX_PL_Object
*)getMinCrlNumber
,
325 if (result
!= PKIX_TRUE
) {
326 pkixTestErrorMsg
= "unexpected Minimum CRL Number mismatch";
329 subTest("PKIX_ComCRLSelParams_SetMaxCRLNumber");
331 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
334 PL_strlen(asciiCrlNumber99999
),
335 &crlNumber99999String
,
338 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create
339 (crlNumber99999String
, &setMaxCrlNumber
, NULL
));
341 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetMaxCRLNumber
342 (goodObject
, setMaxCrlNumber
, NULL
));
344 subTest("PKIX_ComCRLSelParams_GetMaxCRLNumber");
346 PKIX_TEST_EXPECT_NO_ERROR
347 (PKIX_ComCRLSelParams_GetMaxCRLNumber
348 (goodObject
, &getMaxCrlNumber
, NULL
));
350 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
351 ((PKIX_PL_Object
*)setMaxCrlNumber
,
352 (PKIX_PL_Object
*)getMaxCrlNumber
,
355 if (result
!= PKIX_TRUE
) {
356 pkixTestErrorMsg
= "unexpected Maximum CRL Number mismatch";
361 PKIX_TEST_DECREF_AC(setMaxCrlNumber
);
362 PKIX_TEST_DECREF_AC(getMaxCrlNumber
);
363 PKIX_TEST_DECREF_AC(setMinCrlNumber
);
364 PKIX_TEST_DECREF_AC(getMinCrlNumber
);
365 PKIX_TEST_DECREF_AC(crlNumber1String
);
366 PKIX_TEST_DECREF_AC(crlNumber99999String
);
371 void testDuplicate(PKIX_ComCRLSelParams
*goodObject
){
373 PKIX_ComCRLSelParams
*dupObject
= NULL
;
374 PKIX_Boolean result
= PKIX_FALSE
;
376 PKIX_TEST_STD_VARS();
378 subTest("PKIX_ComCRLSelParams_Duplicate");
379 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Duplicate
380 ((PKIX_PL_Object
*)goodObject
,
381 (PKIX_PL_Object
**)&dupObject
,
384 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
385 ((PKIX_PL_Object
*)goodObject
,
386 (PKIX_PL_Object
*)dupObject
,
387 &result
, plContext
));
389 if (result
!= PKIX_TRUE
) {
391 "unexpected Duplicate ComCRLSelParams mismatch";
396 PKIX_TEST_DECREF_AC(dupObject
);
400 void printUsage(char *pName
){
401 printf("\nUSAGE: %s <central-data-dir>\n\n", pName
);
404 /* Functional tests for ComCRLSelParams public functions */
406 int main(int argc
, char *argv
[]){
408 char *dataCentralDir
= NULL
;
409 char *goodInput
= "yassir2yassir";
410 PKIX_ComCRLSelParams
*goodObject
= NULL
;
411 PKIX_ComCRLSelParams
*diffObject
= NULL
;
412 PKIX_UInt32 actualMinorVersion
;
414 PKIX_Boolean useArenas
= PKIX_FALSE
;
416 PKIX_TEST_STD_VARS();
418 startTests("ComCRLSelParams");
420 useArenas
= PKIX_TEST_ARENAS_ARG(argv
[1]);
422 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
423 (PKIX_TRUE
, /* nssInitNeeded */
436 dataCentralDir
= argv
[j
+1];
438 subTest("PKIX_ComCRLSelParams_Create");
440 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_Create
444 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_Create
448 testIssuer(goodObject
);
450 testCertificateChecking(dataCentralDir
, goodInput
, goodObject
);
452 testDateAndTime(goodObject
);
454 testMaxMinCRLNumbers(goodObject
);
456 testDuplicate(goodObject
);
458 PKIX_TEST_EQ_HASH_TOSTR_DUP
468 PKIX_TEST_DECREF_AC(goodObject
);
469 PKIX_TEST_DECREF_AC(diffObject
);
471 PKIX_Shutdown(plContext
);
475 endTests("ComCRLSelParams");