jdk/test/javax/security/auth/x500/X500Principal/Parse.java
author mullan
Mon, 29 Aug 2011 12:22:06 -0400
changeset 10370 5db0cf452a50
child 11846 d0507b006470
permissions -rw-r--r--
7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect Reviewed-by: vinnie
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
/*
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    26
 * @bug 7024771
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 = {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    35
        new TestCase("CN=prefix\\<>suffix", false)
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    36
    };
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    37
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    38
    public static void main(String args[]) throws Exception {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    39
        for (int i = 0; i < testCases.length; i++) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    40
            testCases[i].run();
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    41
        }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    42
        System.out.println("Test completed ok.");
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
}
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    45
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    46
class TestCase {
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
     private String name;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    49
     private boolean expectedResult;
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
     TestCase(String name, boolean expectedResult) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    52
         this.name = name;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    53
         this.expectedResult = expectedResult;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    54
     }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    55
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    56
     void run() throws Exception {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    57
         Exception f = null;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    58
         try {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    59
             System.out.println("Parsing: \"" + name + "\"");
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    60
             new X500Principal(name);
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    61
             if (expectedResult == false) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    62
                 f = new Exception("Successfully parsed invalid name");
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    63
             }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    64
         } catch (IllegalArgumentException e) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    65
             if (expectedResult == true) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    66
                 throw e;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    67
             }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    68
         }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    69
         if (f != null) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    70
             throw f;
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    71
         }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    72
     }
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents:
diff changeset
    73
}