Implement jwt_token_creds interop test

Using a JWT is a bit more work than it should be, but improving that
will come later.

At present, this test fails, but it is believed to be due to the auth
library.
This commit is contained in:
Eric Anderson 2015-09-01 16:49:52 -07:00
parent 00e024c684
commit c68f9ffce0
2 changed files with 28 additions and 0 deletions

View File

@ -48,6 +48,7 @@ import com.google.auth.oauth2.ComputeEngineCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.OAuth2Credentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.protobuf.ByteString;
import com.google.protobuf.EmptyProtos.Empty;
@ -817,6 +818,29 @@ public abstract class AbstractTransportTest {
assertEquals(goldenResponse, response);
}
/** Test JWT-based auth. */
public void jwtTokenCreds(InputStream serviceAccountJson) throws Exception {
final SimpleRequest request = SimpleRequest.newBuilder()
.setResponseType(PayloadType.COMPRESSABLE)
.setResponseSize(314159)
.setPayload(Payload.newBuilder()
.setBody(ByteString.copyFrom(new byte[271828])))
.setFillUsername(true)
.build();
ServiceAccountCredentials origCreds = (ServiceAccountCredentials)
GoogleCredentials.fromStream(serviceAccountJson);
ServiceAccountJwtAccessCredentials credentials = new ServiceAccountJwtAccessCredentials(
origCreds.getClientId(), origCreds.getClientEmail(), origCreds.getPrivateKey(),
origCreds.getPrivateKeyId());
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
.withInterceptors(new ClientAuthInterceptor(credentials,
Executors.newSingleThreadExecutor()));
SimpleResponse response = stub.unaryCall(request);
assertEquals(origCreds.getClientEmail(), response.getUsername());
assertEquals(314159, response.getPayload().getBody().size());
}
/** Sends a unary rpc with raw oauth2 access token credentials. */
public void oauth2AuthToken(String jsonKey, InputStream credentialsStream, String authScope)
throws Exception {

View File

@ -167,6 +167,7 @@ public class TestServiceClient {
+ "\n empty_stream: A stream that has zero-messages in both directions"
+ "\n service_account_creds: large_unary with service_account auth"
+ "\n compute_engine_creds: large_unary with compute engine auth"
+ "\n jwt_token_creds: JWT-based auth"
+ "\n oauth2_auth_token: raw oauth2 access token auth"
+ "\n per_rpc_creds: per rpc raw oauth2 access token auth"
+ "\n cancel_after_begin: cancel stream after starting it"
@ -230,6 +231,9 @@ public class TestServiceClient {
String jsonKey = Files.toString(new File(serviceAccountKeyFile), Charset.forName("UTF-8"));
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
tester.serviceAccountCreds(jsonKey, credentialsStream, oauthScope);
} else if ("jwt_token_creds".equals(testCase)) {
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
tester.jwtTokenCreds(credentialsStream);
} else if ("oauth2_auth_token".equals(testCase)) {
String jsonKey = Files.toString(new File(serviceAccountKeyFile), Charset.forName("UTF-8"));
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));