Skip to content

Commit 81b5b80

Browse files
committed
The root cause of the CI failure was that the old code's SSLContext.setDefault() silently weakened TLS for the entire JVM, and the
test's readContent was unknowingly piggy-backing on that global relaxation. After the hardening fix, readContent now does its own per-connection trust-all + hostname-verifier override (same pattern as the production fix), so the test no longer depends on JVM-wide state. This also makes the test an implicit regression guard: if someone reintroduces SSLContext.setDefault() in the reporter, nothing in the test relies on it.
1 parent 5aa8698 commit 81b5b80

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

external/storm-metrics-prometheus/src/test/java/org/apache/storm/metrics/prometheus/PrometheusPreparableReporterTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
import org.testcontainers.junit.jupiter.Testcontainers;
2323
import org.testcontainers.utility.MountableFile;
2424

25+
import javax.net.ssl.HttpsURLConnection;
26+
import javax.net.ssl.SSLContext;
27+
import javax.net.ssl.TrustManager;
28+
import javax.net.ssl.X509TrustManager;
2529
import java.io.BufferedReader;
2630
import java.io.IOException;
2731
import java.io.InputStreamReader;
2832
import java.net.HttpURLConnection;
2933
import java.net.URL;
34+
import java.security.GeneralSecurityException;
35+
import java.security.cert.X509Certificate;
3036
import java.util.Arrays;
3137
import java.util.Base64;
3238
import java.util.HashSet;
@@ -163,6 +169,31 @@ private void assertMetrics(List<String> elements, String endpoint, Map<String, O
163169
private String readContent(String url, Map<String, Object> conf) throws IOException {
164170
final URL obj = new URL(url);
165171
final HttpURLConnection con = (HttpURLConnection) obj.openConnection();
172+
if (con instanceof HttpsURLConnection) {
173+
// The test PushGateway uses a self-signed certificate. Scope the trust-all
174+
// SSLContext to this connection only, so we do not mutate JVM-wide TLS state.
175+
try {
176+
final SSLContext sslContext = SSLContext.getInstance("TLS");
177+
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
178+
@Override
179+
public X509Certificate[] getAcceptedIssuers() {
180+
return new X509Certificate[0];
181+
}
182+
183+
@Override
184+
public void checkClientTrusted(X509Certificate[] chain, String authType) {
185+
}
186+
187+
@Override
188+
public void checkServerTrusted(X509Certificate[] chain, String authType) {
189+
}
190+
}}, null);
191+
((HttpsURLConnection) con).setSSLSocketFactory(sslContext.getSocketFactory());
192+
((HttpsURLConnection) con).setHostnameVerifier((h, s) -> true);
193+
} catch (GeneralSecurityException e) {
194+
throw new IOException(e);
195+
}
196+
}
166197
con.setRequestMethod("GET");
167198

168199
if (conf.containsKey("storm.daemon.metrics.reporter.plugin.prometheus.basic_auth_user")) {

0 commit comments

Comments
 (0)