test/jdk/javax/security/auth/x500/X500Principal/Parse.java
author jjg
Fri, 09 Aug 2019 15:22:43 -0700
changeset 57706 7ac414640ad5
parent 47216 71c04702a3d5
permissions -rw-r--r--
8229386: Typo "lables" in doc comment Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     1
/*
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     4
 *
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     8
 *
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    13
 * accompanied this code).
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    14
 *
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    18
 *
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    21
 * questions.
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    22
 */
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    23
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    24
/*
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    25
 * @test
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    26
 * @bug 7024771 7024604
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    27
 * @summary various X500Principal DN parsing tests
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    28
 */
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    29
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    30
import javax.security.auth.x500.X500Principal;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    31
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    32
public class Parse {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    33
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    34
    private static TestCase[] testCases = {
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    35
        new TestCase("CN=prefix\\<>suffix", false),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    36
        new TestCase("OID.1=value", false),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    37
        new TestCase("oid.1=value", false),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    38
        new TestCase("OID.1.2=value", true),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    39
        new TestCase("oid.1.2=value", true),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    40
        new TestCase("1=value", false),
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    41
        new TestCase("1.2=value", true)
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    42
    };
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    43
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    44
    public static void main(String args[]) throws Exception {
11846
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    45
        for (TestCase testCase : testCases) {
d0507b006470 7024604: OID.1 causes IAE in X500Principal constructor
mullan
parents: 10370
diff changeset
    46
            testCase.run();
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    47
        }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    48
        System.out.println("Test completed ok.");
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    49
    }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    50
}
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    51
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    52
class TestCase {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    53
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    54
     private String name;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    55
     private boolean expectedResult;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    56
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    57
     TestCase(String name, boolean expectedResult) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    58
         this.name = name;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    59
         this.expectedResult = expectedResult;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    60
     }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    61
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    62
     void run() throws Exception {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    63
         Exception f = null;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    64
         try {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    65
             System.out.println("Parsing: \"" + name + "\"");
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    66
             new X500Principal(name);
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    67
             if (expectedResult == false) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    68
                 f = new Exception("Successfully parsed invalid name");
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    69
             }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    70
         } catch (IllegalArgumentException e) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    71
             if (expectedResult == true) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    72
                 throw e;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    73
             }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    74
         }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    75
         if (f != null) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    76
             throw f;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    77
         }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    78
     }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    79
}