blob: f5de5a1ad6f1d3a9b8e685c0ec1beb7e2a47ac2b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 6181936
27 * @summary Test basic functionality of X500Principal.getName(String, Map)
28 * @author Sean Mullan
29 */
30import java.util.Collections;
31import java.util.HashMap;
32import java.util.Map;
33import javax.security.auth.x500.X500Principal;
34
35public class OIDMap {
36
37 public static void main(String[] args) throws Exception {
38
39 X500Principal p = null;
40 Map<String, String> m1, m2 = null;
41
42 // test null oidMap
43 p = new X500Principal("CN=user");
44 try {
45 p.getName("RFC2253", null);
46 throw new Exception
47 ("expected NullPointerException for null oidMap");
48 } catch (NullPointerException npe) {}
49
50 // test improperly specified keyword
51 m1 = Collections.singletonMap("FOO", "1.2.3");
52 m2 = Collections.singletonMap("1.2.3", "*&$");
53 p = new X500Principal("FOO=user", m1);
54 try {
55 p.getName("RFC2253", m2);
56 throw new Exception
57 ("expected IllegalArgumentException for bad keyword");
58 } catch (IllegalArgumentException iae) {}
59 try {
60 m2 = Collections.singletonMap("1.2.3", "1abc");
61 p.getName("RFC2253", m2);
62 throw new Exception
63 ("expected IllegalArgumentException for bad keyword");
64 } catch (IllegalArgumentException iae) {}
65 try {
66 m2 = Collections.singletonMap("1.2.3", "");
67 p.getName("RFC2253", m2);
68 throw new Exception
69 ("expected IllegalArgumentException for bad keyword");
70 } catch (IllegalArgumentException iae) {}
71 try {
72 m2 = Collections.singletonMap("1.2.3", "a1_b)a");
73 p.getName("RFC2253", m2);
74 throw new Exception
75 ("expected IllegalArgumentException for bad keyword");
76 } catch (IllegalArgumentException iae) {}
77
78 // ignore improperly specified OID
79 m1 = Collections.singletonMap("*&D", "FOO");
80 p = new X500Principal("CN=user");
81 p.getName("RFC2253", m1);
82
83 // override builtin OIDs
84 m1 = Collections.singletonMap("2.5.4.3", "FOO");
85 p = new X500Principal("CN=user");
86 if (!p.getName("RFC2253", m1).startsWith("FOO")) {
87 throw new Exception("mapping did not override builtin OID");
88 }
89
90 // disallow CANONICAL format
91 try {
92 p.getName("CANONICAL", m1);
93 throw new Exception
94 ("expected IllegalArgumentException for CANONICAL format");
95 } catch (IllegalArgumentException iae) {}
96 // disallow invalid format
97 try {
98 p.getName("YABBADABBADOO", m1);
99 throw new Exception
100 ("expected IllegalArgumentException for invalid format");
101 } catch (IllegalArgumentException iae) {}
102
103 // map OIDs
104 m1 = Collections.singletonMap("1.1", "BAR");
105 p = new X500Principal("1.1=sean");
106 System.out.println(p.getName("RFC1779", m1));
107 System.out.println(p.getName("RFC2253", m1));
108 // FIXME: 1779 format is broken!
109 if (!p.getName("RFC1779", m1).startsWith("BAR")) {
110 throw new Exception("mapping did not override builtin OID");
111 }
112 }
113}