@@ -289,6 +289,67 @@ public void testWithSystemTrustStore() {
289289 }
290290 }
291291
292+ @ Test
293+ public void testDirectConnectionSystemTrustStoreFallback () {
294+ System .out .println (
295+ "Scenario: UseSystemTrustStore=1 with no system property -> fallback to cacerts (direct)" );
296+
297+ // ensure the property is *unset* for this test run
298+ String savedProp = System .getProperty ("javax.net.ssl.trustStore" );
299+ try {
300+ System .clearProperty ("javax.net.ssl.trustStore" );
301+
302+ for (boolean thrift : new boolean [] {true , false }) {
303+ String url = buildJdbcUrl (thrift , false , false , false , true , false );
304+ try {
305+ verifyConnect (url );
306+ } catch (Exception e ) {
307+ fail (
308+ "Fallback‑to‑cacerts direct connect failed (thrift="
309+ + thrift
310+ + "): "
311+ + e .getMessage ());
312+ }
313+ }
314+ } finally {
315+ // restore original system state
316+ if (savedProp != null ) {
317+ System .setProperty ("javax.net.ssl.trustStore" , savedProp );
318+ }
319+ }
320+ }
321+
322+ @ Test
323+ public void testIgnoreSystemPropertyWhenUseSystemTrustStoreDisabled () {
324+ System .out .println (
325+ "Scenario: bogus javax.net.ssl.trustStore present but UseSystemTrustStore=0 (driver must ignore)" );
326+
327+ String savedProp = System .getProperty ("javax.net.ssl.trustStore" );
328+ try {
329+ System .setProperty ("javax.net.ssl.trustStore" , "/path/that/does/not/exist.jks" );
330+
331+ for (boolean thrift : new boolean [] {true , false }) {
332+ String url = buildJdbcUrl (thrift , false , false , false , false , false );
333+ try {
334+ verifyConnect (url );
335+ } catch (Exception e ) {
336+ fail (
337+ "Driver failed to ignore bogus system trust store (thrift="
338+ + thrift
339+ + "): "
340+ + e .getMessage ());
341+ }
342+ }
343+ } finally {
344+ // restore original value
345+ if (savedProp != null ) {
346+ System .setProperty ("javax.net.ssl.trustStore" , savedProp );
347+ } else {
348+ System .clearProperty ("javax.net.ssl.trustStore" );
349+ }
350+ }
351+ }
352+
292353 @ Test
293354 public void testWithCustomTrustStore () {
294355 System .out .println ("Scenario: Testing with custom trust store" );
0 commit comments