Skip to content

Commit 86a58df

Browse files
committed
chore: Fix tests
1 parent 721a38d commit 86a58df

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ private final GoogleCredentials tryGetComputeCredentials(HttpTransportFactory tr
311311
}
312312
boolean runningOnComputeEngine = ComputeEngineCredentials.isOnGce(transportFactory, this);
313313
checkedComputeEngine = true;
314+
ComputeEngineCredentials.Builder builder =
315+
shouldCheckMDSOnInitialization()
316+
? ComputeEngineCredentials.newBuilder()
317+
: ComputeEngineCredentials.newTestBuilder();
314318
if (runningOnComputeEngine) {
315-
return ComputeEngineCredentials.newBuilder()
316-
.setHttpTransportFactory(transportFactory)
317-
.build();
319+
return builder.setHttpTransportFactory(transportFactory).build();
318320
}
319321
return null;
320322
}
@@ -363,6 +365,10 @@ InputStream readStream(File file) throws FileNotFoundException {
363365
return new FileInputStream(file);
364366
}
365367

368+
boolean shouldCheckMDSOnInitialization() {
369+
return true;
370+
}
371+
366372
/*
367373
* End of methods to allow overriding in the test code to isolate from the environment.
368374
*/

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,11 @@ InputStream readStream(File file) throws FileNotFoundException {
977977
void setFileSandbox(boolean fileSandbox) {
978978
this.fileSandbox = fileSandbox;
979979
}
980+
981+
@Override
982+
boolean shouldCheckMDSOnInitialization() {
983+
return false;
984+
}
980985
}
981986

982987
static class MockRequestCountingTransportFactory implements HttpTransportFactory {

0 commit comments

Comments
 (0)