Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / cmd / libpkix / pkix / params / test_valparams.c
blob5a4c80cfb9a355c24f8bb3284d249404a33021b7
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
12 * License.
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.
21 * Contributor(s):
22 * Sun Microsystems
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_valparams.c
40 * Test ValidateParams Type
44 #include "testutil.h"
45 #include "testutil_nss.h"
47 void *plContext = NULL;
49 static void
50 testDestroy(void *goodObject, void *equalObject, void *diffObject)
52 PKIX_TEST_STD_VARS();
54 subTest("PKIX_ValidateParams_Destroy");
56 PKIX_TEST_DECREF_BC(goodObject);
57 PKIX_TEST_DECREF_BC(equalObject);
58 PKIX_TEST_DECREF_BC(diffObject);
60 cleanup:
62 PKIX_TEST_RETURN();
66 void testGetProcParams(
67 PKIX_ValidateParams *goodObject,
68 PKIX_ValidateParams *equalObject){
70 PKIX_ProcessingParams *goodProcParams = NULL;
71 PKIX_ProcessingParams *equalProcParams = NULL;
73 PKIX_TEST_STD_VARS();
74 subTest("PKIX_ValidateParams_GetProcessingParams");
76 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetProcessingParams
77 (goodObject, &goodProcParams, plContext));
79 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetProcessingParams
80 (equalObject, &equalProcParams, plContext));
82 testEqualsHelper
83 ((PKIX_PL_Object *)goodProcParams,
84 (PKIX_PL_Object *)equalProcParams,
85 PKIX_TRUE,
86 plContext);
88 cleanup:
90 PKIX_TEST_DECREF_AC(goodProcParams);
91 PKIX_TEST_DECREF_AC(equalProcParams);
93 PKIX_TEST_RETURN();
97 void testGetCertChain(
98 PKIX_ValidateParams *goodObject,
99 PKIX_ValidateParams *equalObject){
101 PKIX_List *goodChain = NULL;
102 PKIX_List *equalChain = NULL;
104 PKIX_TEST_STD_VARS();
105 subTest("PKIX_ValidateParams_GetCertChain");
107 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetCertChain
108 (goodObject, &goodChain, plContext));
110 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ValidateParams_GetCertChain
111 (equalObject, &equalChain, plContext));
113 testEqualsHelper
114 ((PKIX_PL_Object *)goodChain,
115 (PKIX_PL_Object *)equalChain,
116 PKIX_TRUE,
117 plContext);
119 cleanup:
121 PKIX_TEST_DECREF_AC(goodChain);
122 PKIX_TEST_DECREF_AC(equalChain);
124 PKIX_TEST_RETURN();
127 void printUsage(char *pName){
128 printf("\nUSAGE: %s <central-data-dir>\n\n", pName);
131 int main(int argc, char *argv[]) {
133 PKIX_ValidateParams *goodObject = NULL;
134 PKIX_ValidateParams *equalObject = NULL;
135 PKIX_ValidateParams *diffObject = NULL;
136 PKIX_List *chain = NULL;
137 PKIX_UInt32 actualMinorVersion;
138 PKIX_UInt32 j = 0;
139 char *dirName = NULL;
140 PKIX_Boolean useArenas = PKIX_FALSE;
142 char *goodInput = "yassir2yassir";
143 char *diffInput = "yassir2bcn";
145 char *expectedAscii =
146 "[\n"
147 "\tProcessing Params: \n"
148 "\t********BEGIN PROCESSING PARAMS********\n"
149 "\t\t"
150 "[\n"
151 "\tTrust Anchors: \n"
152 "\t********BEGIN LIST OF TRUST ANCHORS********\n"
153 "\t\t"
154 "([\n"
155 "\tTrusted CA Name: "
156 "CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
157 "\tTrusted CA PublicKey: ANSI X9.57 DSA Signature\n"
158 "\tInitial Name Constraints:(null)\n"
159 "]\n"
160 ", [\n"
161 "\tTrusted CA Name: OU=bcn,OU=east,O=sun,C=us\n"
162 "\tTrusted CA PublicKey: ANSI X9.57 DSA Signature\n"
163 "\tInitial Name Constraints:(null)\n"
164 "]\n"
165 ")\n"
166 "\t********END LIST OF TRUST ANCHORS********\n"
167 "\tDate: \t\t(null)\n"
168 "\tTarget Constraints: (null)\n"
169 "\tInitial Policies: (null)\n"
170 "\tQualifiers Rejected: FALSE\n"
171 "\tCert Stores: (EMPTY)\n"
172 "\tCRL Checking Enabled: 0\n"
173 "]\n"
174 "\n"
175 "\t********END PROCESSING PARAMS********\n"
176 "\tChain: \t\t"
177 "([\n"
178 "\tVersion: v3\n"
179 "\tSerialNumber: 37bc66ec\n"
180 "\tIssuer: CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
181 "\tSubject: OU=bcn,OU=east,O=sun,C=us\n"
182 "\tValidity: [From: Thu Aug 19 16:19:56 1999\n"
183 "\t To: Fri Aug 18 16:19:56 2000]\n"
184 "\tSubjectAltNames: (null)\n"
185 "\tAuthorityKeyId: (null)\n"
186 "\tSubjectKeyId: (null)\n"
187 "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
188 "\tCritExtOIDs: (2.5.29.15, 2.5.29.19)\n"
189 "\tExtKeyUsages: (null)\n"
190 "\tBasicConstraint: CA(0)\n"
191 "\tCertPolicyInfo: (null)\n"
192 "\tPolicyMappings: (null)\n"
193 "\tExplicitPolicy: -1\n"
194 "\tInhibitMapping: -1\n"
195 "\tInhibitAnyPolicy:-1\n"
196 "\tNameConstraints: (null)\n"
197 "]\n"
198 ", [\n"
199 "\tVersion: v3\n"
200 "\tSerialNumber: 37bc65af\n"
201 "\tIssuer: CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
202 "\tSubject: CN=yassir,OU=bcn,OU=east,O=sun,C=us\n"
203 "\tValidity: [From: Thu Aug 19 16:14:39 1999\n"
204 "\t To: Fri Aug 18 16:14:39 2000]\n"
205 "\tSubjectAltNames: (null)\n"
206 "\tAuthorityKeyId: (null)\n"
207 "\tSubjectKeyId: (null)\n"
208 "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
209 "\tCritExtOIDs: (2.5.29.15, 2.5.29.19)\n"
210 "\tExtKeyUsages: (null)\n"
211 "\tBasicConstraint: CA(0)\n"
212 "\tCertPolicyInfo: (null)\n"
213 "\tPolicyMappings: (null)\n"
214 "\tExplicitPolicy: -1\n"
215 "\tInhibitMapping: -1\n"
216 "\tInhibitAnyPolicy:-1\n"
217 "\tNameConstraints: (null)\n"
218 "]\n"
219 ")\n"
220 "]\n";
222 PKIX_TEST_STD_VARS();
224 startTests("ValidateParams");
226 useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
228 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
229 (PKIX_TRUE, /* nssInitNeeded */
230 useArenas,
231 PKIX_MAJOR_VERSION,
232 PKIX_MINOR_VERSION,
233 PKIX_MINOR_VERSION,
234 &actualMinorVersion,
235 &plContext));
237 if (argc < 2){
238 printUsage(argv[0]);
239 return (0);
242 dirName = argv[j+1];
244 subTest("PKIX_ValidateParams_Create");
245 chain = createCertChain(dirName, diffInput, goodInput, plContext);
246 goodObject = createValidateParams
247 (dirName,
248 goodInput,
249 diffInput,
250 NULL,
251 NULL,
252 PKIX_FALSE,
253 PKIX_FALSE,
254 PKIX_FALSE,
255 PKIX_FALSE,
256 chain,
257 plContext);
258 equalObject = createValidateParams
259 (dirName,
260 goodInput,
261 diffInput,
262 NULL,
263 NULL,
264 PKIX_FALSE,
265 PKIX_FALSE,
266 PKIX_FALSE,
267 PKIX_FALSE,
268 chain,
269 plContext);
270 diffObject = createValidateParams
271 (dirName,
272 diffInput,
273 goodInput,
274 NULL,
275 NULL,
276 PKIX_FALSE,
277 PKIX_FALSE,
278 PKIX_FALSE,
279 PKIX_FALSE,
280 chain,
281 plContext);
283 testGetProcParams(goodObject, equalObject);
284 testGetCertChain(goodObject, equalObject);
286 PKIX_TEST_EQ_HASH_TOSTR_DUP
287 (goodObject,
288 equalObject,
289 diffObject,
290 NULL, /* expectedAscii, */
291 ValidateParams,
292 PKIX_FALSE);
294 testDestroy(goodObject, equalObject, diffObject);
296 cleanup:
298 PKIX_TEST_DECREF_AC(chain);
300 PKIX_Shutdown(plContext);
302 PKIX_TEST_RETURN();
304 endTests("ValidateParams");
306 return (0);