jdk/test/sun/security/krb5/auto/TcpTimeout.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 23339 d66b18f52418
child 31474 7b79555b8073
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13016
diff changeset
     2
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     4
 *
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     8
 *
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    13
 * accompanied this code).
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    14
 *
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    18
 *
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    21
 * questions.
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    22
 */
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    23
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    24
/*
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    25
 * @test
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    26
 * @bug 6952519
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    27
 * @modules java.base/sun.net.spi.nameservice
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    28
 *          java.base/sun.security.util
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    29
 *          java.security.jgss/sun.security.krb5
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    30
 *          java.security.jgss/sun.security.krb5.internal
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    31
 *          java.security.jgss/sun.security.krb5.internal.ccache
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    32
 *          java.security.jgss/sun.security.krb5.internal.crypto
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 23339
diff changeset
    33
 *          java.security.jgss/sun.security.krb5.internal.ktab
12842
f6f9cb8f6b97 7162687: enhance KDC server availability detection
weijun
parents: 11357
diff changeset
    34
 * @compile -XDignore.symbol.file TcpTimeout.java
11357
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    35
 * @run main/othervm TcpTimeout
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    36
 * @summary kdc_timeout is not being honoured when using TCP
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    37
 */
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    38
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    39
import java.io.*;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    40
import java.net.ServerSocket;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    41
import sun.security.krb5.Config;
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    42
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    43
public class TcpTimeout {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    44
    public static void main(String[] args)
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    45
            throws Exception {
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    46
11357
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    47
        // Set debug to grab debug output like ">>> KDCCommunication"
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    48
        System.setProperty("sun.security.krb5.debug", "true");
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    49
11357
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    50
        // Called before new ServerSocket on p1 and p2 to make sure
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    51
        // customized nameservice is used
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    52
        KDC k = new KDC(OneKDC.REALM, OneKDC.KDCHOST, 0, true);
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    53
        int p3 = k.getPort();
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    54
        k.addPrincipal(OneKDC.USER, OneKDC.PASS);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    55
        k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM);
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    56
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    57
        // Start two listener that does not communicate, simulate timeout
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    58
        ServerSocket ss1 = null;
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    59
        ServerSocket ss2 = null;
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    60
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    61
        try {
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    62
            ss1 = new ServerSocket(0);
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    63
            ss2 = new ServerSocket(0);
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    64
            int p1 = ss1.getLocalPort();
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    65
            int p2 = ss2.getLocalPort();
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    66
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    67
            FileWriter fw = new FileWriter("alternative-krb5.conf");
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    68
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    69
            fw.write("[libdefaults]\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    70
                    "udp_preference_limit = 1\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    71
                    "max_retries = 2\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    72
                    "default_realm = " + OneKDC.REALM + "\n" +
23339
d66b18f52418 8035963: The failed Kerberos tests due to timeouts
weijun
parents: 14342
diff changeset
    73
                    "kdc_timeout = " + BadKdc.toReal(5000) + "\n");
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    74
            fw.write("[realms]\n" + OneKDC.REALM + " = {\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    75
                    "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    76
                    "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    77
                    "kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" +
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    78
                    "}\n");
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    79
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    80
            fw.close();
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    81
            System.setProperty("java.security.krb5.conf",
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    82
                    "alternative-krb5.conf");
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    83
            Config.refresh();
11357
0ef20e50a018 7122169: TcpTimeout fail for various reasons
weijun
parents: 7175
diff changeset
    84
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    85
            System.out.println("Ports opened on " + p1 + ", " + p2 + ", " + p3);
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    86
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    87
            // The correct behavior should be:
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    88
            // 5 sec on p1, 5 sec on p1, fail
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    89
            // 5 sec on p2, 5 sec on p2, fail
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    90
            // p3 ok, p3 ok again for preauth.
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    91
            int count = 6;
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    92
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    93
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    94
            PrintStream oldout = System.out;
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    95
            System.setOut(new PrintStream(bo));
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    96
            Context c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    97
            System.setOut(oldout);
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
    98
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
    99
            String[] lines = new String(bo.toByteArray()).split("\n");
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   100
            for (String line: lines) {
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   101
                if (line.startsWith(">>> KDCCommunication")) {
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   102
                    System.out.println(line);
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   103
                    count--;
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   104
                }
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
   105
            }
13016
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   106
            if (count != 0) {
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   107
                throw new Exception("Retry count is " + count + " less");
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   108
            }
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   109
        } finally {
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   110
            if (ss1 != null) ss1.close();
8e43ddef9617 7176574: sun/security/krb5/auto/TcpTimeout.java failed with solaris-i586
weijun
parents: 12842
diff changeset
   111
            if (ss2 != null) ss2.close();
7175
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
   112
        }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
   113
    }
46ec4c2dbc16 6952519: kdc_timeout is not being honoured when using TCP
weijun
parents:
diff changeset
   114
}