@@ -1094,7 +1094,6 @@ void build_withCertificateSourceAndCustomX509Provider_success()
10941094
10951095 // Verify the custom provider methods were called during build.
10961096 verify (x509Provider ).getKeyStore ();
1097- verify (x509Provider ).getCertificatePath ();
10981097 }
10991098
11001099 @ Test
@@ -1156,26 +1155,27 @@ void build_withCustomProvider_throwsOnGetKeyStore()
11561155 @ Test
11571156 void build_withCustomProvider_throwsOnGetCertificatePath ()
11581157 throws IOException , KeyStoreException , CertificateException , NoSuchAlgorithmException {
1159- // Simulate a scenario where the X509Provider cannot access or read the certificate
1160- // configuration file needed to determine the certificate path, resulting in an IOException.
1158+ // Simulate a scenario where path resolution fails during build with a custom
1159+ // provider.
1160+ // We achieve this by passing a non-existent configuration path which causes
1161+ // MtlsUtils to throw
1162+ // IOException.
11611163 KeyStore keyStore = KeyStore .getInstance ("JKS" );
11621164 keyStore .load (null , null );
11631165 TestX509Provider x509Provider = new TestX509Provider (keyStore , "/path/to/certificate.json" );
1164- x509Provider .setShouldThrowOnGetCertificatePath (true ); // Configure to throw
11651166
11661167 Map <String , Object > certificateMap = new HashMap <>();
1167- certificateMap .put ("certificate_config_location" , "/path/to/certificate .json" );
1168+ certificateMap .put ("certificate_config_location" , "/non/existent/path .json" );
11681169
11691170 // Expect RuntimeException because the constructor wraps the IOException.
11701171 RuntimeException exception =
11711172 assertThrows (
11721173 RuntimeException .class ,
11731174 () -> createCredentialsWithCertificate (x509Provider , certificateMap ));
11741175
1175- // Verify the cause is the expected IOException from the mock .
1176+ // Verify the cause is the expected IOException (or subclass) from MtlsUtils .
11761177 assertNotNull (exception .getCause ());
11771178 assertTrue (exception .getCause () instanceof IOException );
1178- assertEquals ("Simulated IOException on certificate path" , exception .getCause ().getMessage ());
11791179
11801180 // Verify the wrapper exception message
11811181 assertEquals (
@@ -1284,7 +1284,6 @@ private static class TestX509Provider extends X509Provider {
12841284 private final KeyStore keyStore ;
12851285 private final String certificatePath ;
12861286 private boolean shouldThrowOnGetKeyStore = false ;
1287- private boolean shouldThrowOnGetCertificatePath = false ;
12881287
12891288 TestX509Provider (KeyStore keyStore , String certificatePath ) {
12901289 super ();
@@ -1300,20 +1299,8 @@ public KeyStore getKeyStore() throws IOException {
13001299 return keyStore ;
13011300 }
13021301
1303- @ Override
1304- public String getCertificatePath () throws IOException {
1305- if (shouldThrowOnGetCertificatePath ) {
1306- throw new IOException ("Simulated IOException on certificate path" );
1307- }
1308- return certificatePath ;
1309- }
1310-
13111302 void setShouldThrowOnGetKeyStore (boolean shouldThrow ) {
13121303 this .shouldThrowOnGetKeyStore = shouldThrow ;
13131304 }
1314-
1315- void setShouldThrowOnGetCertificatePath (boolean shouldThrow ) {
1316- this .shouldThrowOnGetCertificatePath = shouldThrow ;
1317- }
13181305 }
13191306}
0 commit comments