Search in sources :

Example 11 with MockHttpTransportFactory

use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.

the class ComputeEngineCredentialsTest method equals_false_transportFactory.

@Test
public void equals_false_transportFactory() throws IOException {
    MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory();
    MockMetadataServerTransportFactory serverTransportFactory = new MockMetadataServerTransportFactory();
    ComputeEngineCredentials credentials = ComputeEngineCredentials.newBuilder().setHttpTransportFactory(serverTransportFactory).build();
    ComputeEngineCredentials otherCredentials = ComputeEngineCredentials.newBuilder().setHttpTransportFactory(httpTransportFactory).build();
    assertFalse(credentials.equals(otherCredentials));
    assertFalse(otherCredentials.equals(credentials));
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) Test(org.junit.Test)

Example 12 with MockHttpTransportFactory

use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.

the class DefaultCredentialsProviderTest method getDefaultCredentials_envMissingFile_throws.

@Test
public void getDefaultCredentials_envMissingFile_throws() {
    final String invalidPath = "/invalid/path";
    MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
    TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
    testProvider.setEnv(DefaultCredentialsProvider.CREDENTIAL_ENV_VAR, invalidPath);
    try {
        testProvider.getDefaultCredentials(transportFactory);
        fail("Non existent credential should throw exception");
    } catch (IOException e) {
        String message = e.getMessage();
        assertTrue(message.contains(DefaultCredentialsProvider.CREDENTIAL_ENV_VAR));
        assertTrue(message.contains(invalidPath));
    }
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with MockHttpTransportFactory

use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.

the class DefaultCredentialsProviderTest method getDefaultCredentials_appEngineRuntimeWithoutClass_throwsHelpfulLoadError.

@Test
public void getDefaultCredentials_appEngineRuntimeWithoutClass_throwsHelpfulLoadError() {
    MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
    TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
    testProvider.addType(DefaultCredentialsProvider.APP_ENGINE_SIGNAL_CLASS, MockAppEngineSystemProperty.class);
    testProvider.setProperty("isOnGAEStandard7", "true");
    try {
        testProvider.getDefaultCredentials(transportFactory);
        fail("Credential expected to fail to load if credential class not present.");
    } catch (IOException e) {
        String message = e.getMessage();
        assertFalse(message.contains(DefaultCredentialsProvider.HELP_PERMALINK));
        assertTrue(message.contains("Check that the App Engine SDK is deployed."));
    }
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with MockHttpTransportFactory

use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.

the class DefaultCredentialsProviderTest method getDefaultCredentials_appEngineClassWithoutRuntime_NotFoundError.

@Test
public void getDefaultCredentials_appEngineClassWithoutRuntime_NotFoundError() {
    MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
    TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
    testProvider.addType(DefaultCredentialsProvider.APP_ENGINE_SIGNAL_CLASS, MockOffAppEngineSystemProperty.class);
    testProvider.setProperty("isOnGAEStandard7", "true");
    try {
        testProvider.getDefaultCredentials(transportFactory);
        fail("No credential expected when not on App Engine.");
    } 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 15 with MockHttpTransportFactory

use of com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory in project google-auth-library-java by google.

the class DefaultCredentialsProviderTest method getDefaultCredentials_noCredentials_throws.

@Test
public void getDefaultCredentials_noCredentials_throws() throws Exception {
    MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
    TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
    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)

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