test/jdk/sun/security/tools/keytool/DupCommands.java
author vtewari
Wed, 25 Apr 2018 12:29:48 +0530
changeset 49882 a02abc7e5536
parent 47216 71c04702a3d5
permissions -rw-r--r--
8144806: sun/security/tools/keytool/standard.sh fails intermittently at deleting x.jks Reviewed-by: weijun Contributed-by: bhanu.prakash.gopularam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45839
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     1
/*
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     4
 *
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     8
 *
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    13
 * accompanied this code).
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    14
 *
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    18
 *
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    21
 * questions.
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    22
 */
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    23
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    24
/*
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    25
 * @test
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    26
 * @bug 8183509
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    27
 * @summary keytool should not allow multiple commands
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    28
 * @library /test/lib
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    29
 * @build jdk.test.lib.SecurityTools
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    30
 *        jdk.test.lib.Utils
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    31
 *        jdk.test.lib.Asserts
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    32
 *        jdk.test.lib.JDKToolFinder
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    33
 *        jdk.test.lib.JDKToolLauncher
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    34
 *        jdk.test.lib.Platform
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    35
 *        jdk.test.lib.process.*
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    36
 * @run main/othervm DupCommands
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    37
 */
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    38
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    39
import jdk.test.lib.SecurityTools;
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    40
import jdk.test.lib.process.OutputAnalyzer;
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    41
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    42
public class DupCommands {
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    43
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    44
    public static void main(String[] args) throws Throwable {
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    45
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    46
        kt("-list -printcert")
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    47
                .shouldHaveExitValue(1)
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    48
                .shouldContain("Only one command is allowed");
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    49
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    50
        kt("-import -importcert") // command with different names
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    51
                .shouldHaveExitValue(1)
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    52
                .shouldContain("Only one command is allowed");
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    53
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    54
        kt("-help -v -v")
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    55
                .shouldHaveExitValue(0)
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    56
                .shouldContain("The -v option is specified multiple times.");
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    57
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    58
        kt("-help -id 1 -id 2") // some options are allowed multiple times
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    59
                .shouldHaveExitValue(0)
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    60
                .shouldNotContain("specified multiple times.");
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    61
    }
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    62
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    63
    static OutputAnalyzer kt(String arg) throws Exception {
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    64
        return SecurityTools.keytool(arg);
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    65
    }
6df5e24443fc 8183509: keytool should not allow multiple commands
weijun
parents:
diff changeset
    66
}