Skip to content

Commit

Permalink
8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest…
Browse files Browse the repository at this point in the history
….sh to jtreg java test

Reviewed-by: dfuchs, smarks
  • Loading branch information
mpdonova authored and Stuart Marks committed Mar 6, 2023
1 parent cfb0a25 commit ccfe167
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 204 deletions.
237 changes: 89 additions & 148 deletions test/jdk/javax/rmi/ssl/SSLSocketParametersTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -21,6 +21,18 @@
* questions.
*/

/*
* @test
* @bug 5016500
* @summary Test SslRmi[Client|Server]SocketFactory SSL socket parameters.
* @run main/othervm SSLSocketParametersTest 1
* @run main/othervm SSLSocketParametersTest 2
* @run main/othervm SSLSocketParametersTest 3
* @run main/othervm SSLSocketParametersTest 4
* @run main/othervm SSLSocketParametersTest 5
* @run main/othervm SSLSocketParametersTest 6
* @run main/othervm SSLSocketParametersTest 7
*/
import java.io.IOException;
import java.io.File;
import java.io.Serializable;
Expand Down Expand Up @@ -77,7 +89,7 @@ public void runClient(Remote stub) throws IOException {
}
}

public class ClientFactory extends SslRMIClientSocketFactory {
public static class ClientFactory extends SslRMIClientSocketFactory {

public ClientFactory() {
super();
Expand All @@ -90,7 +102,7 @@ public Socket createSocket(String host, int port) throws IOException {
}
}

public class ServerFactory extends SslRMIServerSocketFactory {
public static class ServerFactory extends SslRMIServerSocketFactory {

public ServerFactory() {
super();
Expand All @@ -116,174 +128,103 @@ public ServerSocket createServerSocket(int port) throws IOException {
}
}

public void runTest(String[] args) {

int test = Integer.parseInt(args[0]);

String msg1 = "Running SSLSocketParametersTest [" + test + "]";
String msg2 = "SSLSocketParametersTest [" + test + "] PASSED!";
String msg3 = "SSLSocketParametersTest [" + test + "] FAILED!";

switch (test) {
case 1: /* default constructor - default config */
System.out.println(msg1);
try {
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory());
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg2);
} catch (Exception e) {
System.out.println(msg3 + " Exception: " + e.toString());
e.printStackTrace(System.out);
System.exit(1);
}
break;
case 2: /* non-default constructor - default config */
System.out.println(msg1);
try {
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory(null,
null,
false));
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg2);
} catch (Exception e) {
System.out.println(msg3 + " Exception: " + e.toString());
e.printStackTrace(System.out);
System.exit(1);
public void testRmiCommunication(RMIServerSocketFactory serverFactory, boolean expectException) {

HelloImpl server = null;
try {
server = new HelloImpl(0,
new ClientFactory(),
serverFactory);
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
if (expectException) {
throw new RuntimeException("Test completed without throwing an expected exception.");
}
break;
case 3: /* needClientAuth=true */
System.out.println(msg1);
try {
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory(null,
null,
null,
true));
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg2);
} catch (Exception e) {
System.out.println(msg3 + " Exception: " + e.toString());
e.printStackTrace(System.out);
System.exit(1);
}
break;
case 4: /* server side dummy_ciphersuite */
System.out.println(msg1);
try {
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory(SSLContext.getDefault(),
new String[] {"dummy_ciphersuite"},
null,
false));
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg3);
System.exit(1);
} catch (Exception e) {
System.out.println(msg2 + " Exception: " + e.toString());
System.exit(0);

} catch (IOException exc) {
if (!expectException) {
throw new RuntimeException("An error occurred during test execution", exc);
} else {
System.out.println("Caught expected exception: " + exc);
}
break;
case 5: /* server side dummy_protocol */
System.out.println(msg1);
try {
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory(null,
new String[] {"dummy_protocol"},
false));
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg3);
System.exit(1);
} catch (Exception e) {
System.out.println(msg2 + " Exception: " + e.toString());
System.exit(0);

}
}

private static void testServerFactory(String[] cipherSuites, String[] protocol, String expectedMessage) throws Exception {
try {
new ServerFactory(SSLContext.getDefault(),
cipherSuites, protocol, false);
throw new RuntimeException(
"The expected exception for "+ expectedMessage + " was not thrown.");
} catch (IllegalArgumentException exc) {
// expecting an exception with a specific message
// anything else is an error
if (!exc.getMessage().toLowerCase().contains(expectedMessage)) {
throw exc;
}
break;
case 6: /* client side dummy_ciphersuite */
System.out.println(msg1);
try {
}
}

public void runTest(int testNumber) throws Exception {
System.out.println("Running test " + testNumber);

switch (testNumber) {
/* default constructor - default config */
case 1 -> testRmiCommunication(new ServerFactory(), false);

/* non-default constructor - default config */
case 2 -> testRmiCommunication(new ServerFactory(null, null, false), false);

/* needClientAuth=true */
case 3 -> testRmiCommunication(new ServerFactory(null, null, null, true), false);

/* server side dummy_ciphersuite */
case 4 ->
testServerFactory(new String[]{"dummy_ciphersuite"}, null, "unsupported ciphersuite");

/* server side dummy_protocol */
case 5 ->
testServerFactory(null, new String[]{"dummy_protocol"}, "unsupported protocol");

/* client side dummy_ciphersuite */
case 6 -> {
System.setProperty("javax.rmi.ssl.client.enabledCipherSuites",
"dummy_ciphersuite");
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory());
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg3);
System.exit(1);
} catch (Exception e) {
System.out.println(msg2 + " Exception: " + e.toString());
System.exit(0);
"dummy_ciphersuite");
testRmiCommunication(new ServerFactory(), true);
}
break;
case 7: /* client side dummy_protocol */
System.out.println(msg1);
try {

/* client side dummy_protocol */
case 7 -> {
System.setProperty("javax.rmi.ssl.client.enabledProtocols",
"dummy_protocol");
HelloImpl server = new HelloImpl(
0,
new ClientFactory(),
new ServerFactory());
Remote stub = server.runServer();
HelloClient client = new HelloClient();
client.runClient(stub);
System.out.println(msg3);
System.exit(1);
} catch (Exception e) {
System.out.println(msg2 + " Exception: " + e.toString());
System.exit(0);
"dummy_protocol");
testRmiCommunication(new ServerFactory(), true);
}
break;
default:
throw new IllegalArgumentException("invalid test number");

default ->
throw new RuntimeException("Unknown test number: " + testNumber);
}
}

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
// Set keystore properties (server-side)
//
final String keystore = System.getProperty("test.src") +
File.separator + "keystore";
File.separator + "keystore";
System.out.println("KeyStore = " + keystore);
System.setProperty("javax.net.ssl.keyStore", keystore);
System.setProperty("javax.net.ssl.keyStorePassword", "password");

// Set truststore properties (client-side)
//
final String truststore = System.getProperty("test.src") +
File.separator + "truststore";
File.separator + "truststore";
System.out.println("TrustStore = " + truststore);
System.setProperty("javax.net.ssl.trustStore", truststore);
System.setProperty("javax.net.ssl.trustStorePassword", "trustword");

// Run test
//
SSLSocketParametersTest test = new SSLSocketParametersTest();
test.runTest(args);
System.exit(0);
test.runTest(Integer.parseInt(args[0]));
}
}
}
56 changes: 0 additions & 56 deletions test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh

This file was deleted.

3 comments on commit ccfe167

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on ccfe167 Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on ccfe167 Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-ccfe1675 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit ccfe1675 from the openjdk/jdk repository.

The commit being backported was authored by Matthew Donovan on 6 Mar 2023 and was reviewed by Daniel Fuchs and Stuart Marks.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-ccfe1675:backport-GoeLin-ccfe1675
$ git checkout backport-GoeLin-ccfe1675
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-ccfe1675

Please sign in to comment.