4040import static org .junit .jupiter .api .Assertions .assertSame ;
4141import static org .junit .jupiter .api .Assertions .assertThrows ;
4242import static org .junit .jupiter .api .Assertions .assertTrue ;
43- import static org .mockito .Mockito .spy ;
44- import static org .mockito .Mockito .verify ;
43+ import static org .junit .jupiter .api .Assertions .fail ;
4544
4645import com .google .api .client .http .HttpTransport ;
4746import com .google .api .client .json .GenericJson ;
@@ -1053,14 +1052,8 @@ void build_withCertificateSource_succeeds() throws Exception {
10531052 }
10541053
10551054 @ Test
1056- void build_withCertificateSourceAndCustomX509Provider_success ()
1055+ void build_withDefaultCertificateConfig_success ()
10571056 throws IOException , KeyStoreException , CertificateException , NoSuchAlgorithmException {
1058- // Create an empty KeyStore and a spy on a custom X509Provider.
1059- KeyStore keyStore = KeyStore .getInstance ("JKS" );
1060- keyStore .load (null , null );
1061- TestX509Provider x509Provider =
1062- spy (new TestX509Provider (keyStore , "/path/to/certificate.json" ));
1063-
10641057 // Set up credential source for certificate type.
10651058 Map <String , Object > certificateMap = new HashMap <>();
10661059 certificateMap .put ("use_default_certificate_config" , true );
@@ -1071,11 +1064,18 @@ void build_withCertificateSourceAndCustomX509Provider_success()
10711064 MockExternalAccountCredentialsTransportFactory mockTransportFactory =
10721065 new MockExternalAccountCredentialsTransportFactory ();
10731066
1074- // Build credentials with the custom provider.
1067+ // Use the pre-existing test configuration file to bypass well-known path resolution.
1068+ EnvironmentProvider mockEnvProvider =
1069+ name ->
1070+ "GOOGLE_API_CERTIFICATE_CONFIG" .equals (name )
1071+ ? new File ("testresources/mtls/certificate_config.json" ).getAbsolutePath ()
1072+ : null ;
1073+
1074+ // Build credentials using the default provider (no setX509Provider).
10751075 IdentityPoolCredentials credentials =
10761076 IdentityPoolCredentials .newBuilder ()
1077- .setX509Provider (x509Provider )
10781077 .setHttpTransportFactory (mockTransportFactory )
1078+ .setEnvironmentProvider (mockEnvProvider )
10791079 .setAudience ("test-audience" )
10801080 .setSubjectTokenType ("test-token-type" )
10811081 .setCredentialSource (credentialSource )
@@ -1091,9 +1091,6 @@ void build_withCertificateSourceAndCustomX509Provider_success()
10911091 IdentityPoolCredentials .CERTIFICATE_METRICS_HEADER_VALUE ,
10921092 credentials .getCredentialSourceType (),
10931093 "Metrics header should indicate certificate source" );
1094-
1095- // Verify the custom provider methods were called during build.
1096- verify (x509Provider ).getKeyStore ();
10971094 }
10981095
10991096 @ Test
0 commit comments