Implement per_rpc_creds test

This commit is contained in:
Xudong Ma 2015-08-27 13:59:35 -07:00
parent 3c79c52427
commit 1f0cad21e5
2 changed files with 16 additions and 2 deletions

View File

@ -593,9 +593,9 @@ public abstract class AbstractTransportTest {
requestHeadersCapture.get().get(GrpcUtil.TIMEOUT_KEY));
Assert.assertTrue(
"configuredTimeoutMinutes=" + configuredTimeoutMinutes
+ ", transferredTimeoutMinutes=" + transferredTimeoutMinutes,
+ ", transferredTimeoutMinutes=" + transferredTimeoutMinutes,
configuredTimeoutMinutes - transferredTimeoutMinutes >= 0
&& configuredTimeoutMinutes - transferredTimeoutMinutes <= 1);
&& configuredTimeoutMinutes - transferredTimeoutMinutes <= 1);
}
@Test
@ -847,6 +847,15 @@ public abstract class AbstractTransportTest {
authScope.contains(response.getOauthScope()));
}
/** Sends a unary rpc with "per rpc" raw oauth2 access token credentials. */
public void perRpcCreds(String jsonKey, InputStream credentialsStream, String oauthScope)
throws Exception {
// In gRpc Java, we don't have per Rpc credentials, user can use an intercepted stub only once
// for that purpose.
// So, this test is identical to oauth2_auth_token test.
oauth2AuthToken(jsonKey, credentialsStream, oauthScope);
}
protected static void assertSuccess(StreamRecorder<?> recorder) {
if (recorder.getError() != null) {
throw new AssertionError(recorder.getError());

View File

@ -168,6 +168,7 @@ public class TestServiceClient {
+ "\n service_account_creds: large_unary with service_account auth"
+ "\n compute_engine_creds: large_unary with compute engine 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"
+ "\n cancel_after_first_response: cancel on first response"
+ "\n --use_tls=true|false Whether to use TLS. Default " + c.useTls
@ -233,6 +234,10 @@ public class TestServiceClient {
String jsonKey = Files.toString(new File(serviceAccountKeyFile), Charset.forName("UTF-8"));
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
tester.oauth2AuthToken(jsonKey, credentialsStream, oauthScope);
} else if ("per_rpc_creds".equals(testCase)) {
String jsonKey = Files.toString(new File(serviceAccountKeyFile), Charset.forName("UTF-8"));
FileInputStream credentialsStream = new FileInputStream(new File(serviceAccountKeyFile));
tester.perRpcCreds(jsonKey, credentialsStream, oauthScope);
} else if ("cancel_after_begin".equals(testCase)) {
tester.cancelAfterBegin();
} else if ("cancel_after_first_response".equals(testCase)) {