@@ -1120,7 +1120,6 @@ void build_withCertificateSourceAndCustomX509Provider_success()
11201120
11211121 // Verify the custom provider methods were called during build.
11221122 verify (x509Provider ).getKeyStore ();
1123- verify (x509Provider ).getCertificatePath ();
11241123 }
11251124
11261125 @ Test
@@ -1182,26 +1181,27 @@ void build_withCustomProvider_throwsOnGetKeyStore()
11821181 @ Test
11831182 void build_withCustomProvider_throwsOnGetCertificatePath ()
11841183 throws IOException , KeyStoreException , CertificateException , NoSuchAlgorithmException {
1185- // Simulate a scenario where the X509Provider cannot access or read the certificate
1186- // configuration file needed to determine the certificate path, resulting in an IOException.
1184+ // Simulate a scenario where path resolution fails during build with a custom
1185+ // provider.
1186+ // We achieve this by passing a non-existent configuration path which causes
1187+ // MtlsUtils to throw
1188+ // IOException.
11871189 KeyStore keyStore = KeyStore .getInstance ("JKS" );
11881190 keyStore .load (null , null );
11891191 TestX509Provider x509Provider = new TestX509Provider (keyStore , "/path/to/certificate.json" );
1190- x509Provider .setShouldThrowOnGetCertificatePath (true ); // Configure to throw
11911192
11921193 Map <String , Object > certificateMap = new HashMap <>();
1193- certificateMap .put ("certificate_config_location" , "/path/to/certificate .json" );
1194+ certificateMap .put ("certificate_config_location" , "/non/existent/path .json" );
11941195
11951196 // Expect RuntimeException because the constructor wraps the IOException.
11961197 RuntimeException exception =
11971198 assertThrows (
11981199 RuntimeException .class ,
11991200 () -> createCredentialsWithCertificate (x509Provider , certificateMap ));
12001201
1201- // Verify the cause is the expected IOException from the mock .
1202+ // Verify the cause is the expected IOException (or subclass) from MtlsUtils .
12021203 assertNotNull (exception .getCause ());
12031204 assertTrue (exception .getCause () instanceof IOException );
1204- assertEquals ("Simulated IOException on certificate path" , exception .getCause ().getMessage ());
12051205
12061206 // Verify the wrapper exception message
12071207 assertEquals (
@@ -1310,7 +1310,6 @@ private static class TestX509Provider extends X509Provider {
13101310 private final KeyStore keyStore ;
13111311 private final String certificatePath ;
13121312 private boolean shouldThrowOnGetKeyStore = false ;
1313- private boolean shouldThrowOnGetCertificatePath = false ;
13141313
13151314 TestX509Provider (KeyStore keyStore , String certificatePath ) {
13161315 super ();
@@ -1326,20 +1325,8 @@ public KeyStore getKeyStore() throws IOException {
13261325 return keyStore ;
13271326 }
13281327
1329- @ Override
1330- public String getCertificatePath () throws IOException {
1331- if (shouldThrowOnGetCertificatePath ) {
1332- throw new IOException ("Simulated IOException on certificate path" );
1333- }
1334- return certificatePath ;
1335- }
1336-
13371328 void setShouldThrowOnGetKeyStore (boolean shouldThrow ) {
13381329 this .shouldThrowOnGetKeyStore = shouldThrow ;
13391330 }
1340-
1341- void setShouldThrowOnGetCertificatePath (boolean shouldThrow ) {
1342- this .shouldThrowOnGetCertificatePath = shouldThrow ;
1343- }
13441331 }
13451332}
0 commit comments