author | iveresov |
Fri, 28 Jun 2019 21:41:04 -0700 | |
changeset 55540 | d4de822dc421 |
parent 51977 | a8862960c19f |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
45393 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
import java.nio.file.Files; |
|
25 |
import java.nio.file.Path; |
|
26 |
import java.nio.file.Paths; |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
27 |
import java.nio.file.StandardCopyOption; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
28 |
import java.security.Security; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
29 |
import java.util.Collections; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
30 |
import java.util.HashMap; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
31 |
import java.util.LinkedList; |
36511 | 32 |
import java.util.List; |
33 |
import java.util.Map; |
|
34 |
import java.util.Arrays; |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
35 |
import java.util.stream.Stream; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
36 |
import java.io.File; |
36511 | 37 |
import java.io.IOException; |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
38 |
import java.io.OutputStream; |
36511 | 39 |
import java.lang.module.ModuleDescriptor; |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
40 |
import java.lang.module.ModuleDescriptor.Builder; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
41 |
import jdk.internal.module.ModuleInfoWriter; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
42 |
import jdk.test.lib.process.ProcessTools; |
51977
a8862960c19f
8211171: move JarUtils to top-level testlibrary
iignatyev
parents:
47216
diff
changeset
|
43 |
import jdk.test.lib.util.JarUtils; |
36511 | 44 |
|
45 |
||
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
46 |
/* |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
47 |
* @test |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
48 |
* @bug 8130360 8183310 |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
49 |
* @summary Test security provider in different combination of modular option |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
50 |
* defined with(out) service description. |
51977
a8862960c19f
8211171: move JarUtils to top-level testlibrary
iignatyev
parents:
47216
diff
changeset
|
51 |
* @library /test/lib |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
52 |
* @modules java.base/jdk.internal.module |
51977
a8862960c19f
8211171: move JarUtils to top-level testlibrary
iignatyev
parents:
47216
diff
changeset
|
53 |
* @build jdk.test.lib.util.JarUtils TestProvider TestClient |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
54 |
* @run main SecurityProviderModularTest CL true |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
55 |
* @run main SecurityProviderModularTest CL false |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
56 |
* @run main SecurityProviderModularTest SL true |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
57 |
* @run main SecurityProviderModularTest SL false |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
58 |
* @run main SecurityProviderModularTest SPN true |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
59 |
* @run main SecurityProviderModularTest SPN false |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
60 |
* @run main SecurityProviderModularTest SPT true |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
61 |
* @run main SecurityProviderModularTest SPT false |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
62 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
63 |
public class SecurityProviderModularTest { |
36511 | 64 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
65 |
private static final Path TEST_CLASSES |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
66 |
= Paths.get(System.getProperty("test.classes")); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
67 |
private static final Path ARTIFACT_DIR = Paths.get("jars"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
68 |
private static final Path SEC_FILE = Paths.get("java.extn.security"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
69 |
private static final String PS = File.pathSeparator; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
70 |
private static final String P_TYPE = "p.TestProvider"; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
71 |
private static final String C_TYPE = "c.TestClient"; |
36511 | 72 |
|
73 |
/** |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
74 |
* Here is the naming convention followed. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
75 |
* Test runtime arguments, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
76 |
* CL - Provider class loaded through ClassLoader |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
77 |
* SL - Provider class to be discovered by ServiceLoader |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
78 |
* SPN - Provider name defined through "java.extn.security" file which |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
79 |
* referred through system property "java.security.properties". |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
80 |
* SPT - Provider type defined through "java.extn.security" file which |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
81 |
* referred through system property "java.security.properties". |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
82 |
* |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
83 |
* For each jar file name, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
84 |
* p.jar - Unnamed provider jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
85 |
* pd.jar - Unnamed provider jar with META-INF provider descriptor. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
86 |
* mp.jar - Modular provider jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
87 |
* mpd.jar - Modular provider jar with META-INF provider descriptor. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
88 |
* msp.jar - Modular provider jar provides service through module-info.java |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
89 |
* mspd.jar - Modular provider jar with META-INF provider descriptor and |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
90 |
* provides service through module-info.java. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
91 |
* c.jar - Unnamed client jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
92 |
* mc.jar - Modular client jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
93 |
* mcs.jar - Modular client jar uses service through module-info.java. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
94 |
* amc.jar - Modular client used for automatic provider jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
95 |
* amcs.jar - Modular client used for automatic provider jar uses service |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
96 |
* through module-info.java. |
36511 | 97 |
*/ |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
98 |
private static final Path P_JAR = artifact("p.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
99 |
private static final Path PD_JAR = artifact("pd.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
100 |
private static final Path MP_JAR = artifact("mp.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
101 |
private static final Path MPD_JAR = artifact("mpd.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
102 |
private static final Path MSP_JAR = artifact("msp.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
103 |
private static final Path MSPD_JAR = artifact("mspd.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
104 |
private static final Path C_JAR = artifact("c.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
105 |
private static final Path MC_JAR = artifact("mc.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
106 |
private static final Path MCS_JAR = artifact("mcs.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
107 |
private static final Path AMC_JAR = artifact("amc.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
108 |
private static final Path AMCS_JAR = artifact("amcs.jar"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
109 |
private static final Map<String, String> MSG_MAP = new HashMap<>(); |
36511 | 110 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
111 |
static { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
112 |
/* |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
113 |
* This mapping help process finding expected message based |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
114 |
* on the key passed as argument while executing java command. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
115 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
116 |
MSG_MAP.put("NoAccess", "cannot access class p.TestProvider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
117 |
MSG_MAP.put("Success", "Client: found provider TestProvider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
118 |
MSG_MAP.put("NoProvider", "Provider TestProvider not found"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
119 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
120 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
121 |
private final String addUNArg; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
122 |
private final String addNMArg; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
123 |
private final String cArg; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
124 |
private final String unnP; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
125 |
private final String modP; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
126 |
private final String unnC; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
127 |
private final String modC; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
128 |
private final String autoMC; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
129 |
private final String expModRes; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
130 |
private final String expAModRes; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
131 |
// Common set of VM arguments used in all test cases |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
132 |
private final List<String> commonArgs; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
133 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
134 |
public SecurityProviderModularTest(String use, boolean metaDesc) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
135 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
136 |
List<String> argList = new LinkedList<>(); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
137 |
argList.add("-Duser.language=en"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
138 |
argList.add("-Duser.region=US"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
139 |
final boolean useSL = "SL".equals(use) || "SPN".equals(use); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
140 |
final boolean useCL = "CL".equals(use); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
141 |
final boolean useSPT = "SPT".equals(use); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
142 |
final boolean useSP = use.startsWith("SP"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
143 |
/* Use Security property file when the provider expected to |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
144 |
* loaded through Security property file. */ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
145 |
if (useSP) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
146 |
/* Create a java.security file to specify the new provider. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
147 |
* java.security file extension can be provided using |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
148 |
* "-Djava.security.properties" VM argument at runtime.*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
149 |
createJavaSecurityFileExtn("SPN".equals(use)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
150 |
argList.add("-Djava.security.properties=" + toAbsPath(SEC_FILE)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
151 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
152 |
commonArgs = Collections.unmodifiableList(argList); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
153 |
cArg = (useCL) ? P_TYPE : "TestProvider"; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
154 |
addUNArg = (useSL) ? "" : ("--add-modules=" |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
155 |
+ ((metaDesc) ? "pd" : "p")); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
156 |
addNMArg = (useSL) ? "" : "--add-modules=mp"; |
36511 | 157 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
158 |
// Based on Testcase, select unnamed/modular jar files to use. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
159 |
unnP = toAbsPath((metaDesc) ? PD_JAR : P_JAR); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
160 |
modP = toAbsPath(useSL ? (metaDesc ? MSPD_JAR : MSP_JAR) |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
161 |
: (metaDesc ? MPD_JAR : MP_JAR)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
162 |
unnC = toAbsPath(C_JAR); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
163 |
modC = toAbsPath(useSL ? MCS_JAR : MC_JAR); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
164 |
autoMC = toAbsPath(useSL ? AMCS_JAR : AMC_JAR); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
165 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
166 |
expModRes = "Success"; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
167 |
expAModRes = (useSPT | useCL) ? "Success" |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
168 |
: (metaDesc) ? "Success" : "NoProvider"; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
169 |
String loadByMsg = useSP ? "SecurityPropertyFile" |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
170 |
: ((useCL) ? "ClassLoader" : "ServiceLoader"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
171 |
System.out.printf("%n*** Providers loaded through %s and includes" |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
172 |
+ " META Descriptor: %s ***%n%n", loadByMsg, metaDesc); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
173 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
174 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
175 |
/* |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
176 |
* Test cases are based on the following logic, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
177 |
* for (ProviderLoadedThrough : {"ServiceLoader", "ClassLoader", |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
178 |
* "SecurityPropertyFile"}) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
179 |
* for (definedWith : {"METAINFService", "WithoutMETAINFService"}) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
180 |
* for (clientType : {"NAMED", "AUTOMATIC", "UNNAMED"}) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
181 |
* for (providerType : {"NAMED", "AUTOMATIC", "UNNAMED"}) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
182 |
* Create and run java command for each possible case |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
183 |
* } |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
184 |
* } |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
185 |
* } |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
186 |
* } |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
187 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
188 |
public static void main(String[] args) throws Exception { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
189 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
190 |
// Generates unnamed and modular jars. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
191 |
setUp(); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
192 |
boolean metaDesc = Boolean.valueOf(args[1]); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
193 |
SecurityProviderModularTest test |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
194 |
= new SecurityProviderModularTest(args[0], metaDesc); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
195 |
test.process(args[0]); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
196 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
197 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
198 |
private void process(String use) throws Exception { |
36511 | 199 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
200 |
// Case: NAMED-NAMED, NAMED-AUTOMATIC, NAMED-UNNAMED |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
201 |
System.out.printf("Case: Modular Client and Modular Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
202 |
execute(String.format("--module-path %s%s%s -m mc/%s %s %s", |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
203 |
modC, PS, modP, C_TYPE, use, cArg), expModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
204 |
System.out.printf("Case: Modular Client and automatic Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
205 |
execute(String.format("--module-path %s%s%s %s -m mc/%s %s %s", autoMC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
206 |
PS, unnP, addUNArg, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
207 |
System.out.printf("Case: Modular Client and unnamed Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
208 |
execute(String.format("--module-path %s -cp %s -m mc/%s %s %s", autoMC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
209 |
unnP, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
210 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
211 |
// Case: AUTOMATIC-NAMED, AUTOMATIC-AUTOMATIC, AUTOMATIC-UNNAMED |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
212 |
System.out.printf("Case: Automatic Client and modular Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
213 |
execute(String.format("--module-path %s%s%s %s -m c/%s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
214 |
PS, modP, addNMArg, C_TYPE, use, cArg), expModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
215 |
System.out.printf("Case: Automatic Client and automatic Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
216 |
execute(String.format("--module-path %s%s%s %s -m c/%s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
217 |
PS, unnP, addUNArg, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
218 |
System.out.printf("Case: Automatic Client and unnamed Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
219 |
execute(String.format("--module-path %s -cp %s -m c/%s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
220 |
unnP, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
221 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
222 |
// Case: UNNAMED-NAMED, UNNAMED-AUTOMATIC, UNNAMED-UNNAMED |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
223 |
System.out.printf("Case: Unnamed Client and modular Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
224 |
execute(String.format("-cp %s --module-path %s %s %s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
225 |
modP, addNMArg, C_TYPE, use, cArg), expModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
226 |
System.out.printf("Case: Unnamed Client and automatic Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
227 |
execute(String.format("-cp %s --module-path %s %s %s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
228 |
unnP, addUNArg, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
229 |
System.out.printf("Case: Unnamed Client and unnamed Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
230 |
execute(String.format("-cp %s%s%s %s %s %s", unnC, PS, unnP, C_TYPE, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
231 |
use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
232 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
233 |
// Case: unnamed jars in --module-path and modular jars in -cp. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
234 |
System.out.printf( |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
235 |
"Case: Unnamed Client and Unnamed Provider in modulepath"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
236 |
execute(String.format("--module-path %s%s%s %s -m c/%s %s %s", unnC, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
237 |
PS, unnP, addUNArg, C_TYPE, use, cArg), expAModRes); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
238 |
System.out.printf( |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
239 |
"Case: Modular Client and Modular Provider in classpath"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
240 |
execute(String.format("-cp %s%s%s %s %s %s", modC, PS, modP, C_TYPE, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
241 |
use, cArg), expAModRes); |
36511 | 242 |
} |
243 |
||
244 |
/** |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
245 |
* Execute with command arguments and process the result. |
36511 | 246 |
*/ |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
247 |
private void execute(String args, String msgKey) throws Exception { |
36511 | 248 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
249 |
String[] safeArgs = Stream.concat(commonArgs.stream(), |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
250 |
Stream.of(args.split("\\s+"))).filter(s -> { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
251 |
if (s.contains(" ")) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
252 |
throw new RuntimeException("No spaces in args"); |
36511 | 253 |
} |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
254 |
return !s.isEmpty(); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
255 |
}).toArray(String[]::new); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
256 |
String out = ProcessTools.executeTestJvm(safeArgs).getOutput(); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
257 |
// Handle response. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
258 |
if ((msgKey != null && out.contains(MSG_MAP.get(msgKey)))) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
259 |
System.out.printf("PASS: Expected Result: %s.%n", |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
260 |
MSG_MAP.get(msgKey)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
261 |
} else if (out.contains("Exception") || out.contains("Error")) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
262 |
System.out.printf("OUTPUT: %s", out); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
263 |
throw new RuntimeException("FAIL: Unknown Exception occured. " |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
264 |
+ "Expected: " + MSG_MAP.get(msgKey)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
265 |
} else { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
266 |
System.out.printf("OUTPUT: %s", out); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
267 |
throw new RuntimeException("FAIL: Unknown Test case found"); |
36511 | 268 |
} |
269 |
} |
|
270 |
||
271 |
/** |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
272 |
* Creates Unnamed/modular jar files for TestClient and TestClassLoader. |
36511 | 273 |
*/ |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
274 |
private static void setUp() throws Exception { |
36511 | 275 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
276 |
if (ARTIFACT_DIR.toFile().exists()) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
277 |
System.out.println("Skipping setup: Artifacts already exists."); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
278 |
return; |
36511 | 279 |
} |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
280 |
// Generate unnamed provider jar file. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
281 |
JarUtils.createJarFile(P_JAR, TEST_CLASSES, "p/TestProvider.class"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
282 |
// Generate unnamed client jar file. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
283 |
JarUtils.createJarFile(C_JAR, TEST_CLASSES, "c/TestClient.class"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
284 |
// Generate unnamed provider jar files with META-INF descriptor. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
285 |
generateJar(P_JAR, PD_JAR, null, true); |
36511 | 286 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
287 |
Builder mBuilder = ModuleDescriptor.newModule("mp").exports("p"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
288 |
// Modular provider defined as META-INF service. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
289 |
generateJar(P_JAR, MPD_JAR, mBuilder.build(), true); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
290 |
// Modular jar exports package to let the provider type accessible. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
291 |
generateJar(P_JAR, MP_JAR, mBuilder.build(), false); |
36511 | 292 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
293 |
mBuilder = ModuleDescriptor.newModule("mp") |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
294 |
.provides("java.security.Provider", Arrays.asList(P_TYPE)); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
295 |
// Modular provider Service in module-info does not need to export |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
296 |
// its package. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
297 |
generateJar(P_JAR, MSP_JAR, mBuilder.build(), false); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
298 |
// Modular provider Service in module-info also have META-INF descriptor |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
299 |
generateJar(P_JAR, MSPD_JAR, mBuilder.build(), true); |
36511 | 300 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
301 |
mBuilder = ModuleDescriptor.newModule("mc").exports("c"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
302 |
// Generate modular client jar file to use automatic provider jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
303 |
generateJar(C_JAR, AMC_JAR, mBuilder.build(), false); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
304 |
// Generate modular client jar file to use modular provider jar. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
305 |
generateJar(C_JAR, MC_JAR, mBuilder.requires("mp").build(), false); |
36511 | 306 |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
307 |
mBuilder = ModuleDescriptor.newModule("mc").exports("c") |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
308 |
.uses("java.security.Provider"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
309 |
// Generate modular client jar file to use automatic provider service. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
310 |
generateJar(C_JAR, AMCS_JAR, mBuilder.build(), false); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
311 |
// Generate modular client jar file using modular provider service. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
312 |
generateJar(C_JAR, MCS_JAR, mBuilder.requires("mp").build(), false); |
36511 | 313 |
} |
314 |
||
315 |
/** |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
316 |
* Update Unnamed jars and include descriptor files. |
36511 | 317 |
*/ |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
318 |
private static void generateJar(Path sjar, Path djar, |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
319 |
ModuleDescriptor mDesc, boolean metaDesc) throws Exception { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
320 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
321 |
Files.copy(sjar, djar, StandardCopyOption.REPLACE_EXISTING); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
322 |
Path dir = Files.createTempDirectory("tmp"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
323 |
if (metaDesc) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
324 |
write(dir.resolve(Paths.get("META-INF", "services", |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
325 |
"java.security.Provider")), P_TYPE); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
326 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
327 |
if (mDesc != null) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
328 |
Path mi = dir.resolve("module-info.class"); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
329 |
try (OutputStream out = Files.newOutputStream(mi)) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
330 |
ModuleInfoWriter.write(mDesc, out); |
36511 | 331 |
} |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
332 |
System.out.format("Added 'module-info.class' in '%s'%n", djar); |
36511 | 333 |
} |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
334 |
JarUtils.updateJarFile(djar, dir); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
335 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
336 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
337 |
/** |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
338 |
* Look for file path in generated jars. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
339 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
340 |
private static Path artifact(String file) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
341 |
return ARTIFACT_DIR.resolve(file); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
342 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
343 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
344 |
/** |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
345 |
* Convert to absolute file path. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
346 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
347 |
private static String toAbsPath(Path path) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
348 |
return path.toFile().getAbsolutePath(); |
36511 | 349 |
} |
350 |
||
351 |
/** |
|
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
352 |
* Create the parent directories if missing to ensure the path exist. |
36511 | 353 |
*/ |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
354 |
private static Path ensurePath(Path at) throws IOException { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
355 |
Path parent = at.getParent(); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
356 |
if (parent != null && !parent.toFile().exists()) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
357 |
ensurePath(parent); |
39774
25d5618feb3c
8151654: Additional modular test for "auth.login.defaultCallbackHandler"
ssahoo
parents:
36511
diff
changeset
|
358 |
} |
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
359 |
return Files.createDirectories(parent); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
360 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
361 |
|
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
362 |
/** |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
363 |
* Generates service descriptor inside META-INF folder. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
364 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
365 |
private static void write(Path at, String content) throws IOException { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
366 |
ensurePath(at); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
367 |
Files.write(at, content.getBytes("UTF-8")); |
36511 | 368 |
} |
369 |
||
46898
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
370 |
/** |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
371 |
* Create new provider entry through java.security file extension. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
372 |
* New provider entry will be the last entry inside the JRE. |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
373 |
*/ |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
374 |
private static void createJavaSecurityFileExtn(boolean useName) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
375 |
int insertAt = Security.getProviders().length + 1; |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
376 |
String provider = (useName ? "TestProvider" : P_TYPE); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
377 |
try { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
378 |
Files.write(SEC_FILE, String.format("security.provider.%s=%s", |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
379 |
insertAt, provider).getBytes("UTF-8")); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
380 |
} catch (IOException e) { |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
381 |
throw new RuntimeException(e); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
382 |
} |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
383 |
System.out.printf("Security property file created at: %s with value:" |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
384 |
+ " %s%n", SEC_FILE, provider); |
4d2a6afafb76
8183310: java/security/modules/ModularTest.java should clean up better
ssahoo
parents:
45393
diff
changeset
|
385 |
} |
36511 | 386 |
} |