Skip to content

Commit 5738695

Browse files
committed
Refactor: rename dummy subclases
1 parent bca629c commit 5738695

File tree

4 files changed

+81
-104
lines changed

4 files changed

+81
-104
lines changed

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/DummyImplementations.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
package org.elasticsearch.entitlement.qa.common;
1111

12+
import java.net.InetAddress;
13+
import java.net.Socket;
14+
import java.security.cert.Certificate;
1215
import java.text.BreakIterator;
1316
import java.text.Collator;
1417
import java.text.DateFormat;
@@ -30,6 +33,9 @@
3033
import java.util.spi.LocaleServiceProvider;
3134
import java.util.spi.TimeZoneNameProvider;
3235

36+
import javax.net.ssl.HttpsURLConnection;
37+
import javax.net.ssl.SSLSocketFactory;
38+
3339
/**
3440
* A collection of concrete subclasses that we can instantiate but that don't actually work.
3541
* <p>
@@ -248,6 +254,79 @@ public Locale[] getAvailableLocales() {
248254
}
249255
}
250256

257+
static class DummyHttpsURLConnection extends HttpsURLConnection {
258+
DummyHttpsURLConnection() {
259+
super(null);
260+
}
261+
262+
@Override
263+
public void connect() {
264+
throw unexpected();
265+
}
266+
267+
@Override
268+
public void disconnect() {
269+
throw unexpected();
270+
}
271+
272+
@Override
273+
public boolean usingProxy() {
274+
throw unexpected();
275+
}
276+
277+
@Override
278+
public String getCipherSuite() {
279+
throw unexpected();
280+
}
281+
282+
@Override
283+
public Certificate[] getLocalCertificates() {
284+
throw unexpected();
285+
}
286+
287+
@Override
288+
public Certificate[] getServerCertificates() {
289+
throw unexpected();
290+
}
291+
}
292+
293+
static class DummySSLSocketFactory extends SSLSocketFactory {
294+
@Override
295+
public Socket createSocket(String host, int port) {
296+
throw unexpected();
297+
}
298+
299+
@Override
300+
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) {
301+
throw unexpected();
302+
}
303+
304+
@Override
305+
public Socket createSocket(InetAddress host, int port) {
306+
throw unexpected();
307+
}
308+
309+
@Override
310+
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) {
311+
throw unexpected();
312+
}
313+
314+
@Override
315+
public String[] getDefaultCipherSuites() {
316+
throw unexpected();
317+
}
318+
319+
@Override
320+
public String[] getSupportedCipherSuites() {
321+
throw unexpected();
322+
}
323+
324+
@Override
325+
public Socket createSocket(Socket s, String host, int port, boolean autoClose) {
326+
throw unexpected();
327+
}
328+
}
329+
251330
private static RuntimeException unexpected() {
252331
return new IllegalStateException("This method isn't supposed to be called");
253332
}

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/RestEntitlementsCheckAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static void setDefaultHostnameVerifier() {
140140
}
141141

142142
private static void setDefaultSSLSocketFactory() {
143-
HttpsURLConnection.setDefaultSSLSocketFactory(new TestSSLSocketFactory());
143+
HttpsURLConnection.setDefaultSSLSocketFactory(new DummyImplementations.DummySSLSocketFactory());
144144
}
145145

146146
@SuppressForbidden(reason = "Specifically testing Runtime.exit")
@@ -178,7 +178,7 @@ private static void processBuilder_startPipeline() {
178178
}
179179

180180
private static void setHttpsConnectionProperties() {
181-
new TestHttpsURLConnection().setSSLSocketFactory(new TestSSLSocketFactory());
181+
new DummyImplementations.DummyHttpsURLConnection().setSSLSocketFactory(new DummyImplementations.DummySSLSocketFactory());
182182
}
183183

184184
private static void system$$setIn() {

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/TestHttpsURLConnection.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

libs/entitlement/qa/common/src/main/java/org/elasticsearch/entitlement/qa/common/TestSSLSocketFactory.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)