From 574c053ebb757f5d61da0aca058f66f26111e0ff Mon Sep 17 00:00:00 2001 From: apolcyn Date: Fri, 1 Feb 2019 16:49:54 -0800 Subject: [PATCH] interop-testing: Add GoogleDefaultCreds test case for java --- .../integration/AbstractInteropTest.java | 21 +++++++++++++++++++ .../grpc/testing/integration/TestCases.java | 2 ++ .../integration/TestServiceClient.java | 13 ++++++++++++ .../testing/integration/TestCasesTest.java | 1 + 4 files changed, 37 insertions(+) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index a50dda5a86..7b6b7d19e8 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -1712,6 +1712,27 @@ public abstract class AbstractInteropTest { oauth2AuthToken(jsonKey, credentialsStream, oauthScope); } + /** Sends an unary rpc with "google default credentials". */ + public void googleDefaultCredentials( + String defaultServiceAccount, + TestServiceGrpc.TestServiceBlockingStub googleDefaultStub) throws Exception { + final SimpleRequest request = SimpleRequest.newBuilder() + .setFillUsername(true) + .setResponseSize(314159) + .setPayload(Payload.newBuilder() + .setBody(ByteString.copyFrom(new byte[271828]))) + .build(); + final SimpleResponse response = googleDefaultStub.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); + } + protected static void assertSuccess(StreamRecorder recorder) { if (recorder.getError() != null) { throw new AssertionError(recorder.getError()); diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java index 7ac02ad57d..c11580ca75 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestCases.java @@ -42,6 +42,8 @@ public enum TestCases { JWT_TOKEN_CREDS("JWT-based auth"), OAUTH2_AUTH_TOKEN("raw oauth2 access token auth"), PER_RPC_CREDS("per rpc raw oauth2 access token auth"), + GOOGLE_DEFAULT_CREDENTIALS( + "google default credentials, i.e. GoogleManagedChannel based auth"), CUSTOM_METADATA("unary and full duplex calls with metadata"), STATUS_CODE_AND_MESSAGE("request error code and message"), SPECIAL_STATUS_MESSAGE("special characters in status message"), diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index b90eaa829f..2d88bfec6c 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -304,6 +304,19 @@ public class TestServiceClient { break; } + case GOOGLE_DEFAULT_CREDENTIALS: { + ManagedChannel channel = GoogleDefaultChannelBuilder.forAddress( + serverHost, serverPort).build(); + try { + TestServiceGrpc.TestServiceBlockingStub googleDefaultStub = + TestServiceGrpc.newBlockingStub(channel); + tester.googleDefaultCredentials(defaultServiceAccount, googleDefaultStub); + } finally { + channel.shutdownNow(); + } + break; + } + case CUSTOM_METADATA: { tester.customMetadata(); break; diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java index cec02dde8a..2ce95b412f 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TestCasesTest.java @@ -56,6 +56,7 @@ public class TestCasesTest { "jwt_token_creds", "oauth2_auth_token", "per_rpc_creds", + "google_default_credentials", "custom_metadata", "status_code_and_message", "special_status_message",