PageRenderTime 43ms CodeModel.GetById 14ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/cmd/libpkix/pkix/results/test_policynode.c

http://github.com/zpao/v8monkey
C | 712 lines | 516 code | 120 blank | 76 comment | 19 complexity | 4adf7f794892980afe42ec33a7fae097 MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  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/
  8 *
  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.
 13 *
 14 * The Original Code is the PKIX-C library.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Sun Microsystems, Inc.
 18 * Portions created by the Initial Developer are
 19 * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *   Sun Microsystems, Inc.
 23 *
 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.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37/*
 38 * test_policynode.c
 39 *
 40 * Test PolicyNode Type
 41 *
 42 */
 43
 44#include "testutil.h"
 45#include "testutil_nss.h"
 46
 47static void *plContext =  NULL;
 48
 49static void
 50test_GetChildren(
 51        PKIX_PolicyNode *goodNode,
 52        PKIX_PolicyNode *equalNode,
 53        PKIX_PolicyNode *diffNode)
 54{
 55
 56/*
 57 * Caution: be careful where you insert this test. PKIX_PolicyNode_GetChildren
 58 * is required by the API to return an immutable List, and it does it by setting
 59 * the List immutable. We don't make a copy because the assumption is that
 60 * certificate and policy processing have been completed before the user gets at
 61 * the public API. So subsequent tests of functions that modify the policy tree,
 62 * such as Prune, will fail if called after the execution of this test.
 63 */
 64
 65        PKIX_Boolean isImmutable = PKIX_FALSE;
 66        PKIX_List *goodList = NULL;
 67        PKIX_List *equalList = NULL;
 68        PKIX_List *diffList = NULL;
 69
 70        PKIX_TEST_STD_VARS();
 71
 72        subTest("PKIX_PolicyNode_GetChildren");
 73
 74        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetChildren
 75                (goodNode, &goodList, plContext));
 76        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetChildren
 77                (equalNode, &equalList, plContext));
 78        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetChildren
 79                (diffNode, &diffList, plContext));
 80
 81        PKIX_TEST_EQ_HASH_TOSTR_DUP
 82                (goodList, equalList, diffList, NULL, List, NULL);
 83
 84        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_IsImmutable
 85                (goodList, &isImmutable, plContext));
 86
 87        if (isImmutable != PKIX_TRUE) {
 88            testError("PKIX_PolicyNode_GetChildren returned a mutable List");
 89        }
 90
 91cleanup:
 92        PKIX_TEST_DECREF_AC(goodList);
 93        PKIX_TEST_DECREF_AC(equalList);
 94        PKIX_TEST_DECREF_AC(diffList);
 95
 96        PKIX_TEST_RETURN();
 97}
 98
 99static void
100test_GetParent(
101        PKIX_PolicyNode *goodNode,
102        PKIX_PolicyNode *equalNode,
103        PKIX_PolicyNode *diffNode,
104        char *expectedAscii)
105{
106        PKIX_PolicyNode *goodParent = NULL;
107        PKIX_PolicyNode *equalParent = NULL;
108        PKIX_PolicyNode *diffParent = NULL;
109
110        PKIX_TEST_STD_VARS();
111
112        subTest("PKIX_PolicyNode_GetParent");
113
114        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetParent
115                (goodNode, &goodParent, plContext));
116        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetParent
117                (equalNode, &equalParent, plContext));
118        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetParent
119                (diffNode, &diffParent, plContext));
120
121        PKIX_TEST_EQ_HASH_TOSTR_DUP
122                (goodParent,
123                equalParent,
124                diffParent,
125                expectedAscii,
126                CertPolicyNode,
127                NULL);
128
129cleanup:
130        PKIX_TEST_DECREF_AC(goodParent);
131        PKIX_TEST_DECREF_AC(equalParent);
132        PKIX_TEST_DECREF_AC(diffParent);
133
134        PKIX_TEST_RETURN();
135}
136
137/*
138 * This test is the same as testDuplicateHelper, except that it
139 * produces a more useful "Actual value" and "Expected value"
140 * in the case of an unexpected mismatch.
141 */
142static void
143test_DuplicateHelper(PKIX_PolicyNode *object, void *plContext)
144{
145        PKIX_PolicyNode *newObject = NULL;
146        PKIX_Boolean cmpResult;
147        PKIX_PL_String *original = NULL;
148        PKIX_PL_String *copy = NULL;
149
150        PKIX_TEST_STD_VARS();
151
152        subTest("testing pkix_PolicyNode_Duplicate");
153
154        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Duplicate
155                ((PKIX_PL_Object *)object,
156                (PKIX_PL_Object **)&newObject,
157                plContext));
158
159        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
160                ((PKIX_PL_Object *)object,
161                (PKIX_PL_Object *)newObject,
162                &cmpResult,
163                plContext));
164
165        if (!cmpResult){
166                PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
167                        ((PKIX_PL_Object*)object, &original, plContext));
168                testError("unexpected mismatch");
169                (void) printf
170                        ("original value:\t%s\n", original->escAsciiString);
171
172                if (newObject) {
173                        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
174                                ((PKIX_PL_Object*)newObject, &copy, plContext));
175                        (void) printf
176                                ("copy value:\t%s\n", copy->escAsciiString);
177                } else {
178                        (void) printf("copy value:\t(NULL)\n");
179                }
180        }
181
182cleanup:
183
184        PKIX_TEST_DECREF_AC(newObject);
185        PKIX_TEST_DECREF_AC(original);
186        PKIX_TEST_DECREF_AC(copy);
187
188        PKIX_TEST_RETURN();
189}
190
191static void
192test_GetValidPolicy(
193        PKIX_PolicyNode *goodNode,
194        PKIX_PolicyNode *equalNode,
195        PKIX_PolicyNode *diffNode,
196        char *expectedAscii)
197{
198        PKIX_PL_OID *goodPolicy = NULL;
199        PKIX_PL_OID *equalPolicy = NULL;
200        PKIX_PL_OID *diffPolicy = NULL;
201
202        PKIX_TEST_STD_VARS();
203
204        subTest("PKIX_PolicyNode_GetValidPolicy");
205
206        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetValidPolicy
207                (goodNode, &goodPolicy, plContext));
208        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetValidPolicy
209                (equalNode, &equalPolicy, plContext));
210        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetValidPolicy
211                (diffNode, &diffPolicy, plContext));
212
213        PKIX_TEST_EQ_HASH_TOSTR_DUP
214                (goodPolicy, equalPolicy, diffPolicy, expectedAscii, OID, NULL);
215
216cleanup:
217        PKIX_TEST_DECREF_AC(goodPolicy);
218        PKIX_TEST_DECREF_AC(equalPolicy);
219        PKIX_TEST_DECREF_AC(diffPolicy);
220
221
222        PKIX_TEST_RETURN();
223}
224
225static void test_GetPolicyQualifiers(
226        PKIX_PolicyNode *goodNode,
227        PKIX_PolicyNode *equalNode,
228        PKIX_PolicyNode *diffNode,
229        char *expectedAscii)
230{
231        PKIX_Boolean isImmutable = PKIX_FALSE;
232        PKIX_List *goodList = NULL;
233        PKIX_List *equalList = NULL;
234        PKIX_List *diffList = NULL;
235
236        PKIX_TEST_STD_VARS();
237
238        subTest("PKIX_PolicyNode_GetPolicyQualifiers");
239
240        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetPolicyQualifiers
241                (goodNode, &goodList, plContext));
242        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetPolicyQualifiers
243                (equalNode, &equalList, plContext));
244        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetPolicyQualifiers
245                (diffNode, &diffList, plContext));
246
247        PKIX_TEST_EQ_HASH_TOSTR_DUP
248                (goodList, equalList, diffList, expectedAscii, List, plContext);
249
250        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_IsImmutable
251                (goodList, &isImmutable, plContext));
252
253        if (isImmutable != PKIX_TRUE) {
254            testError
255                ("PKIX_PolicyNode_GetPolicyQualifiers returned a mutable List");
256        }
257cleanup:
258        PKIX_TEST_DECREF_AC(goodList);
259        PKIX_TEST_DECREF_AC(equalList);
260        PKIX_TEST_DECREF_AC(diffList);
261
262        PKIX_TEST_RETURN();
263}
264
265static void test_GetExpectedPolicies(
266        PKIX_PolicyNode *goodNode,
267        PKIX_PolicyNode *equalNode,
268        PKIX_PolicyNode *diffNode,
269        char *expectedAscii)
270{
271        PKIX_Boolean isImmutable = PKIX_FALSE;
272        PKIX_List *goodList = NULL;
273        PKIX_List *equalList = NULL;
274        PKIX_List *diffList = NULL;
275
276        PKIX_TEST_STD_VARS();
277
278        subTest("PKIX_PolicyNode_GetExpectedPolicies");
279
280        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetExpectedPolicies
281                (goodNode, &goodList, plContext));
282        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetExpectedPolicies
283                (equalNode, &equalList, plContext));
284        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetExpectedPolicies
285                (diffNode, &diffList, plContext));
286
287        PKIX_TEST_EQ_HASH_TOSTR_DUP
288                (goodList, equalList, diffList, expectedAscii, List, plContext);
289
290        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_IsImmutable
291                (goodList, &isImmutable, plContext));
292
293        if (isImmutable != PKIX_TRUE) {
294            testError
295                ("PKIX_PolicyNode_GetExpectedPolicies returned a mutable List");
296        }
297cleanup:
298        PKIX_TEST_DECREF_AC(goodList);
299        PKIX_TEST_DECREF_AC(equalList);
300        PKIX_TEST_DECREF_AC(diffList);
301
302        PKIX_TEST_RETURN();
303}
304
305static void test_IsCritical(
306        PKIX_PolicyNode *goodNode,
307        PKIX_PolicyNode *equalNode,
308        PKIX_PolicyNode *diffNode)
309{
310        PKIX_Boolean goodBool = PKIX_FALSE;
311        PKIX_Boolean equalBool = PKIX_FALSE;
312        PKIX_Boolean diffBool = PKIX_FALSE;
313        PKIX_TEST_STD_VARS();
314
315        subTest("PKIX_PolicyNode_IsCritical");
316
317        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_IsCritical
318                (goodNode, &goodBool, plContext));
319        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_IsCritical
320                (equalNode, &equalBool, plContext));
321        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_IsCritical
322                (diffNode, &diffBool, plContext));
323
324        if ((!goodBool) || (!equalBool) || (diffBool)) {
325                testError("IsCritical returned unexpected value");
326        }
327cleanup:
328
329        PKIX_TEST_RETURN();
330}
331
332static void test_GetDepth(
333        PKIX_PolicyNode *depth1Node,
334        PKIX_PolicyNode *depth2Node,
335        PKIX_PolicyNode *depth3Node)
336{
337        PKIX_UInt32 depth1 = 0;
338        PKIX_UInt32 depth2 = 0;
339        PKIX_UInt32 depth3 = 0;
340        PKIX_TEST_STD_VARS();
341
342        subTest("PKIX_PolicyNode_GetDepth");
343
344        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetDepth
345                (depth1Node, &depth1, plContext));
346        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetDepth
347                (depth2Node, &depth2, plContext));
348        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PolicyNode_GetDepth
349                (depth3Node, &depth3, plContext));
350
351        if ((depth1 != 1) || (depth2 != 2) || (depth3 != 3)) {
352                testError("GetDepth returned unexpected value");
353        }
354
355cleanup:
356
357        PKIX_TEST_RETURN();
358}
359
360static
361void printUsage(void) {
362        (void) printf("\nUSAGE:\ttest_policynode <NIST_FILES_DIR> \n\n");
363}
364
365int test_policynode(int argc, char *argv[]) {
366
367        /*
368         * Create a tree with parent = anyPolicy,
369         * child1 with Nist1+Nist2, child2 with Nist1.
370         * Give each child another child, with policies Nist2
371         * and Nist1, respectively. Pruning with a depth of two
372         * should have no effect. Give one of the children
373         * another child. Then pruning with a depth of three
374         * should reduce the tree to a single strand, as child1
375         * and child3 are removed.
376         *
377         *              parent (anyPolicy)
378         *          /                   \
379         *      child1(Nist1+Nist2)     child2(Nist1)
380         *          |                       |
381         *      child3(Nist2)           child4(Nist1)
382         *                                  |
383         *                              child5(Nist1)
384         *
385         */
386        char *asciiAnyPolicy = "2.5.29.32.0";
387        PKIX_PL_Cert *cert = NULL;
388        PKIX_PL_CertPolicyInfo *nist1Policy = NULL;
389        PKIX_PL_CertPolicyInfo *nist2Policy = NULL;
390        PKIX_List *policyQualifierList = NULL;
391        PKIX_PL_OID *oidAnyPolicy = NULL;
392        PKIX_PL_OID *oidNist1Policy = NULL;
393        PKIX_PL_OID *oidNist2Policy = NULL;
394        PKIX_List *expectedAnyList = NULL;
395        PKIX_List *expectedNist1List = NULL;
396        PKIX_List *expectedNist2List = NULL;
397        PKIX_List *expectedNist1Nist2List = NULL;
398        PKIX_List *emptyList = NULL;
399        PKIX_PolicyNode *parentNode = NULL;
400        PKIX_PolicyNode *childNode1 = NULL;
401        PKIX_PolicyNode *childNode2 = NULL;
402        PKIX_PolicyNode *childNode3 = NULL;
403        PKIX_PolicyNode *childNode4 = NULL;
404        PKIX_PolicyNode *childNode5 = NULL;
405        PKIX_PL_String *parentString = NULL;
406        PKIX_Boolean pDelete = PKIX_FALSE;
407        char *expectedParentAscii =
408                "{2.16.840.1.101.3.2.1.48.2,(1.3.6.1.5.5.7.2.2:[30 5C "
409                "1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 68 65"
410                " 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F 6D 2"
411                "0 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68 69 "
412                "73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 20 66"
413                " 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 20 6"
414                "F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.1[(1.3"
415                ".6.1.5.5.7.2.2:[30 5C 1A 5A 71 31 3A 20 20 54 68 69 7"
416                "3 20 69 73 20 74 68 65 20 75 73 65 72 20 6E 6F 74 69 "
417                "63 65 20 66 72 6F 6D 20 71 75 61 6C 69 66 69 65 72 20"
418                " 31 2E 20 20 54 68 69 73 20 63 65 72 74 69 66 69 63 6"
419                "1 74 65 20 69 73 20 66 6F 72 20 74 65 73 74 20 70 75 "
420                "72 70 6F 73 65 73 20 6F 6E 6C 79])], 2.16.840.1.101.3"
421                ".2.1.48.2[(1.3.6.1.5.5.7.2.2:[30 5A 1A 58 71 32 3A 20"
422                " 20 54 68 69 73 20 69 73 20 74 68 65 20 75 73 65 72 2"
423                "0 6E 6F 74 69 63 65 20 66 72 6F 6D 20 71 75 61 6C 69 "
424                "66 69 65 72 20 32 2E 20 20 54 68 69 73 20 75 73 65 72"
425                " 20 6E 6F 74 69 63 65 20 73 68 6F 75 6C 64 20 6E 6F 7"
426                "4 20 62 65 20 64 69 73 70 6C 61 79 65 64])]),1}\n"
427                ". {2.16.840.1.101.3.2.1.48.2,(1.3.6.1.5.5.7.2.2:[30 5"
428                "C 1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 68 "
429                "65 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F 6D"
430                " 20 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68 6"
431                "9 73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 20 "
432                "66 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 20"
433                " 6F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.2),2}";
434        char *expectedValidAscii =
435                "2.16.840.1.101.3.2.1.48.2";
436        char *expectedQualifiersAscii =
437                /* "(1.3.6.1.5.5.7.2.2)"; */
438                "(1.3.6.1.5.5.7.2.2:[30 5C 1A 5A 71 31 3A 20 20 54 68 "
439                "69 73 20 69 73 20 74 68 65 20 75 73 65 72 20 6E 6F 74"
440                " 69 63 65 20 66 72 6F 6D 20 71 75 61 6C 69 66 69 65 7"
441                "2 20 31 2E 20 20 54 68 69 73 20 63 65 72 74 69 66 69 "
442                "63 61 74 65 20 69 73 20 66 6F 72 20 74 65 73 74 20 70"
443                " 75 72 70 6F 73 65 73 20 6F 6E 6C 79])";
444        char *expectedPoliciesAscii =
445                "(2.16.840.1.101.3.2.1.48.1)";
446        char *expectedTree =
447                "{2.5.29.32.0,{},Critical,(2.5.29.32.0),0}\n"
448                ". {2.16.840.1.101.3.2.1.48.2,(1.3.6.1.5.5.7.2.2:[30 5"
449                "C 1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 68 "
450                "65 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F 6D"
451                " 20 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68 6"
452                "9 73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 20 "
453                "66 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 20"
454                " 6F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.1[(1"
455                ".3.6.1.5.5.7.2.2:[30 5C 1A 5A 71 31 3A 20 20 54 68 69"
456                " 73 20 69 73 20 74 68 65 20 75 73 65 72 20 6E 6F 74 6"
457                "9 63 65 20 66 72 6F 6D 20 71 75 61 6C 69 66 69 65 72 "
458                "20 31 2E 20 20 54 68 69 73 20 63 65 72 74 69 66 69 63"
459                " 61 74 65 20 69 73 20 66 6F 72 20 74 65 73 74 20 70 7"
460                "5 72 70 6F 73 65 73 20 6F 6E 6C 79])], 2.16.840.1.101"
461                ".3.2.1.48.2[(1.3.6.1.5.5.7.2.2:[30 5A 1A 58 71 32 3A "
462                "20 20 54 68 69 73 20 69 73 20 74 68 65 20 75 73 65 72"
463                " 20 6E 6F 74 69 63 65 20 66 72 6F 6D 20 71 75 61 6C 6"
464                "9 66 69 65 72 20 32 2E 20 20 54 68 69 73 20 75 73 65 "
465                "72 20 6E 6F 74 69 63 65 20 73 68 6F 75 6C 64 20 6E 6F"
466                " 74 20 62 65 20 64 69 73 70 6C 61 79 65 64])]"
467                "),1}\n"
468                ". . {2.16.840.1.101.3.2.1.48.2,(1.3.6.1.5.5.7.2.2:[30"
469                " 5C 1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 6"
470                "8 65 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F "
471                "6D 20 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68"
472                " 69 73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 2"
473                "0 66 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 "
474                "20 6F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.2)"
475                ",2}\n"
476                ". {2.16.840.1.101.3.2.1.48.1,(1.3.6.1.5.5.7.2.2:[30 5"
477                "C 1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 68 "
478                "65 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F 6D"
479                " 20 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68 6"
480                "9 73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 20 "
481                "66 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 20"
482                " 6F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.1),1}\n"
483                ". . {2.16.840.1.101.3.2.1.48.1,(EMPTY),Not Critical,"
484                "(2.16.840.1.101.3.2.1.48.1),2}\n"
485                ". . . {2.16.840.1.101.3.2.1.48.1,{},Critical,(2.16.84"
486                "0.1.101.3.2.1.48.1),3}";
487        char *expectedPrunedTree =
488                "{2.5.29.32.0,{},Critical,(2.5.29.32.0),0}\n"
489                ". {2.16.840.1.101.3.2.1.48.1,(1.3.6.1.5.5.7.2.2:[30 5"
490                "C 1A 5A 71 31 3A 20 20 54 68 69 73 20 69 73 20 74 68 "
491                "65 20 75 73 65 72 20 6E 6F 74 69 63 65 20 66 72 6F 6D"
492                " 20 71 75 61 6C 69 66 69 65 72 20 31 2E 20 20 54 68 6"
493                "9 73 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 20 "
494                "66 6F 72 20 74 65 73 74 20 70 75 72 70 6F 73 65 73 20"
495                " 6F 6E 6C 79]),Critical,(2.16.840.1.101.3.2.1.48.1),1}\n"
496                ". . {2.16.840.1.101.3.2.1.48.1,(EMPTY),Not Critical,"
497                "(2.16.840.1.101.3.2.1.48.1),2}\n"
498                ". . . {2.16.840.1.101.3.2.1.48.1,{},Critical,(2.16.84"
499                "0.1.101.3.2.1.48.1),3}";
500
501        PKIX_UInt32 actualMinorVersion;
502        PKIX_UInt32 j = 0;
503        char *dirName = NULL;
504
505        PKIX_TEST_STD_VARS();
506
507        if (argc < 2) {
508                printUsage();
509                return (0);
510        }
511
512        startTests("PolicyNode");
513
514        PKIX_TEST_EXPECT_NO_ERROR(
515            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
516
517        dirName = argv[j+1];
518
519        subTest("Creating OID objects");
520        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_OID_Create
521                (asciiAnyPolicy, &oidAnyPolicy, plContext));
522
523        /* Read certificates to get real policies, qualifiers */
524
525        cert = createCert
526                (dirName, "UserNoticeQualifierTest16EE.crt", plContext);
527
528        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetPolicyInformation
529                (cert, &expectedNist1Nist2List, plContext));
530        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
531                (expectedNist1Nist2List,
532                0,
533                (PKIX_PL_Object **)&nist1Policy,
534                plContext));
535        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetItem
536                (expectedNist1Nist2List,
537                1,
538                (PKIX_PL_Object **)&nist2Policy,
539                plContext));
540
541        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CertPolicyInfo_GetPolQualifiers
542                (nist1Policy, &policyQualifierList, plContext));
543
544        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CertPolicyInfo_GetPolicyId
545                (nist1Policy, &oidNist1Policy, plContext));
546
547        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CertPolicyInfo_GetPolicyId
548                (nist2Policy, &oidNist2Policy, plContext));
549
550        subTest("Creating expectedPolicy List objects");
551
552        PKIX_TEST_EXPECT_NO_ERROR
553                (PKIX_List_Create(&expectedAnyList, plContext));
554
555        PKIX_TEST_EXPECT_NO_ERROR
556                (PKIX_List_Create(&expectedNist1List, plContext));
557
558        PKIX_TEST_EXPECT_NO_ERROR
559                (PKIX_List_Create(&expectedNist2List, plContext));
560
561
562        subTest("Populating expectedPolicy List objects");
563
564        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
565                (expectedAnyList, (PKIX_PL_Object *)oidAnyPolicy, plContext));
566
567        PKIX_TEST_EXPECT_NO_ERROR
568                (PKIX_List_AppendItem
569                (expectedNist1List,
570                (PKIX_PL_Object *)oidNist1Policy,
571                plContext));
572
573        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
574                                    (expectedNist2List,
575                                    (PKIX_PL_Object *)oidNist2Policy,
576                                    plContext));
577
578        subTest("Creating PolicyNode objects");
579
580        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&emptyList, plContext));
581
582        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
583                (oidAnyPolicy,
584                NULL,
585                PKIX_TRUE,
586                expectedAnyList,
587                &parentNode,
588                plContext));
589
590        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
591                (oidNist2Policy,
592                policyQualifierList,
593                PKIX_TRUE,
594                expectedNist1Nist2List,
595                &childNode1,
596                plContext));
597
598        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
599                (oidNist1Policy,
600                policyQualifierList,
601                PKIX_TRUE,
602                expectedNist1List,
603                &childNode2,
604                plContext));
605
606        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
607                (oidNist2Policy,
608                policyQualifierList,
609                PKIX_TRUE,
610                expectedNist2List,
611                &childNode3,
612                plContext));
613
614        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
615                (oidNist1Policy,
616                emptyList,
617                PKIX_FALSE,
618                expectedNist1List,
619                &childNode4,
620                plContext));
621
622        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Create
623                (oidNist1Policy,
624                NULL,
625                PKIX_TRUE,
626                expectedNist1List,
627                &childNode5,
628                plContext));
629
630        subTest("Creating the PolicyNode tree");
631
632        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_AddToParent
633                (parentNode, childNode1, plContext));
634        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_AddToParent
635                (parentNode, childNode2, plContext));
636
637        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_AddToParent
638                (childNode1, childNode3, plContext));
639
640        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_AddToParent
641                (childNode2, childNode4, plContext));
642
643        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_AddToParent
644                (childNode4, childNode5, plContext));
645
646        subTest("Displaying PolicyNode objects");
647
648        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
649                ((PKIX_PL_Object*)parentNode, &parentString, plContext));
650        (void) printf("parentNode is\n\t%s\n", parentString->escAsciiString);
651
652        testToStringHelper
653                ((PKIX_PL_Object*)parentNode, expectedTree, plContext);
654
655        test_DuplicateHelper(parentNode, plContext);
656
657        test_GetParent(childNode3, childNode3, childNode4, expectedParentAscii);
658        test_GetValidPolicy
659                (childNode1, childNode3, parentNode, expectedValidAscii);
660        test_GetPolicyQualifiers
661                (childNode1, childNode3, childNode4, expectedQualifiersAscii);
662        test_GetExpectedPolicies
663                (childNode2, childNode4, childNode3, expectedPoliciesAscii);
664        test_IsCritical(childNode1, childNode2, childNode4);
665        test_GetDepth(childNode2, childNode4, childNode5);
666
667        subTest("pkix_PolicyNode_Prune");
668
669        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Prune
670                (parentNode, 2, &pDelete, plContext));
671
672        testToStringHelper
673                ((PKIX_PL_Object*)parentNode, expectedTree, plContext);
674
675        PKIX_TEST_EXPECT_NO_ERROR(pkix_PolicyNode_Prune
676                (parentNode, 3, &pDelete, plContext));
677
678        testToStringHelper
679                ((PKIX_PL_Object*)parentNode, expectedPrunedTree, plContext);
680
681        test_GetChildren(parentNode, parentNode, childNode2);
682
683cleanup:
684
685        PKIX_TEST_DECREF_AC(cert);
686        PKIX_TEST_DECREF_AC(nist1Policy);
687        PKIX_TEST_DECREF_AC(nist2Policy);
688        PKIX_TEST_DECREF_AC(policyQualifierList);
689        PKIX_TEST_DECREF_AC(oidAnyPolicy);
690        PKIX_TEST_DECREF_AC(oidNist1Policy);
691        PKIX_TEST_DECREF_AC(oidNist2Policy);
692        PKIX_TEST_DECREF_AC(expectedAnyList);
693        PKIX_TEST_DECREF_AC(expectedNist1List);
694        PKIX_TEST_DECREF_AC(expectedNist2List);
695        PKIX_TEST_DECREF_AC(expectedNist1Nist2List);
696        PKIX_TEST_DECREF_AC(emptyList);
697        PKIX_TEST_DECREF_AC(parentNode);
698        PKIX_TEST_DECREF_AC(childNode1);
699        PKIX_TEST_DECREF_AC(childNode2);
700        PKIX_TEST_DECREF_AC(childNode3);
701        PKIX_TEST_DECREF_AC(childNode4);
702        PKIX_TEST_DECREF_AC(childNode5);
703        PKIX_TEST_DECREF_AC(parentString);
704
705        PKIX_Shutdown(plContext);
706
707        PKIX_TEST_RETURN();
708
709        endTests("PolicyNode");
710
711        return (0);
712}