jdk/test/sun/security/krb5/TimeInCCache.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 76 87bd6df367b8
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 76
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     4
 *
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     8
 *
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    13
 * accompanied this code).
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    14
 *
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    18
 *
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    21
 * have any questions.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    22
 */
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    23
/*
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    24
 * @test
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    25
 * @bug 6590930
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    26
 * @summary read/write does not match for ccache
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    27
 */
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    28
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    29
import java.io.ByteArrayInputStream;
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    30
import java.lang.reflect.Field;
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    31
import java.lang.reflect.Method;
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    32
import sun.security.krb5.internal.ccache.CCacheInputStream;
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    33
import sun.security.krb5.internal.ccache.Credentials;
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    34
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    35
public class TimeInCCache {
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    37
        // A trivial cache file, with startdate and renewTill being zero.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    38
        // The endtime is set to sometime in year 2022, so that isValid()
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    39
        // will always check starttime.
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    40
        byte[] ccache = new byte[]{
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    41
            5, 4, 0, 12, 0, 1, 0, 8, -1, -1, -1, 19, -1, -2, 89, 51,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    42
            0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 77, 65, 88, 73,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    43
            46, 76, 79, 67, 65, 76, 0, 0, 0, 5, 100, 117, 109, 109, 121, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    44
            0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 77, 65, 88, 73, 46,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    45
            76, 79, 67, 65, 76, 0, 0, 0, 5, 100, 117, 109, 109, 121, 0, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    46
            0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 77, 65, 88, 73, 46, 76,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    47
            79, 67, 65, 76, 0, 0, 0, 6, 107, 114, 98, 116, 103, 116, 0, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    48
            0, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, 0, 17, 0, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    49
            0, 16, -78, -85, -90, -50, -68, 115, 68, 8, -39, -109, 91, 61, -17, -27,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    50
            -122, -120, 71, 69, 16, -121, 0, 0, 0, 0, 98, 69, 16, -121, 0, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    51
            0, 0, 0, 64, -32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    52
            0, 1, 0, 97, -127, -3, 48, -127, -6, -96, 3, 2, 1, 5, -95, 12,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    53
            27, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, -94, 31, 48, 29,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    54
            -96, 3, 2, 1, 0, -95, 22, 48, 20, 27, 6, 107, 114, 98, 116, 103,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    55
            116, 27, 10, 77, 65, 88, 73, 46, 76, 79, 67, 65, 76, -93, -127, -61,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    56
            48, -127, -64, -96, 3, 2, 1, 17, -95, 3, 2, 1, 1, -94, -127, -77,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    57
            4, -127, -80, 43, 65, -66, 34, 21, -34, 37, 35, 32, 50, -14, 122, 77,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    58
            -3, -29, 37, 99, 50, 125, -43, -96, -78, 85, 23, 41, -80, 68, 2, -109,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    59
            -27, 38, -41, -72, -32, 127, 63, -76, -22, 81, 33, -114, -30, 104, 125, -81,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    60
            -29, 70, -25, 23, 100, -75, -25, 62, -120, -78, -61, -100, -74, 50, -117, -127,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    61
            -16, 79, -106, 62, -39, 91, 100, -10, 23, -88, -18, -47, 51, -19, 113, 18,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    62
            98, -101, 31, 98, 22, -81, 11, -41, -42, 67, 87, 92, -2, 42, -54, 79,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    63
            49, -90, 43, -37, 90, -102, 125, 62, -88, -77, 100, 102, 23, -57, -51, 38,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    64
            68, -44, -57, -102, 103, -6, 85, -58, 74, -117, -87, 67, -103, -36, 110, -122,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    65
            115, 12, 118, -106, -114, -51, 79, 68, 32, -91, -53, -5, -51, 89, 72, 70,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    66
            123, -12, -95, 9, 40, -30, -117, 74, 77, 38, 91, 126, -82, 17, 98, 98,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    67
            -49, 78, 36, 36, 103, -76, -100, -23, 118, -92, -8, 80, 103, -23, -98, 56,
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    68
            21, 65, -77, 0, 0, 0, 0
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    69
        };
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    70
        System.setProperty("sun.security.krb5.debug", "true");  // test code changes in DEBUG
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    71
        CCacheInputStream cis = new CCacheInputStream(new ByteArrayInputStream(ccache));
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    72
        cis.readVersion();
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    73
        cis.readTag();
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    74
        cis.readPrincipal(0x504);
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    75
        Method m = CCacheInputStream.class.getDeclaredMethod("readCred", Integer.TYPE);
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    76
        m.setAccessible(true);
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    77
        Credentials c = (Credentials) m.invoke(cis, new Integer(0x504));
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    78
        sun.security.krb5.Credentials cc = c.setKrbCreds();
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    79
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    80
        // 1. Make sure starttime is still null
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    81
        if (cc.getStartTime() != null) {
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    82
            throw new Exception("Fail, starttime should be zero here");
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    83
        }
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    84
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    85
        // 2. Make sure renewTill is still null
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    86
        if (cc.getRenewTill() != null) {
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    87
            throw new Exception("Fail, renewTill should be zero here");
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    88
        }
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    89
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    90
        // 3. Make sure isValid works
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    91
        c.isValid();
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    92
    }
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents:
diff changeset
    93
}