OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 /* | 4 /* |
5 * test_generalname.c | 5 * test_generalname.c |
6 * | 6 * |
7 * Test GeneralName Type | 7 * Test GeneralName Type |
8 * | 8 * |
9 */ | 9 */ |
10 | 10 |
11 #include "testutil.h" | 11 #include "testutil.h" |
12 #include "testutil_nss.h" | 12 #include "testutil_nss.h" |
13 | 13 |
14 static void *plContext = NULL; | 14 static void *plContext = NULL; |
15 | 15 |
16 static void | 16 static void createGeneralNames(PKIX_UInt32 nameType, char *goodInput, |
17 createGeneralNames(PKIX_UInt32 nameType, char *goodInput, char *diffInput, | 17 char *diffInput, PKIX_PL_GeneralName **goodName, |
18 PKIX_PL_GeneralName **goodName, | 18 PKIX_PL_GeneralName **equalName, |
19 PKIX_PL_GeneralName **equalName, | 19 PKIX_PL_GeneralName **diffName) { |
20 PKIX_PL_GeneralName **diffName){ | |
21 | 20 |
22 subTest("PKIX_PL_GeneralName_Create <goodName>"); | 21 subTest("PKIX_PL_GeneralName_Create <goodName>"); |
23 *goodName = createGeneralName(nameType, goodInput, plContext); | 22 *goodName = createGeneralName(nameType, goodInput, plContext); |
24 | 23 |
25 subTest("PKIX_PL_GeneralName_Create <equalName>"); | 24 subTest("PKIX_PL_GeneralName_Create <equalName>"); |
26 *equalName = createGeneralName(nameType, goodInput, plContext); | 25 *equalName = createGeneralName(nameType, goodInput, plContext); |
27 | 26 |
28 subTest("PKIX_PL_GeneralName_Create <diffName>"); | 27 subTest("PKIX_PL_GeneralName_Create <diffName>"); |
29 *diffName = createGeneralName(nameType, diffInput, plContext); | 28 *diffName = createGeneralName(nameType, diffInput, plContext); |
30 | |
31 } | 29 } |
32 | 30 |
33 static void | 31 static void testDestroy(void *goodObject, void *equalObject, void *diffObject) { |
34 testDestroy(void *goodObject, void *equalObject, void *diffObject) | 32 PKIX_TEST_STD_VARS(); |
35 { | |
36 PKIX_TEST_STD_VARS(); | |
37 | 33 |
38 subTest("PKIX_PL_GeneralName_Destroy"); | 34 subTest("PKIX_PL_GeneralName_Destroy"); |
39 | 35 |
40 PKIX_TEST_DECREF_BC(goodObject); | 36 PKIX_TEST_DECREF_BC(goodObject); |
41 PKIX_TEST_DECREF_BC(equalObject); | 37 PKIX_TEST_DECREF_BC(equalObject); |
42 PKIX_TEST_DECREF_BC(diffObject); | 38 PKIX_TEST_DECREF_BC(diffObject); |
43 | 39 |
44 cleanup: | 40 cleanup: |
45 | 41 |
46 PKIX_TEST_RETURN(); | 42 PKIX_TEST_RETURN(); |
47 | |
48 } | 43 } |
49 | 44 |
50 static void testNameType | 45 static void testNameType(PKIX_UInt32 nameType, char *goodInput, char *diffInput, |
51 (PKIX_UInt32 nameType, char *goodInput, char *diffInput, char *expectedAscii){ | 46 char *expectedAscii) { |
52 | 47 |
53 PKIX_PL_GeneralName *goodName = NULL; | 48 PKIX_PL_GeneralName *goodName = NULL; |
54 PKIX_PL_GeneralName *equalName = NULL; | 49 PKIX_PL_GeneralName *equalName = NULL; |
55 PKIX_PL_GeneralName *diffName = NULL; | 50 PKIX_PL_GeneralName *diffName = NULL; |
56 | 51 |
57 createGeneralNames(nameType, goodInput, diffInput, | 52 createGeneralNames(nameType, goodInput, diffInput, &goodName, &equalName, |
58 &goodName, &equalName, &diffName); | 53 &diffName); |
59 | 54 |
60 PKIX_TEST_EQ_HASH_TOSTR_DUP | 55 PKIX_TEST_EQ_HASH_TOSTR_DUP(goodName, equalName, diffName, expectedAscii, |
61 (goodName, | 56 GeneralName, PKIX_TRUE); |
62 equalName, | |
63 diffName, | |
64 expectedAscii, | |
65 GeneralName, | |
66 PKIX_TRUE); | |
67 | 57 |
68 testDestroy(goodName, equalName, diffName); | 58 testDestroy(goodName, equalName, diffName); |
69 } | 59 } |
70 | 60 |
71 int test_generalname(int argc, char *argv[]) { | 61 int test_generalname(int argc, char *argv[]) { |
72 | 62 |
73 char *goodInput = NULL; | 63 char *goodInput = NULL; |
74 char *diffInput = NULL; | 64 char *diffInput = NULL; |
75 PKIX_UInt32 actualMinorVersion; | 65 PKIX_UInt32 actualMinorVersion; |
76 PKIX_UInt32 j = 0; | 66 PKIX_UInt32 j = 0; |
77 | 67 |
78 PKIX_TEST_STD_VARS(); | 68 PKIX_TEST_STD_VARS(); |
79 | 69 |
80 startTests("GeneralName"); | 70 startTests("GeneralName"); |
81 | 71 |
82 PKIX_TEST_EXPECT_NO_ERROR( | 72 PKIX_TEST_EXPECT_NO_ERROR( |
83 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); | 73 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); |
84 | 74 |
85 goodInput = "john@sun.com"; | 75 goodInput = "john@sun.com"; |
86 diffInput = "john@labs.com"; | 76 diffInput = "john@labs.com"; |
87 testNameType(PKIX_RFC822_NAME, goodInput, diffInput, goodInput); | 77 testNameType(PKIX_RFC822_NAME, goodInput, diffInput, goodInput); |
88 | 78 |
89 goodInput = "example1.com"; | 79 goodInput = "example1.com"; |
90 diffInput = "ex2.net"; | 80 diffInput = "ex2.net"; |
91 testNameType(PKIX_DNS_NAME, goodInput, diffInput, goodInput); | 81 testNameType(PKIX_DNS_NAME, goodInput, diffInput, goodInput); |
92 | 82 |
93 goodInput = "cn=yassir, ou=labs, o=sun, c=us"; | 83 goodInput = "cn=yassir, ou=labs, o=sun, c=us"; |
94 diffInput = "cn=alice, ou=labs, o=sun, c=us"; | 84 diffInput = "cn=alice, ou=labs, o=sun, c=us"; |
95 testNameType(PKIX_DIRECTORY_NAME, | 85 testNameType(PKIX_DIRECTORY_NAME, goodInput, diffInput, |
96 goodInput, | 86 "CN=yassir,OU=labs,O=sun,C=us"); |
97 diffInput, | |
98 "CN=yassir,OU=labs,O=sun,C=us"); | |
99 | 87 |
100 goodInput = "http://example1.com"; | 88 goodInput = "http://example1.com"; |
101 diffInput = "http://ex2.net"; | 89 diffInput = "http://ex2.net"; |
102 testNameType(PKIX_URI_NAME, goodInput, diffInput, goodInput); | 90 testNameType(PKIX_URI_NAME, goodInput, diffInput, goodInput); |
103 | 91 |
104 goodInput = "1.2.840.11"; | 92 goodInput = "1.2.840.11"; |
105 diffInput = "1.2.840.115349"; | 93 diffInput = "1.2.840.115349"; |
106 testNameType(PKIX_OID_NAME, goodInput, diffInput, goodInput); | 94 testNameType(PKIX_OID_NAME, goodInput, diffInput, goodInput); |
107 | 95 |
108 /* | 96 /* |
109 * We don't support creating PKIX_EDIPARTY_NAME, | 97 * We don't support creating PKIX_EDIPARTY_NAME, |
110 * PKIX_IP_NAME, OTHER_NAME, X400_ADDRESS from strings | 98 * PKIX_IP_NAME, OTHER_NAME, X400_ADDRESS from strings |
111 */ | 99 */ |
112 | 100 |
113 cleanup: | 101 cleanup: |
114 | 102 |
115 PKIX_Shutdown(plContext); | 103 PKIX_Shutdown(plContext); |
116 | 104 |
117 PKIX_TEST_RETURN(); | 105 PKIX_TEST_RETURN(); |
118 | 106 |
119 endTests("GeneralName"); | 107 endTests("GeneralName"); |
120 | 108 |
121 return (0); | 109 return (0); |
122 } | 110 } |
OLD | NEW |