Search in sources :

Example 1 with MockHttpTransportFactory

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));
    }
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with MockHttpTransportFactory

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);
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) Test(org.junit.Test)

Example 3 with MockHttpTransportFactory

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));
    }
}
Also used : InputStream(java.io.InputStream) MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with MockHttpTransportFactory

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);
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) Test(org.junit.Test)

Example 5 with MockHttpTransportFactory

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
    }
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) Test(org.junit.Test)

Aggregations

MockHttpTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory)19 Test (org.junit.Test)19 URI (java.net.URI)7 IOException (java.io.IOException)6 MockTokenServerTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory)2 InputStream (java.io.InputStream)1