Path: blob/master/test/jdk/javax/security/auth/x500/X500Principal/KeywordMap.java
41154 views
/*1* Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 618193626* @summary Test basic functionality of X500Principal(String, Map) constructor27* @author Sean Mullan28*/29import java.util.Collections;30import java.util.HashMap;31import java.util.Map;32import javax.security.auth.x500.X500Principal;3334public class KeywordMap {3536public static void main(String[] args) throws Exception {3738X500Principal p = null;39Map<String, String> m = null;4041// test null keywordMap42try {43p = new X500Principal("CN=user", null);44throw new Exception45("expected NullPointerException for null keywordMap");46} catch (NullPointerException npe) {}4748// test improperly specified OID49m = Collections.singletonMap("FOO", "FOO");50try {51p = new X500Principal("FOO=user", m);52throw new Exception53("expected IllegalArgumentException for bad OID");54} catch (IllegalArgumentException iae) {}5556// ignore improperly specified keyword57m = Collections.singletonMap("?*&", "FOO");58p = new X500Principal("CN=user", m);5960// throw exception if no mapping for keyword61m = Collections.singletonMap("BAR", "1.2.3");62try {63p = new X500Principal("FOO=user", m);64throw new Exception65("expected IllegalArgumentExc for keyword with no mapping");66} catch (IllegalArgumentException iae) {}6768// don't match keyword in lower-case69m = Collections.singletonMap("foo", "1.2.3");70try {71p = new X500Principal("FOO=user", m);72throw new Exception73("expected IllegalArgumentExc for wrong-case keyword mapping");74} catch (IllegalArgumentException iae) {}7576// allow duplicate OID mappings77m = new HashMap<String, String>();78m.put("FOO", "1.2.3");79m.put("BAR", "1.2.3");80p = new X500Principal("BAR=user", m);8182// override builtin keywords83m = Collections.singletonMap("CN", "1.2.3");84p = new X500Principal("CN=user", m);85if (!p.getName().startsWith("1.2.3")) {86throw new Exception("mapping did not override builtin keyword");87}8889// override builtin OIDs90m = Collections.singletonMap("FOO", "2.5.4.3");91p = new X500Principal("FOO=sean", m);92if (!p.getName().startsWith("CN")) {93throw new Exception("mapping did not override builtin OID");94}95}96}979899