Path: blob/master/test/jdk/javax/security/auth/x500/X500Principal/RFC4514.java
41154 views
/*1* Copyright (c) 2008, 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*/2223import javax.security.auth.x500.X500Principal;2425/**26* @test27* @bug 661199128* @summary Add support for parsing RFC 4514 DNs to X500Principal29*30* Ensure RFC 4514 Distinguished Name Strings can be parsed by X500Principal.31* RFC 4514 obsoleted RFC 2253 so we should make sure we can parse DNs of32* that form that contain subtle differences or clarifications in the grammar.33*/34public class RFC4514 {3536private int failed = 0;3738public static void main(String[] args) throws Exception {39new RFC4514().test();40}4142private void test() throws Exception {4344/**45* RFC 4514 allows space to be escaped as '\ '.46*/47parse("CN=\\ Space\\ ,C=US");48parse("CN=Sp\\ ace,C=US");49/**50* RFC 4514 does not require escaping of '=' characters.51*/52parse("CN=Eq=uals,C=US");53/**54* RFC 4514 requires the null character to be escaped.55*/56parse("CN=\\00,C=US");57/**58* RFC 4514 does not require escaping of non-leading '#' characters.59*/60parse("CN=Num#ber,C=US");61/**62* XMLDSig (http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/)63* allows implementations to escape trailing whitespace as '\20'.64*/65parse("CN=Trailing \\20,C=US");66/**67* XMLDSig allows implementations to escape ASCII control characters68* (Unicode range \x00 - \x1f) by replacing them with "\" followed by69* a two digit hex number showing its Unicode number.70*/71parse("CN=Con\\09trol,C=US");7273if (failed != 0) {74throw new Exception("Some RFC4514 tests FAILED");75}76}7778public void parse(String dnString) throws Exception {7980System.out.println("Parsing " + dnString);81X500Principal dn = new X500Principal(dnString);82String dnString2 = dn.getName();83X500Principal dn2 = new X500Principal(dnString2);84if (dn.equals(dn2)) {85System.out.println("PASSED");86} else {87System.out.println("FAILED");88failed++;89}90}91}929394