jdk/test/sun/security/krb5/config/Duration.java
changeset 27946 9f99b93cbbb2
child 30820 0d4717a011d3
equal deleted inserted replaced
27945:dd8be94d105f 27946:9f99b93cbbb2
       
     1 /*
       
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8044500
       
    27  * @summary Add kinit options and krb5.conf flags that allow users to
       
    28  *          obtain renewable tickets and specify ticket lifetimes
       
    29  * @compile -XDignore.symbol.file Duration.java
       
    30  * @run main Duration
       
    31  */
       
    32 import sun.security.krb5.Config;
       
    33 import sun.security.krb5.KrbException;
       
    34 
       
    35 public class Duration {
       
    36     public static void main(String[] args) throws Exception {
       
    37         check("123", 123);
       
    38         check("1:1", 3660);
       
    39         check("1:1:1", 3661);
       
    40         check("1d", 86400);
       
    41         check("1h", 3600);
       
    42         check("1h1m", 3660);
       
    43         check("1h 1m", 3660);
       
    44         check("1d 1h 1m 1s", 90061);
       
    45         check("1d1h1m1s", 90061);
       
    46 
       
    47         check("", -1);
       
    48         check("abc", -1);
       
    49         check("1ms", -1);
       
    50         check("1d1d", -1);
       
    51         check("1h1d", -1);
       
    52         check("x1h", -1);
       
    53         check("1h x 1m", -1);
       
    54         check(":", -1);
       
    55         check("1:60", -1);
       
    56         check("1:1:1:1", -1);
       
    57         check("1:1:1:", -1);
       
    58     }
       
    59 
       
    60     static void check(String s, int ex) throws Exception {
       
    61         System.out.print("\u001b[1;37;41m" +s + " " + ex);
       
    62         System.out.print("\u001b[m\n");
       
    63         try {
       
    64             int result = Config.duration(s);
       
    65             if (result != ex) throw new Exception("for " + s + " is " + result);
       
    66         } catch (KrbException ke) {
       
    67             ke.printStackTrace();
       
    68             if (ex != -1) throw new Exception();
       
    69         }
       
    70     }
       
    71 }