jdk/test/javax/security/auth/login/modules/JaasModularClientTest.java
author ssahoo
Tue, 26 Jul 2016 09:53:35 +0800
changeset 39774 25d5618feb3c
parent 36511 9d0388c6b336
child 40261 86a49ba76f52
permissions -rw-r--r--
8151654: Additional modular test for "auth.login.defaultCallbackHandler" Reviewed-by: mchung, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.util.LinkedHashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import jdk.testlibrary.ProcessTools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import jdk.testlibrary.OutputAnalyzer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * @bug 8078813
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * @library /java/security/modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * @build CompilerUtils JarUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * @summary Test custom JAAS module with all possible modular option. The test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 *          includes different combination of JAAS client/login modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 *          interaction with or without service description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 * @run testng JaasModularClientTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
public class JaasModularClientTest extends ModularTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final Path S_SRC = SRC.resolve("TestLoginModule.java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    private static final String S_PKG = "login";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final String S_JAR_NAME = S_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String S_DESCR_JAR_NAME = S_PKG + DESCRIPTOR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
            + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final String MS_JAR_NAME = MODULAR + S_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final String MS_DESCR_JAR_NAME = MODULAR + S_PKG + DESCRIPTOR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
            + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final Path C_SRC = SRC.resolve("JaasClient.java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    private static final String C_PKG = "client";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String C_JAR_NAME = C_PKG + JAR_EXTN;
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
    62
    private static final String MCN_JAR_NAME = MODULAR + C_PKG + "N" + JAR_EXTN;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    private static final String MC_JAR_NAME = MODULAR + C_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    private static final Path BUILD_DIR = Paths.get(".").resolve("build");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    private static final Path COMPILE_DIR = BUILD_DIR.resolve("bin");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    private static final Path S_BUILD_DIR = COMPILE_DIR.resolve(S_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    private static final Path S_WITH_META_DESCR_BUILD_DIR = COMPILE_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            S_PKG + DESCRIPTOR);
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
    70
    private static final Path C_BLD_DIR = COMPILE_DIR.resolve(C_PKG);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    private static final Path M_BASE_PATH = BUILD_DIR.resolve("mbase");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    private static final Path ARTIFACTS_DIR = BUILD_DIR.resolve("artifacts");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    private static final Path S_ARTIFACTS_DIR = ARTIFACTS_DIR.resolve(S_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    private static final Path S_JAR = S_ARTIFACTS_DIR.resolve(S_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    private static final Path S_WITH_DESCRIPTOR_JAR = S_ARTIFACTS_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            S_DESCR_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    private static final Path MS_JAR = S_ARTIFACTS_DIR.resolve(MS_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    private static final Path MS_WITH_DESCR_JAR = S_ARTIFACTS_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
            MS_DESCR_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    private static final Path C_ARTIFACTS_DIR = ARTIFACTS_DIR.resolve(C_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    private static final Path C_JAR = C_ARTIFACTS_DIR.resolve(C_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    private static final Path MC_JAR = C_ARTIFACTS_DIR.resolve(MC_JAR_NAME);
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
    85
    private static final Path MCN_JAR = C_ARTIFACTS_DIR.resolve(MCN_JAR_NAME);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    private static final String MAIN = C_PKG + ".JaasClient";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    private static final String S_INTERFACE
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            = "javax.security.auth.spi.LoginModule";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    private static final String S_IMPL = S_PKG + ".TestLoginModule";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    private static final List<String> M_REQUIRED = Arrays.asList("java.base",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
            "jdk.security.auth");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    private static final Path META_DESCR_PATH = Paths.get("META-INF")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            .resolve("services").resolve(S_INTERFACE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    private static final Path S_META_DESCR_FPATH = S_WITH_META_DESCR_BUILD_DIR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            .resolve(META_DESCR_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    private static final boolean WITH_S_DESCR = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
    private static final boolean WITHOUT_S_DESCR = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    private static final String NO_FAILURE = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
     * Generates Test specific input parameters.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    public Object[][] getTestInput() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        List<List<Object>> params = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        String[] args = new String[]{};
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   110
        // PARAMETER ORDERS -
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   111
        // Client Module Type, Service Module Type,
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   112
        // If Service META descriptor Required,
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   113
        // Expected Failure message, Client arguments
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.AUTO,
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   121
                WITHOUT_S_DESCR, NO_FAILURE, args));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.AUTO,
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   134
                WITHOUT_S_DESCR, NO_FAILURE, args));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.AUTO,
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   147
                WITHOUT_S_DESCR, NO_FAILURE, args));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        return params.stream().map(p -> p.toArray()).toArray(Object[][]::new);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
     * Pre-compile and generate the artifacts required to run this test before
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
     * running each test cases.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    public void buildArtifacts() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        boolean done = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            done = CompilerUtils.compile(S_SRC, S_BUILD_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            done &= CompilerUtils.compile(S_SRC, S_WITH_META_DESCR_BUILD_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
            done &= createMetaInfServiceDescriptor(S_META_DESCR_FPATH, S_IMPL);
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   167
            // Generate modular/regular jars with(out) META-INF
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   168
            // service descriptor
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            generateJar(true, MODULE_TYPE.EXPLICIT, MS_JAR, S_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            generateJar(true, MODULE_TYPE.EXPLICIT, MS_WITH_DESCR_JAR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                    S_WITH_META_DESCR_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            generateJar(true, MODULE_TYPE.UNNAMED, S_JAR, S_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
            generateJar(true, MODULE_TYPE.UNNAMED, S_WITH_DESCRIPTOR_JAR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                    S_WITH_META_DESCR_BUILD_DIR, false);
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   175
            // Compile client source codes.
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   176
            done &= CompilerUtils.compile(C_SRC, C_BLD_DIR);
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   177
            // Generate modular client jar with explicit dependency
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   178
            generateJar(false, MODULE_TYPE.EXPLICIT, MC_JAR, C_BLD_DIR, true);
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   179
            // Generate modular client jar without any dependency
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   180
            generateJar(false, MODULE_TYPE.EXPLICIT, MCN_JAR, C_BLD_DIR, false);
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   181
            // Generate regular client jar
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   182
            generateJar(false, MODULE_TYPE.UNNAMED, C_JAR, C_BLD_DIR, false);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            System.out.format("%nArtifacts generated successfully? %s", done);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            if (!done) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                throw new RuntimeException("Artifact generation failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        } catch (IOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            throw new RuntimeException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
     * Generate modular/regular jar based on module type for this test.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
    private void generateJar(boolean isService, MODULE_TYPE moduleType,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
            Path jar, Path compilePath, boolean depends) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        ModuleDescriptor mDescriptor = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        if (isService) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
            mDescriptor = generateModuleDescriptor(isService, moduleType, S_PKG,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                    S_PKG, S_INTERFACE, S_IMPL, null, M_REQUIRED, depends);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            mDescriptor = generateModuleDescriptor(isService, moduleType, C_PKG,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                    C_PKG, S_INTERFACE, null, S_PKG, M_REQUIRED, depends);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        generateJar(mDescriptor, jar, compilePath);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
     * Holds Logic for the test client. This method will get called with each
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
     * test parameter.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
    public OutputAnalyzer executeTestClient(MODULE_TYPE cModuleType,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            Path cJarPath, MODULE_TYPE sModuletype, Path sJarPath,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
            String... args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        OutputAnalyzer output = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        try {
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   220
            // For automated/explicit module types, copy the corresponding
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   221
            // jars to module base folder, which will be considered as
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   222
            // module base path during execution.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            if (!(cModuleType == MODULE_TYPE.UNNAMED
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                    && sModuletype == MODULE_TYPE.UNNAMED)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                copyJarsToModuleBase(cModuleType, cJarPath, M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                copyJarsToModuleBase(sModuletype, sJarPath, M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            System.out.format("%nExecuting java client with required"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                    + " custom service in class/module path.");
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   231
            String mName = getModuleName(cModuleType, cJarPath, C_PKG);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
            Path cmBasePath = (cModuleType != MODULE_TYPE.UNNAMED
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                    || sModuletype != MODULE_TYPE.UNNAMED) ? M_BASE_PATH : null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
            String cPath = buildClassPath(cModuleType, cJarPath, sModuletype,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                    sJarPath);
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   236
            Map<String, String> vmArgs = getVMArgs(sModuletype,
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   237
                    getModuleName(sModuletype, sJarPath, S_PKG));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            output = ProcessTools.executeTestJava(
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   239
                    getJavaCommand(cmBasePath, cPath, mName, MAIN, vmArgs,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                            args)).outputTo(System.out).errorTo(System.out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        } finally {
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   242
            // Clean module path to hold required jars for next run.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
            cleanModuleBasePath(M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        return output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
     * Decide the pre-generated client/service jar path for each test case
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
     * based on client/service module type.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
    @Override
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   253
    public Path findJarPath(boolean isService, MODULE_TYPE moduleType,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
            boolean addMetaDesc, boolean dependsOnServiceModule) {
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   255
        if (isService) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
            if (moduleType == MODULE_TYPE.EXPLICIT) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                if (addMetaDesc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                    return MS_WITH_DESCR_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                    return MS_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                if (addMetaDesc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                    return S_WITH_DESCRIPTOR_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                    return S_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        } else {
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   270
            // Choose corresponding client jar using dependent module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
            if (moduleType == MODULE_TYPE.EXPLICIT) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                if (dependsOnServiceModule) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                    return MC_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                } else {
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   275
                    return MCN_JAR;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                return C_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
39774
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   283
    /**
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   284
     * VM argument required for the test.
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   285
     */
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   286
    private Map<String, String> getVMArgs(MODULE_TYPE sModuletype,
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   287
            String addModName) throws IOException {
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   288
        final Map<String, String> vmArgs = new LinkedHashMap<>();
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   289
        vmArgs.put("-Duser.language=", "en");
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   290
        vmArgs.put("-Duser.region=", "US");
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   291
        vmArgs.put("-Djava.security.auth.login.config=", SRC.resolve(
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   292
                "jaas.conf").toFile().getCanonicalPath());
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   293
        if (addModName != null && sModuletype == MODULE_TYPE.AUTO) {
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   294
            vmArgs.put("-addmods ", addModName);
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   295
        }
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   296
        return vmArgs;
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   297
    }
25d5618feb3c 8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents: 36511
diff changeset
   298
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
}