Skip to content

Commit 6153618

Browse files
committed
Test fix.
1 parent b1dc837 commit 6153618

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

oauth2_http/java/com/google/auth/oauth2/SystemEnvironmentProvider.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are
6+
* met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above
11+
* copyright notice, this list of conditions and the following disclaimer
12+
* in the documentation and/or other materials provided with the
13+
* distribution.
14+
* * Neither the name of Google LLC nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
131
package com.google.auth.oauth2;
232

333
import com.google.api.core.InternalApi;

oauth2_http/javatests/com/google/auth/oauth2/IdentityPoolCredentialsTest.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
import static org.junit.jupiter.api.Assertions.assertSame;
4141
import static org.junit.jupiter.api.Assertions.assertThrows;
4242
import 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

4645
import com.google.api.client.http.HttpTransport;
4746
import 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

Comments
 (0)