Path: blob/master/test/jdk/javax/security/auth/x500/X500Principal/OIDMap.java
41155 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.getName(String, Map)27* @author Sean Mullan28*/29import java.util.Collections;30import java.util.HashMap;31import java.util.Map;32import javax.security.auth.x500.X500Principal;3334public class OIDMap {3536public static void main(String[] args) throws Exception {3738X500Principal p = null;39Map<String, String> m1, m2 = null;4041// test null oidMap42p = new X500Principal("CN=user");43try {44p.getName("RFC2253", null);45throw new Exception46("expected NullPointerException for null oidMap");47} catch (NullPointerException npe) {}4849// test improperly specified keyword50m1 = Collections.singletonMap("FOO", "1.2.3");51m2 = Collections.singletonMap("1.2.3", "*&$");52p = new X500Principal("FOO=user", m1);53try {54p.getName("RFC2253", m2);55throw new Exception56("expected IllegalArgumentException for bad keyword");57} catch (IllegalArgumentException iae) {}58try {59m2 = Collections.singletonMap("1.2.3", "1abc");60p.getName("RFC2253", m2);61throw new Exception62("expected IllegalArgumentException for bad keyword");63} catch (IllegalArgumentException iae) {}64try {65m2 = Collections.singletonMap("1.2.3", "");66p.getName("RFC2253", m2);67throw new Exception68("expected IllegalArgumentException for bad keyword");69} catch (IllegalArgumentException iae) {}70try {71m2 = Collections.singletonMap("1.2.3", "a1_b)a");72p.getName("RFC2253", m2);73throw new Exception74("expected IllegalArgumentException for bad keyword");75} catch (IllegalArgumentException iae) {}7677// ignore improperly specified OID78m1 = Collections.singletonMap("*&D", "FOO");79p = new X500Principal("CN=user");80p.getName("RFC2253", m1);8182// override builtin OIDs83m1 = Collections.singletonMap("2.5.4.3", "FOO");84p = new X500Principal("CN=user");85if (!p.getName("RFC2253", m1).startsWith("FOO")) {86throw new Exception("mapping did not override builtin OID");87}8889// disallow CANONICAL format90try {91p.getName("CANONICAL", m1);92throw new Exception93("expected IllegalArgumentException for CANONICAL format");94} catch (IllegalArgumentException iae) {}95// disallow invalid format96try {97p.getName("YABBADABBADOO", m1);98throw new Exception99("expected IllegalArgumentException for invalid format");100} catch (IllegalArgumentException iae) {}101102// map OIDs103m1 = Collections.singletonMap("1.1", "BAR");104p = new X500Principal("1.1=sean");105System.out.println(p.getName("RFC1779", m1));106System.out.println(p.getName("RFC2253", m1));107// FIXME: 1779 format is broken!108if (!p.getName("RFC1779", m1).startsWith("BAR")) {109throw new Exception("mapping did not override builtin OID");110}111}112}113114115