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