jdk/test/sun/security/krb5/IPv6.java
author weijun
Thu, 24 Sep 2009 21:35:34 +0800
changeset 3944 e098e010b520
parent 3864 21eb0b487d1f
child 5506 202f599c92aa
permissions -rw-r--r--
6885166: regression test for 6877357 (IPv6 address does not work) error (timed out) Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     1
/*
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     4
 *
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     8
 *
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    13
 * accompanied this code).
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    14
 *
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    18
 *
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    21
 * have any questions.
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    22
 */
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    23
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    24
/*
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    25
 * @test
3944
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
    26
 * @bug 6877357 6885166
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    27
 * @summary IPv6 address does not work
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    28
 */
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    29
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    30
import com.sun.security.auth.module.Krb5LoginModule;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    31
import java.io.*;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    32
import java.util.HashMap;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    33
import java.util.Map;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    34
import java.util.regex.Matcher;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    35
import java.util.regex.Pattern;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    36
import javax.security.auth.Subject;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    37
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    38
public class IPv6 {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    39
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    41
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    42
        String[][] kdcs = {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    43
                {"simple.host", null},  // These are legal settings
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    44
                {"simple.host", ""},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    45
                {"simple.host", "8080"},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    46
                {"0.0.0.1", null},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    47
                {"0.0.0.1", ""},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    48
                {"0.0.0.1", "8080"},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    49
                {"1::1", null},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    50
                {"[1::1]", null},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    51
                {"[1::1]", ""},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    52
                {"[1::1]", "8080"},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    53
                {"[1::1", null},        // Two illegal settings
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    54
                {"[1::1]abc", null},
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    55
        };
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    56
        // Prepares a krb5.conf with every kind of KDC settings
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    57
        PrintStream out = new PrintStream(new FileOutputStream("ipv6.conf"));
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    58
        out.println("[libdefaults]");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    59
        out.println("default_realm = V6");
3944
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
    60
        out.println("kdc_timeout = 1");
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    61
        out.println("[realms]");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    62
        out.println("V6 = {");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    63
        for (String[] hp: kdcs) {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    64
            if (hp[1] != null) out.println("    kdc = "+hp[0]+":"+hp[1]);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    65
            else out.println("    kdc = " + hp[0]);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    66
        }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    67
        out.println("}");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    68
        out.close();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    69
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    70
        System.setProperty("sun.security.krb5.debug", "true");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    71
        System.setProperty("java.security.krb5.conf", "ipv6.conf");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    72
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    73
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    74
        PrintStream po = new PrintStream(bo);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    75
        PrintStream oldout = System.out;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    76
        System.setOut(po);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    77
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    78
        try {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    79
            Subject subject = new Subject();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    80
            Krb5LoginModule krb5 = new Krb5LoginModule();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    81
            Map<String, String> map = new HashMap<String, String>();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    82
            Map<String, Object> shared = new HashMap<String, Object>();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    83
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    84
            map.put("debug", "true");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    85
            map.put("doNotPrompt", "true");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    86
            map.put("useTicketCache", "false");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    87
            map.put("useFirstPass", "true");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    88
            shared.put("javax.security.auth.login.name", "any");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    89
            shared.put("javax.security.auth.login.password", "any".toCharArray());
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    90
            krb5.initialize(subject, null, shared, map);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    91
            krb5.login();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    92
        } catch (Exception e) {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    93
            // Ignore
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    94
        }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    95
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    96
        po.flush();
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    97
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
    98
        System.setOut(oldout);
3944
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
    99
        BufferedReader br = new BufferedReader(new StringReader(
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
   100
                new String(bo.toByteArray())));
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   101
        int cc = 0;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   102
        Pattern r = Pattern.compile(".*KrbKdcReq send: kdc=(.*) UDP:(\\d+),.*");
3944
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
   103
        String line;
e098e010b520 6885166: regression test for 6877357 (IPv6 address does not work) error (timed out)
weijun
parents: 3864
diff changeset
   104
        while ((line = br.readLine()) != null) {
3864
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   105
            Matcher m = r.matcher(line.subSequence(0, line.length()));
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   106
            if (m.matches()) {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   107
                System.out.println("------------------");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   108
                System.out.println(line);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   109
                String h = m.group(1), p = m.group(2);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   110
                String eh = kdcs[cc][0], ep = kdcs[cc][1];
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   111
                if (eh.charAt(0) == '[') {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   112
                    eh = eh.substring(1, eh.length()-1);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   113
                }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   114
                System.out.println("Expected: " + eh + " : " + ep);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   115
                System.out.println("Actual: " + h + " : " + p);
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   116
                if (!eh.equals(h) ||
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   117
                        (ep == null || ep.length() == 0) && !p.equals("88") ||
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   118
                        (ep != null && ep.length() > 0) && !p.equals(ep)) {
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   119
                    throw new Exception("Mismatch");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   120
                }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   121
                cc++;
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   122
            }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   123
        }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   124
        if (cc != kdcs.length - 2) {    // 2 illegal settings at the end
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   125
            throw new Exception("Not traversed");
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   126
        }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   127
    }
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   128
}
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   129
21eb0b487d1f 6877357: IPv6 address does not work
weijun
parents:
diff changeset
   130