Skip to content

Commit

Permalink
Replace SSLContext by SSLSocketFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Oct 8, 2024
1 parent 2c2e321 commit a9929e7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -217,7 +217,7 @@ public final class RealJenkinsRule implements TestRule {

private final PrefixedOutputStream.Builder prefixedOutputStreamBuilder = PrefixedOutputStream.builder();
@CheckForNull
private SSLContext sslContext;
private SSLSocketFactory sslSocketFactory;

public RealJenkinsRule() {
home = new AtomicReference<>();
Expand Down Expand Up @@ -735,11 +735,11 @@ public URL getUrl() throws MalformedURLException {
if (port == 0) {
throw new IllegalStateException("This method must be called after calling #startJenkins.");
}
return new URL(sslContext != null ? "https" : "http", host, port, "/jenkins/");
return new URL(sslSocketFactory != null ? "https" : "http", host, port, "/jenkins/");
}

public RealJenkinsRule https(File keyStoreFile, String keyStorePassword, SSLContext sslContext) {
this.sslContext = sslContext;
public RealJenkinsRule https(File keyStoreFile, String keyStorePassword, SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
this.jenkinsOptions(
"--httpsKeyStore=" + keyStoreFile.getAbsolutePath(),
"--httpsKeyStorePassword=" + keyStorePassword);
Expand Down Expand Up @@ -908,7 +908,7 @@ public void startJenkins() throws Throwable {

private Collection<String> getPortOptions() {
// Initially port=0. On subsequent runs, this is set to the port allocated randomly on the first run.
if (sslContext != null) {
if (sslSocketFactory != null) {
return List.of("--httpPort=-1", "--httpsPort=" + port);
} else {
return List.of("--httpPort=" + port);
Expand Down Expand Up @@ -1046,8 +1046,8 @@ public <T extends Serializable> T runRemotely(Step2<T> s) throws Throwable {
}

private HttpURLConnection decorateConnection(@NonNull URLConnection urlConnection) {
if (sslContext != null) {
((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslContext.getSocketFactory());
if (sslSocketFactory != null) {
((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslSocketFactory);
}
return (HttpURLConnection) urlConnection;
}
Expand Down

0 comments on commit a9929e7

Please sign in to comment.