Search in sources :

Example 1 with ComputeEngineCredentials

use of com.google.auth.oauth2.ComputeEngineCredentials in project grpc-java by grpc.

the class AbstractInteropTest method computeEngineCreds.

/** Sends a large unary rpc with compute engine credentials. */
public void computeEngineCreds(String serviceAccount, String oauthScope) throws Exception {
    ComputeEngineCredentials credentials = new ComputeEngineCredentials();
    TestServiceGrpc.TestServiceBlockingStub stub = blockingStub.withCallCredentials(MoreCallCredentials.from(credentials));
    final SimpleRequest request = SimpleRequest.newBuilder().setFillUsername(true).setFillOauthScope(true).setResponseSize(314159).setResponseType(PayloadType.COMPRESSABLE).setPayload(Payload.newBuilder().setBody(ByteString.copyFrom(new byte[271828]))).build();
    final SimpleResponse response = stub.unaryCall(request);
    assertEquals(serviceAccount, response.getUsername());
    assertFalse(response.getOauthScope().isEmpty());
    assertTrue("Received oauth scope: " + response.getOauthScope(), oauthScope.contains(response.getOauthScope()));
    final SimpleResponse goldenResponse = SimpleResponse.newBuilder().setOauthScope(response.getOauthScope()).setUsername(response.getUsername()).setPayload(Payload.newBuilder().setType(PayloadType.COMPRESSABLE).setBody(ByteString.copyFrom(new byte[314159]))).build();
    assertEquals(goldenResponse, response);
}
Also used : SimpleResponse(io.grpc.testing.integration.Messages.SimpleResponse) ComputeEngineCredentials(com.google.auth.oauth2.ComputeEngineCredentials) SimpleRequest(io.grpc.testing.integration.Messages.SimpleRequest)

Aggregations

ComputeEngineCredentials (com.google.auth.oauth2.ComputeEngineCredentials)1 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)1 SimpleResponse (io.grpc.testing.integration.Messages.SimpleResponse)1