Skip to content

Commit 53e7772

Browse files
author
arjan
committed
Set TLS to v1.2 for the EE 7 tests for now.
Added auto-discovery of domain for Payara and GlassFish
1 parent 74f5146 commit 53e7772

File tree

5 files changed

+66
-9
lines changed

5 files changed

+66
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
<dependency>
220220
<groupId>net.sourceforge.htmlunit</groupId>
221221
<artifactId>htmlunit</artifactId>
222-
<version>2.33</version>
222+
<version>2.34.0</version>
223223
<scope>test</scope>
224224
</dependency>
225225
<dependency>

servlet/security-clientcert-jce/src/test/java/org/javaee7/servlet/security/clientcert/jce/SecureServletTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public static WebArchive createDeployment() throws FileNotFoundException, IOExce
101101
// Create a new local key store containing the client private key and the certificate
102102
clientKeyStorePath = createTempJKSKeyStore(clientKeyPair.getPrivate(), clientCertificate);
103103

104+
// Only test TLS v1.2 for now
105+
System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
106+
104107
// Enable to get detailed logging about the SSL handshake on the server
105108

106109
if (System.getProperty("ssl.debug") != null) {

servlet/security-clientcert/src/test/java/org/javaee7/servlet/security/clientcert/SecureServletTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public static WebArchive createDeployment() throws FileNotFoundException, IOExce
102102
System.out.println("Setting server SSL debug on");
103103
addContainerSystemProperty("javax.net.debug", "ssl:handshake");
104104
}
105+
106+
// Only test TLS v1.2 for now
107+
System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
105108

106109
// Add the client certificate that we just generated to the trust store of the server.
107110
// That way the server will trust our certificate.

test-utils/src/main/java/org/javaee7/CliCommands.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public class CliCommands {
2121

2222
private static final Logger logger = Logger.getLogger(CliCommands.class.getName());
2323
private static final String OS = System.getProperty("os.name").toLowerCase();
24-
24+
2525
public static int payaraGlassFish(List<String> cliCommands) {
26+
return payaraGlassFish(cliCommands, null);
27+
}
28+
29+
public static int payaraGlassFish(List<String> cliCommands, List<String> output) {
2630

2731
String gfHome = System.getProperty("glassfishRemote_gfHome");
2832
if (gfHome == null) {
@@ -60,6 +64,7 @@ public static int payaraGlassFish(List<String> cliCommands) {
6064
return
6165
waitToFinish(
6266
readAllInput(
67+
output,
6368
destroyAtShutDown(
6469
processBuilder.start())));
6570
} catch (IOException e) {
@@ -86,11 +91,15 @@ public void run() {
8691
return process;
8792
}
8893

89-
public static Process readAllInput(Process process) {
94+
public static Process readAllInput(List<String> output, Process process) {
9095
// Read any output from the process
9196
try (Scanner scanner = new Scanner(process.getInputStream())) {
9297
while (scanner.hasNextLine()) {
93-
System.out.println(scanner.nextLine());
98+
String nextLine = scanner.nextLine();
99+
System.out.println(nextLine);
100+
if (output != null) {
101+
output.add(nextLine);
102+
}
94103
}
95104
}
96105

test-utils/src/main/java/org/javaee7/ServerOperations.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ public static void addCertificateToContainerTrustStore(Certificate clientCertifi
9191
logger.severe("glassfishRemote_gfHome at " + gfHome + " is not a directory");
9292
return;
9393
}
94-
95-
// TODO: support current domain
94+
9695
String domain = System.getProperty("payara_domain", "domain1");
96+
if (domain != null) {
97+
domain = getPayaraDomainFromServer();
98+
logger.info("Using domain \"" + domain + "\" obtained from server. If this is not correct use -Dpayara_domain to override.");
99+
}
97100

98101
Path cacertsPath = gfHomePath.resolve("glassfish/domains/" + domain + "/config/cacerts.jks");
99102

@@ -116,6 +119,8 @@ public static void addCertificateToContainerTrustStore(Certificate clientCertifi
116119
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) {
117120
throw new IllegalStateException(e);
118121
}
122+
123+
restartContainer(domain);
119124
} else {
120125
if (javaEEServer == null) {
121126
System.out.println("javaEEServer not specified");
@@ -124,7 +129,6 @@ public static void addCertificateToContainerTrustStore(Certificate clientCertifi
124129
}
125130
}
126131

127-
restartContainer();
128132
}
129133

130134
public static URL toContainerHttps(URL url) {
@@ -167,6 +171,31 @@ public static URL toContainerHttps(URL url) {
167171
return null;
168172
}
169173

174+
private static String getPayaraDomainFromServer() {
175+
System.out.println("Getting Payara domaain from server");
176+
177+
List<String> output = new ArrayList<>();
178+
List<String> cmd = new ArrayList<>();
179+
180+
cmd.add("list-domains");
181+
182+
CliCommands.payaraGlassFish(cmd, output);
183+
184+
String domain = null;
185+
for (String line : output) {
186+
if (line.contains(" not running")) {
187+
continue;
188+
}
189+
190+
if (line.endsWith(" running")) {
191+
domain = line.substring(0, line.lastIndexOf(" running"));
192+
break;
193+
}
194+
}
195+
196+
return domain;
197+
}
198+
170199
public static void addContainerSystemProperty(String key, String value) {
171200
String javaEEServer = System.getProperty("javaEEServer");
172201

@@ -177,7 +206,7 @@ public static void addContainerSystemProperty(String key, String value) {
177206
List<String> cmd = new ArrayList<>();
178207

179208
cmd.add("create-jvm-options");
180-
cmd.add("-D" + key + "=" + value);
209+
cmd.add("-D" + key + "=\"" + value + "\"");
181210

182211
CliCommands.payaraGlassFish(cmd);
183212

@@ -191,6 +220,10 @@ public static void addContainerSystemProperty(String key, String value) {
191220
}
192221

193222
public static void restartContainer() {
223+
restartContainer(null);
224+
}
225+
226+
public static void restartContainer(String domain) {
194227
// Arquillian connectors can stop/start already, but not on demand by code
195228

196229
String javaEEServer = System.getProperty("javaEEServer");
@@ -203,7 +236,16 @@ public static void restartContainer() {
203236

204237
cmd.add("restart-domain");
205238

206-
cmd.add(System.getProperty("payara_domain", "domain1"));
239+
String restartDomain = domain;
240+
if (restartDomain == null) {
241+
restartDomain = System.getProperty("payara_domain");
242+
}
243+
244+
if (restartDomain == null) {
245+
restartDomain = getPayaraDomainFromServer();
246+
}
247+
248+
cmd.add(restartDomain);
207249

208250
CliCommands.payaraGlassFish(cmd);
209251

0 commit comments

Comments
 (0)