mirror of https://github.com/grpc/grpc-java.git
interop-testing: implement compute engine channel creds test case in Java
This commit is contained in:
parent
a2cda8d15d
commit
1eb6fc523e
|
|
@ -1660,6 +1660,26 @@ public abstract class AbstractInteropTest {
|
||||||
assertResponse(goldenResponse, response);
|
assertResponse(goldenResponse, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sends an unary rpc with ComputeEngineChannelBuilder. */
|
||||||
|
public void computeEngineChannelCredentials(
|
||||||
|
String defaultServiceAccount,
|
||||||
|
TestServiceGrpc.TestServiceBlockingStub computeEngineStub) throws Exception {
|
||||||
|
final SimpleRequest request = SimpleRequest.newBuilder()
|
||||||
|
.setFillUsername(true)
|
||||||
|
.setResponseSize(314159)
|
||||||
|
.setPayload(Payload.newBuilder()
|
||||||
|
.setBody(ByteString.copyFrom(new byte[271828])))
|
||||||
|
.build();
|
||||||
|
final SimpleResponse response = computeEngineStub.unaryCall(request);
|
||||||
|
assertEquals(defaultServiceAccount, response.getUsername());
|
||||||
|
final SimpleResponse goldenResponse = SimpleResponse.newBuilder()
|
||||||
|
.setUsername(defaultServiceAccount)
|
||||||
|
.setPayload(Payload.newBuilder()
|
||||||
|
.setBody(ByteString.copyFrom(new byte[314159])))
|
||||||
|
.build();
|
||||||
|
assertResponse(goldenResponse, response);
|
||||||
|
}
|
||||||
|
|
||||||
/** Test JWT-based auth. */
|
/** Test JWT-based auth. */
|
||||||
public void jwtTokenCreds(InputStream serviceAccountJson) throws Exception {
|
public void jwtTokenCreds(InputStream serviceAccountJson) throws Exception {
|
||||||
final SimpleRequest request = SimpleRequest.newBuilder()
|
final SimpleRequest request = SimpleRequest.newBuilder()
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ public enum TestCases {
|
||||||
PING_PONG("full-duplex ping-pong streaming"),
|
PING_PONG("full-duplex ping-pong streaming"),
|
||||||
EMPTY_STREAM("A stream that has zero-messages in both directions"),
|
EMPTY_STREAM("A stream that has zero-messages in both directions"),
|
||||||
COMPUTE_ENGINE_CREDS("large_unary with service_account auth"),
|
COMPUTE_ENGINE_CREDS("large_unary with service_account auth"),
|
||||||
|
COMPUTE_ENGINE_CHANNEL_CREDENTIALS("large unary with compute engine channel builder"),
|
||||||
SERVICE_ACCOUNT_CREDS("large_unary with compute engine auth"),
|
SERVICE_ACCOUNT_CREDS("large_unary with compute engine auth"),
|
||||||
JWT_TOKEN_CREDS("JWT-based auth"),
|
JWT_TOKEN_CREDS("JWT-based auth"),
|
||||||
OAUTH2_AUTH_TOKEN("raw oauth2 access token auth"),
|
OAUTH2_AUTH_TOKEN("raw oauth2 access token auth"),
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import io.netty.handler.ssl.SslContext;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -278,6 +279,20 @@ public class TestServiceClient {
|
||||||
tester.computeEngineCreds(defaultServiceAccount, oauthScope);
|
tester.computeEngineCreds(defaultServiceAccount, oauthScope);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case COMPUTE_ENGINE_CHANNEL_CREDENTIALS: {
|
||||||
|
ManagedChannel channel = ComputeEngineChannelBuilder
|
||||||
|
.forAddress(serverHost, serverPort).build();
|
||||||
|
try {
|
||||||
|
TestServiceGrpc.TestServiceBlockingStub computeEngineStub =
|
||||||
|
TestServiceGrpc.newBlockingStub(channel);
|
||||||
|
tester.computeEngineChannelCredentials(defaultServiceAccount, computeEngineStub);
|
||||||
|
} finally {
|
||||||
|
channel.shutdownNow();
|
||||||
|
channel.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SERVICE_ACCOUNT_CREDS: {
|
case SERVICE_ACCOUNT_CREDS: {
|
||||||
String jsonKey = Files.asCharSource(new File(serviceAccountKeyFile), UTF_8).read();
|
String jsonKey = Files.asCharSource(new File(serviceAccountKeyFile), UTF_8).read();
|
||||||
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
|
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ public class TestCasesTest {
|
||||||
"server_compressed_unary",
|
"server_compressed_unary",
|
||||||
"client_streaming",
|
"client_streaming",
|
||||||
"client_compressed_streaming",
|
"client_compressed_streaming",
|
||||||
|
"compute_engine_channel_credentials",
|
||||||
"server_streaming",
|
"server_streaming",
|
||||||
"server_compressed_streaming",
|
"server_compressed_streaming",
|
||||||
"ping_pong",
|
"ping_pong",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue