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_certstore.c | 5 * test_certstore.c |
6 * | 6 * |
7 * Test CertStore Type | 7 * Test CertStore 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 | 16 static PKIX_Error *testCRLCallback(PKIX_CertStore *store, |
17 PKIX_Error *testCRLCallback( | 17 PKIX_CRLSelector *selector, |
18 PKIX_CertStore *store, | 18 void **pNBIOContext, |
19 PKIX_CRLSelector *selector, | 19 PKIX_List **pCrls, /* list of PKIX_PL_Crl */ |
20 » void **pNBIOContext, | 20 void *plContext) { |
21 PKIX_List **pCrls, /* list of PKIX_PL_Crl */ | 21 return (0); |
22 void *plContext) | |
23 { | |
24 return (0); | |
25 } | 22 } |
26 | 23 |
27 static | 24 static PKIX_Error *testCRLContinue(PKIX_CertStore *store, |
28 PKIX_Error *testCRLContinue( | 25 PKIX_CRLSelector *selector, |
29 PKIX_CertStore *store, | 26 void **pNBIOContext, |
30 PKIX_CRLSelector *selector, | 27 PKIX_List **pCrls, /* list of PKIX_PL_Crl */ |
31 » void **pNBIOContext, | 28 void *plContext) { |
32 PKIX_List **pCrls, /* list of PKIX_PL_Crl */ | 29 return (0); |
33 void *plContext) | |
34 { | |
35 return (0); | |
36 } | 30 } |
37 | 31 |
38 static | 32 static PKIX_Error *testCertCallback( |
39 PKIX_Error *testCertCallback( | 33 PKIX_CertStore *store, PKIX_CertSelector *selector, void **pNBIOContext, |
40 PKIX_CertStore *store, | 34 PKIX_List **pCerts, /* list of PKIX_PL_Cert */ |
41 PKIX_CertSelector *selector, | 35 void *plContext) { |
42 » void **pNBIOContext, | 36 return (0); |
43 PKIX_List **pCerts, /* list of PKIX_PL_Cert */ | |
44 void *plContext) | |
45 { | |
46 return (0); | |
47 } | 37 } |
48 | 38 |
49 static | 39 static PKIX_Error *testCertContinue( |
50 PKIX_Error *testCertContinue( | 40 PKIX_CertStore *store, PKIX_CertSelector *selector, void **pNBIOContext, |
51 PKIX_CertStore *store, | 41 PKIX_List **pCerts, /* list of PKIX_PL_Cert */ |
52 PKIX_CertSelector *selector, | 42 void *plContext) { |
53 » void **pNBIOContext, | 43 return (0); |
54 PKIX_List **pCerts, /* list of PKIX_PL_Cert */ | |
55 void *plContext) | |
56 { | |
57 return (0); | |
58 } | 44 } |
59 | 45 |
60 static char *catDirName(char *platform, char *dir, void *plContext) | 46 static char *catDirName(char *platform, char *dir, void *plContext) { |
61 { | 47 char *pathName = NULL; |
62 char *pathName = NULL; | 48 PKIX_UInt32 dirLen; |
63 PKIX_UInt32 dirLen; | 49 PKIX_UInt32 platformLen; |
64 PKIX_UInt32 platformLen; | |
65 | 50 |
66 PKIX_TEST_STD_VARS(); | 51 PKIX_TEST_STD_VARS(); |
67 | 52 |
68 dirLen = PL_strlen(dir); | 53 dirLen = PL_strlen(dir); |
69 platformLen = PL_strlen(platform); | 54 platformLen = PL_strlen(platform); |
70 | 55 |
71 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc | 56 PKIX_TEST_EXPECT_NO_ERROR( |
72 (platformLen + dirLen + 2, (void **)&pathName, plContext)); | 57 PKIX_PL_Malloc(platformLen + dirLen + 2, (void **)&pathName, plContext)); |
73 | 58 |
74 PL_strcpy(pathName, platform); | 59 PL_strcpy(pathName, platform); |
75 PL_strcat(pathName, "/"); | 60 PL_strcat(pathName, "/"); |
76 PL_strcat(pathName, dir); | 61 PL_strcat(pathName, dir); |
77 | 62 |
78 cleanup: | 63 cleanup: |
79 | 64 |
80 PKIX_TEST_RETURN(); | 65 PKIX_TEST_RETURN(); |
81 | 66 |
82 return (pathName); | 67 return (pathName); |
83 } | 68 } |
84 | 69 |
85 static | 70 static void testCertStore(char *crlDir) { |
86 void testCertStore(char *crlDir) | 71 PKIX_PL_String *dirString = NULL; |
87 { | 72 PKIX_CertStore *certStore = NULL; |
88 PKIX_PL_String *dirString = NULL; | 73 PKIX_PL_Object *getCertStoreContext = NULL; |
89 PKIX_CertStore *certStore = NULL; | 74 PKIX_CertStore_CertCallback certCallback = NULL; |
90 PKIX_PL_Object *getCertStoreContext = NULL; | 75 PKIX_CertStore_CRLCallback crlCallback = NULL; |
91 PKIX_CertStore_CertCallback certCallback = NULL; | |
92 PKIX_CertStore_CRLCallback crlCallback = NULL; | |
93 | 76 |
94 PKIX_TEST_STD_VARS(); | 77 PKIX_TEST_STD_VARS(); |
95 | 78 |
96 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create | 79 PKIX_TEST_EXPECT_NO_ERROR( |
97 (PKIX_ESCASCII, | 80 PKIX_PL_String_Create(PKIX_ESCASCII, crlDir, 0, &dirString, plContext)); |
98 crlDir, | |
99 0, | |
100 &dirString, | |
101 plContext)); | |
102 | 81 |
103 subTest("PKIX_CertStore_Create"); | 82 subTest("PKIX_CertStore_Create"); |
104 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_Create | 83 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_Create( |
105 (testCertCallback, | 84 testCertCallback, testCRLCallback, testCertContinue, testCRLContinue, |
106 testCRLCallback, | 85 NULL, /* trustCallback */ |
107 testCertContinue, | 86 (PKIX_PL_Object *)dirString, PKIX_TRUE, /* cacheFlag */ |
108 testCRLContinue, | 87 PKIX_TRUE, /* local */ |
109 NULL, /* trustCallback */ | 88 &certStore, plContext)); |
110 (PKIX_PL_Object *) dirString, | |
111 PKIX_TRUE, /* cacheFlag */ | |
112 PKIX_TRUE, /* local */ | |
113 &certStore, | |
114 plContext)); | |
115 | 89 |
116 subTest("PKIX_CertStore_GetCertCallback"); | 90 subTest("PKIX_CertStore_GetCertCallback"); |
117 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCertCallback | 91 PKIX_TEST_EXPECT_NO_ERROR( |
118 (certStore, &certCallback, plContext)); | 92 PKIX_CertStore_GetCertCallback(certStore, &certCallback, plContext)); |
119 | 93 |
120 if (certCallback != testCertCallback) { | 94 if (certCallback != testCertCallback) { |
121 testError("PKIX_CertStore_GetCertCallback unexpected mismatch"); | 95 testError("PKIX_CertStore_GetCertCallback unexpected mismatch"); |
122 } | 96 } |
123 | 97 |
124 subTest("PKIX_CertStore_GetCRLCallback"); | 98 subTest("PKIX_CertStore_GetCRLCallback"); |
125 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCRLCallback | 99 PKIX_TEST_EXPECT_NO_ERROR( |
126 (certStore, &crlCallback, plContext)); | 100 PKIX_CertStore_GetCRLCallback(certStore, &crlCallback, plContext)); |
127 | 101 |
128 if (crlCallback != testCRLCallback) { | 102 if (crlCallback != testCRLCallback) { |
129 testError("PKIX_CertStore_GetCRLCallback unexpected mismatch"); | 103 testError("PKIX_CertStore_GetCRLCallback unexpected mismatch"); |
130 } | 104 } |
131 | 105 |
132 subTest("PKIX_CertStore_GetCertStoreContext"); | 106 subTest("PKIX_CertStore_GetCertStoreContext"); |
133 PKIX_TEST_EXPECT_NO_ERROR | 107 PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCertStoreContext( |
134 (PKIX_CertStore_GetCertStoreContext | 108 certStore, &getCertStoreContext, plContext)); |
135 (certStore, &getCertStoreContext, plContext)); | |
136 | 109 |
137 if ((PKIX_PL_Object *)dirString != getCertStoreContext) { | 110 if ((PKIX_PL_Object *)dirString != getCertStoreContext) { |
138 testError("PKIX_CertStore_GetCertStoreContext unexpected mismatch"); | 111 testError("PKIX_CertStore_GetCertStoreContext unexpected mismatch"); |
139 } | 112 } |
140 | 113 |
141 cleanup: | 114 cleanup: |
142 | 115 |
143 PKIX_TEST_DECREF_AC(dirString); | 116 PKIX_TEST_DECREF_AC(dirString); |
144 PKIX_TEST_DECREF_AC(certStore); | 117 PKIX_TEST_DECREF_AC(certStore); |
145 PKIX_TEST_DECREF_AC(getCertStoreContext); | 118 PKIX_TEST_DECREF_AC(getCertStoreContext); |
146 | 119 |
147 PKIX_TEST_RETURN(); | 120 PKIX_TEST_RETURN(); |
148 } | 121 } |
149 | 122 |
150 | 123 static void printUsage(char *pName) { |
151 static | 124 printf("\nUSAGE: %s testName <data-dir> <platform-dir>\n\n", pName); |
152 void printUsage(char *pName){ | |
153 printf("\nUSAGE: %s testName <data-dir> <platform-dir>\n\n", pName); | |
154 } | 125 } |
155 | 126 |
156 /* Functional tests for CertStore public functions */ | 127 /* Functional tests for CertStore public functions */ |
157 | 128 |
158 int test_store(int argc, char *argv[]) { | 129 int test_store(int argc, char *argv[]) { |
159 | 130 |
160 char *platformDir = NULL; | 131 char *platformDir = NULL; |
161 char *dataDir = NULL; | 132 char *dataDir = NULL; |
162 char *combinedDir = NULL; | 133 char *combinedDir = NULL; |
163 PKIX_UInt32 actualMinorVersion; | 134 PKIX_UInt32 actualMinorVersion; |
164 PKIX_UInt32 j = 0; | 135 PKIX_UInt32 j = 0; |
165 | 136 |
166 PKIX_TEST_STD_VARS(); | 137 PKIX_TEST_STD_VARS(); |
167 | 138 |
168 PKIX_TEST_EXPECT_NO_ERROR( | 139 PKIX_TEST_EXPECT_NO_ERROR( |
169 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); | 140 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); |
170 | 141 |
171 if (argc < (3 + j)) { | 142 if (argc < (3 + j)) { |
172 printUsage(argv[0]); | 143 printUsage(argv[0]); |
173 return (0); | 144 return (0); |
174 } | 145 } |
175 | 146 |
176 startTests(argv[1 + j]); | 147 startTests(argv[1 + j]); |
177 | 148 |
178 dataDir = argv[2 + j]; | 149 dataDir = argv[2 + j]; |
179 platformDir = argv[3 + j]; | 150 platformDir = argv[3 + j]; |
180 » combinedDir = catDirName(platformDir, dataDir, plContext); | 151 combinedDir = catDirName(platformDir, dataDir, plContext); |
181 | 152 |
182 testCertStore(combinedDir); | 153 testCertStore(combinedDir); |
183 | |
184 | 154 |
185 cleanup: | 155 cleanup: |
186 | 156 |
187 pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext); | 157 pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext); |
188 | 158 |
189 PKIX_Shutdown(plContext); | 159 PKIX_Shutdown(plContext); |
190 | 160 |
191 PKIX_TEST_RETURN(); | 161 PKIX_TEST_RETURN(); |
192 | 162 |
193 endTests("CertStore"); | 163 endTests("CertStore"); |
194 | 164 |
195 return (0); | 165 return (0); |
196 } | 166 } |
OLD | NEW |