Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to verify JITServer with SSL #18262

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<suite id="jitserverArgumentTesting.xml" timeout="1000">
<variable name="ENABLE_JITSERVER" value="-XX:+UseJITServer" />
<variable name="DISABLE_JITSERVER" value="-XX:-UseJITServer" />
<variable name="JITSERVER_SSL1" value="-XX:JITServerSSLRootCerts=cert.pem" />
<variable name="JITSERVER_SSL2" value="-XX:JITServerSSLRootCerts=wrongCert.pem" />
<variable name="JITSERVER_SSL3" value="-XX:JITServerSSLRootCerts=nosslserverCert.pem" />
<variable name="JITSERVER_VERBOSE" value="-Xjit:verbose={JITServer},verbose={JITServerConns},verbose={compilePerformance}" />
<variable name="DEFAULT_JITSERVER_OPTIONS" value="-Xjit" />

Expand Down Expand Up @@ -89,4 +92,45 @@
<output type="failure" caseSensitive="yes" regex="no">JITSERVER NO LONGER EXISTS</output>
</test>

<test id="Test SSL success condition">
<command>bash $SCRIPPATH$ $TEST_RESROOT$ $TEST_JDK_BIN$ "$DEFAULT_JITSERVER_OPTIONS$" "$ENABLE_JITSERVER$ $JITSERVER_VERBOSE$ $JITSERVER_SSL1$" false</command>
<output type="success" caseSensitive="no" regex="yes" javaUtilPattern="yes">(java|openjdk|semeru) version</output>
<output type="required" caseSensitive="no" regex="no">JITServer Client Mode.</output>
<output type="success" caseSensitive="no" regex="no">Successfully initialized SSL context</output>
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember discussing that the test succeeds when any of the type="success" criteria is met.
If that is the case, then "Successfully initialized SSL context" is sufficient to make the test pass, but in reality that is not enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test we can make that condition type="required" for "Successfully initialized SSL context" which will enforce the test to look for this condition and make the test pass only if the condition is met.
However the test will only search for the condition "Successfully initialized SSL context" in the output of the test which includes logs from the server and the client and the test will pass if either client or server logs contain the text.

I can remove the -Xjit:verbose={JITServer} from the server side to avoid checking the logs from the server and change few conditions in the test which currently expects server side logs.

Or a better way might be to make the condition JITServer::StreamFailure: Failed to SSL_connect as required condition in the failure scenario and for success scenario make the Connected to a server as required condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed the server side verbose logging and modified the conditions to check if the connection was success/failure (based on the test criteria) as a required condition.

<output type="success" caseSensitive="no" regex="no">SSL connection on socket</output>
<output type="required" caseSensitive="no" regex="no">Connected to a server</output>
<output type="failure" caseSensitive="no" regex="yes" javaUtilPattern="yes">(Fatal|Unhandled) Exception</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER EXISTS</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER STILL EXISTS</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER DOES NOT EXIST</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER NO LONGER EXISTS</output>
</test>

<test id="Test SSL Failure Case with mismatched certificate">
<command>bash $SCRIPPATH$ $TEST_RESROOT$ $TEST_JDK_BIN$ "$DEFAULT_JITSERVER_OPTIONS$" "$ENABLE_JITSERVER$ $JITSERVER_VERBOSE$ $JITSERVER_SSL2$" false</command>
<output type="success" caseSensitive="no" regex="yes" javaUtilPattern="yes">(java|openjdk|semeru) version</output>
<output type="required" caseSensitive="no" regex="no">JITServer Client Mode.</output>
<output type="success" caseSensitive="no" regex="no">Successfully initialized SSL context</output>
<output type="required" caseSensitive="no" regex="no">JITServer::StreamFailure: Failed to SSL_connect</output>
<output type="failure" caseSensitive="no" regex="no">Connected to a server</output>
<output type="failure" caseSensitive="no" regex="yes" javaUtilPattern="yes">(Fatal|Unhandled) Exception</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER EXISTS</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER STILL EXISTS</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER DOES NOT EXIST</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER NO LONGER EXISTS</output>
</test>

<test id="Test SSL Failure Case with connection to Non-SSL Server">
<command>bash $SCRIPPATH$ $TEST_RESROOT$ $TEST_JDK_BIN$ "$DEFAULT_JITSERVER_OPTIONS$" "$ENABLE_JITSERVER$ $JITSERVER_VERBOSE$ $JITSERVER_SSL3$" false</command>
<output type="success" caseSensitive="no" regex="yes" javaUtilPattern="yes">(java|openjdk|semeru) version</output>
<output type="required" caseSensitive="no" regex="no">JITServer Client Mode.</output>
<output type="success" caseSensitive="no" regex="no">Successfully initialized SSL context</output>
<output type="required" caseSensitive="no" regex="no">JITServer::StreamFailure: Failed to SSL_connect</output>
<output type="failure" caseSensitive="no" regex="no">Connected to a server</output>
<output type="failure" caseSensitive="no" regex="yes" javaUtilPattern="yes">(Fatal|Unhandled) Exception</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER EXISTS</output>
<output type="success" caseSensitive="yes" regex="no">JITSERVER STILL EXISTS</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER DOES NOT EXIST</output>
<output type="failure" caseSensitive="yes" regex="no">JITSERVER NO LONGER EXISTS</output>
</test>
</suite>
17 changes: 16 additions & 1 deletion test/functional/cmdLineTests/jitserver/jitserverScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ source $TEST_ROOT/jitserverconfig.sh

JITSERVER_PORT=$(random_port)

JITSERVER_SSL="-XX:JITServerSSLRootCerts"

if grep -q -- "$JITSERVER_SSL" <<< "$JVM_OPTS"; then
echo "Generate SSL certificates"
source $TEST_ROOT/jitserversslconfig.sh
if ! grep -q "nosslserverCert.pem" <<< "$JVM_OPTS"; then
SSL_OPTS="-XX:JITServerSSLKey=key.pem -XX:JITServerSSLCert=cert.pem"
fi
fi

if [ "$METRICS" == true ]; then
METRICS_PORT=$(random_port)
METRICS_OPTS="-XX:+JITServerMetrics -XX:JITServerMetricsPort=$METRICS_PORT"
fi

JITSERVER_OPTIONS="-XX:JITServerPort=$JITSERVER_PORT $METRICS_OPTS $JITSERVER_OPTS"
JITSERVER_OPTIONS="-XX:JITServerPort=$JITSERVER_PORT $METRICS_OPTS $JITSERVER_OPTS $SSL_OPTS"

echo "Starting $TEST_JDK_BIN/jitserver $JITSERVER_OPTIONS"
$TEST_JDK_BIN/jitserver $JITSERVER_OPTIONS &
Expand Down Expand Up @@ -77,6 +87,11 @@ if [ "$JITSERVER_EXISTS" == 0 ]; then
# Running pkill seems to cause a hang...
#pkill -9 -xf "$TEST_JDK_BIN/jitserver $JITSERVER_OPTIONS"
sleep 2

if grep -q "nosslserverCert.pem" <<< "$JVM_OPTS"; then
rm -f *.pem
fi

else
echo "JITSERVER DOES NOT EXIST"
fi
Expand Down
42 changes: 42 additions & 0 deletions test/functional/cmdLineTests/jitserver/jitserversslconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

#
# Copyright IBM Corp. and others 2023
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
# or the Apache License, Version 2.0 which accompanies this distribution and
# is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following
# Secondary Licenses when the conditions for such availability set
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
# General Public License, version 2 with the GNU Classpath
# Exception [1] and GNU General Public License, version 2 with the
# OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] https://openjdk.org/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
#

echo "Creating SSL certificates";

COMMON_NAME="localhost"
VALID_DAYS=365

# Generate private key
openssl genrsa -out key.pem 2048

# Generate self-signed certificate
openssl req -new -x509 -sha256 -key key.pem -out cert.pem -days $VALID_DAYS -subj "/CN=$COMMON_NAME"

# Generate another private key and self-signed certificate
openssl req -nodes -newkey rsa:2048 -keyout wrongKey.pem -x509 -days 365 -out wrongCert.pem -subj "/CN=localhost"

# Generate another self-signed certificate
openssl req -new -x509 -sha256 -key key.pem -out nosslserverCert.pem -days $VALID_DAYS -subj "/CN=$COMMON_NAME"

echo "Certificates generated";