Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/google-auth-library-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: jabubake/google-auth-library-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on May 12, 2017

  1. Verified

    This commit was signed with the committer’s verified signature.
    darcyclarke Darcy Clarke
    Copy the full SHA
    42154bc View commit details
Original file line number Diff line number Diff line change
@@ -168,8 +168,8 @@ private final GoogleCredentials getDefaultCredentialsUnsynchronized(
}
}

// Then try App Engine
if (credentials == null) {
// Then try App Engine, if not bypassed
if (credentials == null && !isAppEngineCheckByPassed()) {
credentials = tryGetAppEngineCredential();
}

@@ -265,6 +265,17 @@ private final GoogleCredentials tryGetComputeCredentials(HttpTransportFactory tr
return null;
}

// Bypass app engine check if environment variable
// GOOGLE_APPLICATION_CREDENTIALS_SKIP_APP_ENGINE = 1 or true
private boolean isAppEngineCheckByPassed() {
boolean bypass = false; // do not bypass by default
String value = getEnv("GOOGLE_APPLICATION_CREDENTIALS_SKIP_APP_ENGINE");
if (value != null) {
bypass = value.equalsIgnoreCase("true") || value.equals("1");
}
return bypass;
}

/*
* Start of methods to allow overriding in the test code to isolate from the environment.
*/
Original file line number Diff line number Diff line change
@@ -212,6 +212,20 @@ public void getDefaultCredentials_appEngineRuntimeWithoutClass_throwsHelpfulLoad
}
}

@Test
public void getDefaultCredentials_appEngineClass_byPassWorks_retrievesCloudShellCredential()
throws IOException {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.addType(DefaultCredentialsProvider.APP_ENGINE_SIGNAL_CLASS,
MockOffAppEngineSystemProperty.class);
testProvider.setEnv("DEVSHELL_CLIENT_PORT","9090");
testProvider.setEnv("GOOGLE_APPLICATION_CREDENTIALS_SKIP_APP_ENGINE", "true");
GoogleCredentials credentials = testProvider.getDefaultCredentials(transportFactory);
assertNotNull(credentials);
assertTrue(credentials instanceof CloudShellCredentials);
}

@Test
public void getDefaultCredentials_compute_providesToken() throws IOException {
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();