Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / cmd / libpkix / pkix_pl / pki / test_nameconstraints.c
blobc283e9558d84c58ff117bd9d70b1978f0c7c3b00
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Sun Microsystems
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.
36 * ***** END LICENSE BLOCK ***** */
38 * test_nameconstraints.c
40 * Test CERT Name Constraints Type
44 #include "testutil.h"
45 #include "testutil_nss.h"
47 void *plContext = NULL;
49 static char *catDirName(char *platform, char *dir, void *plContext)
51 char *pathName = NULL;
52 PKIX_UInt32 dirLen;
53 PKIX_UInt32 platformLen;
55 PKIX_TEST_STD_VARS();
57 dirLen = PL_strlen(dir);
58 platformLen = PL_strlen(platform);
60 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Malloc
61 (platformLen + dirLen + 2, (void **)&pathName, plContext));
63 PL_strcpy(pathName, platform);
64 PL_strcat(pathName, "/");
65 PL_strcat(pathName, dir);
67 cleanup:
69 PKIX_TEST_RETURN();
71 return (pathName);
74 static void
75 testNameConstraints(char *dataDir)
77 char *goodPname = "nameConstraintsDN5CACert.crt";
78 PKIX_PL_Cert *goodCert = NULL;
79 PKIX_PL_CertNameConstraints *goodNC = NULL;
80 char *expectedAscii =
81 "[\n"
82 "\t\tPermitted Name: (OU=permittedSubtree1,"
83 "O=Test Certificates,C=US)\n"
84 "\t\tExcluded Name: (OU=excludedSubtree1,"
85 "OU=permittedSubtree1,O=Test Certificates,C=US)\n"
86 "\t]\n";
88 PKIX_TEST_STD_VARS();
90 subTest("PKIX_PL_CertNameConstraints");
92 goodCert = createCert(dataDir, goodPname, plContext);
94 subTest("PKIX_PL_Cert_GetNameConstraints");
96 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Cert_GetNameConstraints
97 (goodCert, &goodNC, plContext));
99 testToStringHelper
100 ((PKIX_PL_Object *)goodNC, expectedAscii, plContext);
102 cleanup:
104 PKIX_TEST_DECREF_AC(goodNC);
105 PKIX_TEST_DECREF_AC(goodCert);
107 PKIX_TEST_RETURN();
110 void printUsage(void) {
111 (void) printf
112 ("\nUSAGE:\ttest_nameconstraints <test-purpose>"
113 " <data-dir> <platform-prefix>\n\n");
116 /* Functional tests for CRL public functions */
118 int main(int argc, char *argv[]) {
119 PKIX_UInt32 actualMinorVersion;
120 PKIX_UInt32 j = 0;
121 char *platformDir = NULL;
122 char *dataDir = NULL;
123 char *combinedDir = NULL;
124 PKIX_Boolean useArenas = PKIX_FALSE;
126 /* Note XXX serialnumber and reasoncode need debug */
128 PKIX_TEST_STD_VARS();
130 startTests("NameConstraints");
132 useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
134 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
135 (PKIX_TRUE, /* nssInitNeeded */
136 useArenas,
137 PKIX_MAJOR_VERSION,
138 PKIX_MINOR_VERSION,
139 PKIX_MINOR_VERSION,
140 &actualMinorVersion,
141 &plContext));
143 if (argc < 3 + j) {
144 printUsage();
145 return (0);
148 dataDir = argv[2 + j];
149 platformDir = argv[3 + j];
150 combinedDir = catDirName(platformDir, dataDir, plContext);
152 testNameConstraints(combinedDir);
154 cleanup:
156 pkixTestErrorResult = PKIX_PL_Free(combinedDir, plContext);
158 PKIX_Shutdown(plContext);
160 PKIX_TEST_RETURN();
162 endTests("NameConstraints");
164 return (0);