Search in sources :

Example 1 with FakeMtlsProvider

use of com.google.api.gax.rpc.testing.FakeMtlsProvider in project gax-java by googleapis.

the class ClientContextTest method testAlwaysUseMtlsEndpoint.

@Test
public void testAlwaysUseMtlsEndpoint() throws IOException {
    // Test the case that mTLS endpoint is always used.
    boolean switchToMtlsEndpointAllowed = true;
    MtlsProvider provider = new FakeMtlsProvider(false, MtlsEndpointUsagePolicy.ALWAYS, null, "", false);
    String endpointSelected = ClientContext.getEndpoint(endpoint, mtlsEndpoint, switchToMtlsEndpointAllowed, provider);
    assertEquals(mtlsEndpoint, endpointSelected);
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) MtlsProvider(com.google.api.gax.rpc.mtls.MtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) Test(org.junit.Test)

Example 2 with FakeMtlsProvider

use of com.google.api.gax.rpc.testing.FakeMtlsProvider in project gax-java by googleapis.

the class ClientContextTest method testAutoUseMtlsEndpoint.

@Test
public void testAutoUseMtlsEndpoint() throws IOException {
    // Test the case client certificate exists and mTLS endpoint is selected.
    boolean switchToMtlsEndpointAllowed = true;
    MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.AUTO, FakeMtlsProvider.createTestMtlsKeyStore(), "", false);
    String endpointSelected = ClientContext.getEndpoint(endpoint, mtlsEndpoint, switchToMtlsEndpointAllowed, provider);
    assertEquals(mtlsEndpoint, endpointSelected);
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) MtlsProvider(com.google.api.gax.rpc.mtls.MtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) Test(org.junit.Test)

Example 3 with FakeMtlsProvider

use of com.google.api.gax.rpc.testing.FakeMtlsProvider in project gax-java by googleapis.

the class ClientContextTest method testNeverUseMtlsEndpoint.

@Test
public void testNeverUseMtlsEndpoint() throws IOException {
    // Test the case that mTLS endpoint is never used.
    boolean switchToMtlsEndpointAllowed = true;
    MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.NEVER, FakeMtlsProvider.createTestMtlsKeyStore(), "", false);
    String endpointSelected = ClientContext.getEndpoint(endpoint, mtlsEndpoint, switchToMtlsEndpointAllowed, provider);
    assertEquals(endpoint, endpointSelected);
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) MtlsProvider(com.google.api.gax.rpc.mtls.MtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) Test(org.junit.Test)

Example 4 with FakeMtlsProvider

use of com.google.api.gax.rpc.testing.FakeMtlsProvider in project gax-java by googleapis.

the class AbstractMtlsTransportChannelTest method testUseClientCertificate.

@Test
public void testUseClientCertificate() throws IOException, GeneralSecurityException {
    MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.AUTO, FakeMtlsProvider.createTestMtlsKeyStore(), "", false);
    assertNotNull(getMtlsObjectFromTransportChannel(provider));
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) Test(org.junit.Test)

Example 5 with FakeMtlsProvider

use of com.google.api.gax.rpc.testing.FakeMtlsProvider in project gax-java by googleapis.

the class AbstractMtlsTransportChannelTest method testGetKeyStoreThrows.

@Test
public void testGetKeyStoreThrows() throws GeneralSecurityException {
    // Test the case where provider.getKeyStore() throws.
    MtlsProvider provider = new FakeMtlsProvider(true, MtlsEndpointUsagePolicy.AUTO, null, "", true);
    try {
        getMtlsObjectFromTransportChannel(provider);
        fail("should throw an exception");
    } catch (IOException e) {
        assertTrue("expected getKeyStore to throw an exception", e.getMessage().contains("getKeyStore throws exception"));
    }
}
Also used : FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) FakeMtlsProvider(com.google.api.gax.rpc.testing.FakeMtlsProvider) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FakeMtlsProvider (com.google.api.gax.rpc.testing.FakeMtlsProvider)10 Test (org.junit.Test)10 MtlsProvider (com.google.api.gax.rpc.mtls.MtlsProvider)6 IOException (java.io.IOException)2