use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.
the class DefaultCredentialsProviderTest method getDefaultCredentials_noCredentialsSandbox_throwsNonSecurity.
@Test
public void getDefaultCredentials_noCredentialsSandbox_throwsNonSecurity() throws Exception {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.setFileSandbox(true);
try {
testProvider.getDefaultCredentials(transportFactory);
fail("No credential expected.");
} catch (IOException e) {
String message = e.getMessage();
assertTrue(message.contains(DefaultCredentialsProvider.HELP_PERMALINK));
}
}
use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.
the class DefaultCredentialsProviderTest method getDefaultCredentials_appEngineSkipWorks_retrievesCloudShellCredential.
@Test
public void getDefaultCredentials_appEngineSkipWorks_retrievesCloudShellCredential() throws IOException {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.addType(DefaultCredentialsProvider.APP_ENGINE_SIGNAL_CLASS, MockOffAppEngineSystemProperty.class);
testProvider.setEnv(DefaultCredentialsProvider.CLOUD_SHELL_ENV_VAR, "9090");
testProvider.setEnv(DefaultCredentialsProvider.SKIP_APP_ENGINE_ENV_VAR, "true");
testProvider.setProperty("isOnGAEStanadard7", "true");
GoogleCredentials credentials = testProvider.getDefaultCredentials(transportFactory);
assertNotNull(credentials);
assertTrue(credentials instanceof CloudShellCredentials);
}
use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.
the class DefaultCredentialsProviderTest method getDefaultCredentials_envValidSandbox_throwsNonSecurity.
@Test
public void getDefaultCredentials_envValidSandbox_throwsNonSecurity() throws Exception {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
InputStream userStream = UserCredentialsTest.writeUserStream(USER_CLIENT_ID, USER_CLIENT_SECRET, REFRESH_TOKEN);
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.setFileSandbox(true);
String userPath = "/user.json";
testProvider.addFile(userPath, userStream);
testProvider.setEnv(DefaultCredentialsProvider.CREDENTIAL_ENV_VAR, userPath);
try {
testProvider.getDefaultCredentials(transportFactory);
fail("No credential expected.");
} catch (IOException e) {
String message = e.getMessage();
assertTrue(message.contains(DefaultCredentialsProvider.HELP_PERMALINK));
}
}
use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.
the class DefaultCredentialsProviderTest method getDefaultCredentials_cloudshell.
@Test
public void getDefaultCredentials_cloudshell() throws IOException {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.setEnv(DefaultCredentialsProvider.CLOUD_SHELL_ENV_VAR, "4");
GoogleCredentials defaultCredentials = testProvider.getDefaultCredentials(transportFactory);
assertTrue(defaultCredentials instanceof CloudShellCredentials);
assertEquals(((CloudShellCredentials) defaultCredentials).getAuthPort(), 4);
}
use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.
the class ServiceAccountJwtAccessCredentialsTest method fromStream_nullStream_throws.
@Test
public void fromStream_nullStream_throws() throws IOException {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
try {
ServiceAccountCredentials.fromStream(null, transportFactory);
fail("Should throw if InputStream is null");
} catch (NullPointerException expected) {
// Expected
}
}
Aggregations