Skip to content

Commit

Permalink
8305169: java/security/cert/CertPathValidator/OCSP/GetAndPostTests.ja…
Browse files Browse the repository at this point in the history
…va -- test server didn't start in timely manner

Reviewed-by: ssahoo, jnimeh
  • Loading branch information
mpdonova authored and Jamil Nimeh committed May 5, 2023
1 parent f143bf7 commit 3f6a354
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

import sun.security.testlibrary.SimpleOCSPServer;
import sun.security.testlibrary.SimpleOCSPServer;
import sun.security.testlibrary.SimpleOCSPServer;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
import sun.security.util.ObjectIdentifier;
import sun.security.testlibrary.SimpleOCSPServer;

public class GetAndPostTests {
private static final String PASS = "passphrase";
private static final int SERVER_WAIT_SECS = 60;
private static CertificateFactory certFac;

public static void main(String args[]) throws Exception {
Expand Down Expand Up @@ -114,13 +112,8 @@ public static void main(String args[]) throws Exception {
endEntCert.getSerialNumber(),
new SimpleOCSPServer.CertStatusInfo(
SimpleOCSPServer.CertStatus.CERT_STATUS_GOOD)));
ocspResponder.start();
// Wait 5 seconds for server ready
boolean readyStatus =
ocspResponder.awaitServerReady(5, TimeUnit.SECONDS);
if (!readyStatus) {
throw new RuntimeException("Server not ready");
}

startOcspServer(ocspResponder);

int ocspPort = ocspResponder.getPort();
URI ocspURI = new URI("http://localhost:" + ocspPort);
Expand Down Expand Up @@ -169,6 +162,14 @@ public static void main(String args[]) throws Exception {
}
}

private static void startOcspServer(SimpleOCSPServer ocspResponder) throws InterruptedException, IOException {
ocspResponder.start();
if (!ocspResponder.awaitServerReady(SERVER_WAIT_SECS, TimeUnit.SECONDS)) {
throw new RuntimeException("Server not ready after " + SERVER_WAIT_SECS
+ " seconds.");
}
}

/**
* Create an X509Certificate object from its PEM encoding
*
Expand Down
10 changes: 9 additions & 1 deletion test/jdk/java/security/testlibrary/SimpleOCSPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,18 @@ public synchronized void acceptConnections() {
public synchronized void stop() {
if (started) {
receivedShutdown = true;
started = false;
log("Received shutdown notification");
}
}

public synchronized void shutdownNow() {
stop();
if (threadPool != null) {
threadPool.shutdownNow();
}
}

/**
* Print {@code SimpleOCSPServer} operating parameters.
*
Expand Down Expand Up @@ -577,7 +585,7 @@ private synchronized void log(String message) {
* @param message the message to log
*/
private static synchronized void err(String message) {
System.out.println("[" + Thread.currentThread().getName() + "]: " +
System.err.println("[" + Thread.currentThread().getName() + "]: " +
message);
}

Expand Down

3 comments on commit 3f6a354

@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 3f6a354 Mar 20, 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 3f6a354 Mar 20, 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-3f6a3545 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 3f6a3545 from the openjdk/jdk repository.

The commit being backported was authored by Matthew Donovan on 5 May 2023 and was reviewed by Sibabrata Sahoo and Jamil Nimeh.

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-3f6a3545:backport-GoeLin-3f6a3545
$ git checkout backport-GoeLin-3f6a3545
# 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-3f6a3545

Please sign in to comment.