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_nameconstraints.c | 5 * test_nameconstraints.c |
6 * | 6 * |
7 * Test CERT Name Constraints Type | 7 * Test CERT Name Constraints 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 char *catDirName(char *platform, char *dir, void *plContext) | 16 static char *catDirName(char *platform, char *dir, void *plContext) { |
17 { | 17 char *pathName = NULL; |
18 char *pathName = NULL; | 18 PKIX_UInt32 dirLen; |
19 PKIX_UInt32 dirLen; | 19 PKIX_UInt32 platformLen; |
20 PKIX_UInt32 platformLen; | |
21 | 20 |
22 PKIX_TEST_STD_VARS(); | 21 PKIX_TEST_STD_VARS(); |
23 | 22 |
24 dirLen = PL_strlen(dir); | 23 dirLen = PL_strlen(dir); |
25 platformLen = PL_strlen(platform); | 24 platformLen = PL_strlen(platform); |
26 | 25 |
27 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc | 26 PKIX_TEST_EXPECT_NO_ERROR( |
28 (platformLen + dirLen + 2, (void **)&pathName, plContext)); | 27 PKIX_PL_Malloc(platformLen + dirLen + 2, (void **)&pathName, plContext)); |
29 | 28 |
30 PL_strcpy(pathName, platform); | 29 PL_strcpy(pathName, platform); |
31 PL_strcat(pathName, "/"); | 30 PL_strcat(pathName, "/"); |
32 PL_strcat(pathName, dir); | 31 PL_strcat(pathName, dir); |
33 | 32 |
34 cleanup: | 33 cleanup: |
35 | 34 |
36 PKIX_TEST_RETURN(); | 35 PKIX_TEST_RETURN(); |
37 | 36 |
38 return (pathName); | 37 return (pathName); |
39 } | 38 } |
40 | 39 |
41 static void | 40 static void testNameConstraints(char *dataDir) { |
42 testNameConstraints(char *dataDir) | 41 char *goodPname = "nameConstraintsDN5CACert.crt"; |
43 { | 42 PKIX_PL_Cert *goodCert = NULL; |
44 char *goodPname = "nameConstraintsDN5CACert.crt"; | 43 PKIX_PL_CertNameConstraints *goodNC = NULL; |
45 PKIX_PL_Cert *goodCert = NULL; | 44 char *expectedAscii = |
46 PKIX_PL_CertNameConstraints *goodNC = NULL; | 45 "[\n" |
47 char *expectedAscii = | 46 "\t\tPermitted Name: (OU=permittedSubtree1," |
48 "[\n" | 47 "O=Test Certificates,C=US)\n" |
49 "\t\tPermitted Name: (OU=permittedSubtree1," | 48 "\t\tExcluded Name: (OU=excludedSubtree1," |
50 "O=Test Certificates,C=US)\n" | 49 "OU=permittedSubtree1,O=Test Certificates,C=US)\n" |
51 "\t\tExcluded Name: (OU=excludedSubtree1," | 50 "\t]\n"; |
52 "OU=permittedSubtree1,O=Test Certificates,C=US)\n" | |
53 "\t]\n"; | |
54 | 51 |
55 PKIX_TEST_STD_VARS(); | 52 PKIX_TEST_STD_VARS(); |
56 | 53 |
57 subTest("PKIX_PL_CertNameConstraints"); | 54 subTest("PKIX_PL_CertNameConstraints"); |
58 | 55 |
59 goodCert = createCert(dataDir, goodPname, plContext); | 56 goodCert = createCert(dataDir, goodPname, plContext); |
60 | 57 |
61 subTest("PKIX_PL_Cert_GetNameConstraints"); | 58 subTest("PKIX_PL_Cert_GetNameConstraints"); |
62 | 59 |
63 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetNameConstraints | 60 PKIX_TEST_EXPECT_NO_ERROR( |
64 (goodCert, &goodNC, plContext)); | 61 PKIX_PL_Cert_GetNameConstraints(goodCert, &goodNC, plContext)); |
65 | 62 |
66 testToStringHelper | 63 testToStringHelper((PKIX_PL_Object *)goodNC, expectedAscii, plContext); |
67 ((PKIX_PL_Object *)goodNC, expectedAscii, plContext); | |
68 | 64 |
69 cleanup: | 65 cleanup: |
70 | 66 |
71 PKIX_TEST_DECREF_AC(goodNC); | 67 PKIX_TEST_DECREF_AC(goodNC); |
72 PKIX_TEST_DECREF_AC(goodCert); | 68 PKIX_TEST_DECREF_AC(goodCert); |
73 | 69 |
74 PKIX_TEST_RETURN(); | 70 PKIX_TEST_RETURN(); |
75 } | 71 } |
76 | 72 |
77 static | 73 static void printUsage(void) { |
78 void printUsage(void) { | 74 (void)printf( |
79 (void) printf | 75 "\nUSAGE:\ttest_nameconstraints <test-purpose>" |
80 » » ("\nUSAGE:\ttest_nameconstraints <test-purpose>" | 76 " <data-dir> <platform-prefix>\n\n"); |
81 " <data-dir> <platform-prefix>\n\n"); | |
82 } | 77 } |
83 | 78 |
84 /* Functional tests for CRL public functions */ | 79 /* Functional tests for CRL public functions */ |
85 | 80 |
86 int test_nameconstraints(int argc, char *argv[]) { | 81 int test_nameconstraints(int argc, char *argv[]) { |
87 PKIX_UInt32 actualMinorVersion; | 82 PKIX_UInt32 actualMinorVersion; |
88 PKIX_UInt32 j = 0; | 83 PKIX_UInt32 j = 0; |
89 char *platformDir = NULL; | 84 char *platformDir = NULL; |
90 char *dataDir = NULL; | 85 char *dataDir = NULL; |
91 char *combinedDir = NULL; | 86 char *combinedDir = NULL; |
92 | 87 |
93 /* Note XXX serialnumber and reasoncode need debug */ | 88 /* Note XXX serialnumber and reasoncode need debug */ |
94 | 89 |
95 PKIX_TEST_STD_VARS(); | 90 PKIX_TEST_STD_VARS(); |
96 | 91 |
97 startTests("NameConstraints"); | 92 startTests("NameConstraints"); |
98 | 93 |
99 PKIX_TEST_EXPECT_NO_ERROR( | 94 PKIX_TEST_EXPECT_NO_ERROR( |
100 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); | 95 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); |
101 | 96 |
102 if (argc < 3 + j) { | 97 if (argc < 3 + j) { |
103 printUsage(); | 98 printUsage(); |
104 return (0); | 99 return (0); |
105 } | 100 } |
106 | 101 |
107 dataDir = argv[2 + j]; | 102 dataDir = argv[2 + j]; |
108 platformDir = argv[3 + j]; | 103 platformDir = argv[3 + j]; |
109 » combinedDir = catDirName(platformDir, dataDir, plContext); | 104 combinedDir = catDirName(platformDir, dataDir, plContext); |
110 | 105 |
111 testNameConstraints(combinedDir); | 106 testNameConstraints(combinedDir); |
112 | 107 |
113 cleanup: | 108 cleanup: |
114 | 109 |
115 pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext); | 110 pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext); |
116 | 111 |
117 PKIX_Shutdown(plContext); | 112 PKIX_Shutdown(plContext); |
118 | 113 |
119 PKIX_TEST_RETURN(); | 114 PKIX_TEST_RETURN(); |
120 | 115 |
121 endTests("NameConstraints"); | 116 endTests("NameConstraints"); |
122 | 117 |
123 return (0); | 118 return (0); |
124 } | 119 } |
OLD | NEW |