diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-05-01 13:21:57 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-05-01 13:21:57 -0700 |
commit | d6c16558b40b723d61039c2bfbf491f90adf3ecb (patch) | |
tree | b30695b00ac0a6c7554d98f2b974e8f7bb8fbbc5 /src/php/tests/interop/interop_client.php | |
parent | 9805bb2ce86413105e706da41a1b3e6040264e34 (diff) | |
parent | 5ae895a5d06fad59a89ce6e8923b1145dea663bd (diff) |
Merge github.com:grpc/grpc into one-read
Conflicts:
src/core/iomgr/tcp_posix.c
src/core/profiling/basic_timers.c
Diffstat (limited to 'src/php/tests/interop/interop_client.php')
-rwxr-xr-x | src/php/tests/interop/interop_client.php | 89 |
1 files changed, 74 insertions, 15 deletions
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php index 6f81bfa6cd..22f85aa322 100755 --- a/src/php/tests/interop/interop_client.php +++ b/src/php/tests/interop/interop_client.php @@ -38,6 +38,7 @@ require 'empty.php'; require 'message_set.php'; require 'messages.php'; require 'test.php'; + /** * Assertion function that always exits with an error code if the assertion is * falsy @@ -45,7 +46,7 @@ require 'test.php'; * @param $error_message Message to display if the assertion is false */ function hardAssert($value, $error_message) { - if(!$value) { + if (!$value) { echo $error_message . "\n"; exit(1); } @@ -53,7 +54,7 @@ function hardAssert($value, $error_message) { /** * Run the empty_unary test. - * Currently not tested against any server as of 2014-12-04 + * Passes when run against the Node server as of 2015-04-30 * @param $stub Stub object that has service methods */ function emptyUnary($stub) { @@ -64,11 +65,20 @@ function emptyUnary($stub) { /** * Run the large_unary test. - * Passes when run against the C++ server as of 2014-12-04 - * Not tested against any other server as of 2014-12-04 + * Passes when run against the C++/Node server as of 2015-04-30 * @param $stub Stub object that has service methods */ function largeUnary($stub) { + performLargeUnary($stub); +} + +/** + * Shared code between large unary test and auth test + * @param $stub Stub object that has service methods + * @param $fillUsername boolean whether to fill result with username + * @param $fillOauthScope boolean whether to fill result with oauth scope + */ +function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false) { $request_len = 271828; $response_len = 314159; @@ -79,6 +89,8 @@ function largeUnary($stub) { $payload->setType(grpc\testing\PayloadType::COMPRESSABLE); $payload->setBody(str_repeat("\0", $request_len)); $request->setPayload($payload); + $request->setFillUsername($fillUsername); + $request->setFillOauthScope($fillOauthScope); list($result, $status) = $stub->UnaryCall($request)->wait(); hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully'); @@ -90,11 +102,32 @@ function largeUnary($stub) { 'Payload had the wrong length'); hardAssert($payload->getBody() === str_repeat("\0", $response_len), 'Payload had the wrong content'); + return $result; +} + +/** + * Run the service account credentials auth test. + * Passes when run against the cloud server as of 2015-04-30 + * @param $stub Stub object that has service methods + * @param $args array command line args + */ +function serviceAccountCreds($stub, $args) { + if (!array_key_exists('oauth_scope', $args)) { + throw new Exception('Missing oauth scope'); + } + $jsonKey = json_decode( + file_get_contents(getenv(Google\Auth\CredentialsLoader::ENV_VAR)), + true); + $result = performLargeUnary($stub, $fillUsername=true, $fillOauthScope=true); + hardAssert($result->getUsername() == $jsonKey['client_email'], + 'invalid email returned'); + hardAssert(strpos($args['oauth_scope'], $result->getOauthScope()) !== false, + 'invalid oauth scope returned'); } /** * Run the client_streaming test. - * Not tested against any server as of 2014-12-04. + * Passes when run against the Node server as of 2015-04-30 * @param $stub Stub object that has service methods */ function clientStreaming($stub) { @@ -117,7 +150,7 @@ function clientStreaming($stub) { /** * Run the server_streaming test. - * Not tested against any server as of 2014-12-04. + * Passes when run against the Node server as of 2015-04-30 * @param $stub Stub object that has service methods. */ function serverStreaming($stub) { @@ -148,7 +181,7 @@ function serverStreaming($stub) { /** * Run the ping_pong test. - * Not tested against any server as of 2014-12-04. + * Passes when run against the Node server as of 2015-04-30 * @param $stub Stub object that has service methods. */ function pingPong($stub) { @@ -182,6 +215,11 @@ function pingPong($stub) { 'Call did not complete successfully'); } +/** + * Run the cancel_after_first_response test. + * Passes when run against the Node server as of 2015-04-30 + * @param $stub Stub object that has service methods. + */ function cancelAfterFirstResponse($stub) { $call = $stub->FullDuplexCall(); $request = new grpc\testing\StreamingOutputCallRequest(); @@ -201,7 +239,8 @@ function cancelAfterFirstResponse($stub) { 'Call status was not CANCELLED'); } -$args = getopt('', array('server_host:', 'server_port:', 'test_case:')); +$args = getopt('', array('server_host:', 'server_port:', 'test_case:', + 'server_host_override:', 'oauth_scope:')); if (!array_key_exists('server_host', $args) || !array_key_exists('server_port', $args) || !array_key_exists('test_case', $args)) { @@ -210,20 +249,37 @@ if (!array_key_exists('server_host', $args) || $server_address = $args['server_host'] . ':' . $args['server_port']; -$credentials = Grpc\Credentials::createSsl( - file_get_contents(dirname(__FILE__) . '/../data/ca.pem')); +if (!array_key_exists('server_host_override', $args)) { + $args['server_host_override'] = 'foo.test.google.fr'; +} + +$ssl_cert_file = getenv('SSL_CERT_FILE'); +if (!$ssl_cert_file) { + $ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem'; +} + +$credentials = Grpc\Credentials::createSsl(file_get_contents($ssl_cert_file)); + +$opts = [ + 'grpc.ssl_target_name_override' => $args['server_host_override'], + 'credentials' => $credentials, + ]; + +if (array_key_exists('oauth_scope', $args)) { + $auth = Google\Auth\ApplicationDefaultCredentials::getCredentials( + $args['oauth_scope']); + $opts['update_metadata'] = $auth->getUpdateMetadataFunc(); +} + $stub = new grpc\testing\TestServiceClient( new Grpc\BaseStub( $server_address, - [ - 'grpc.ssl_target_name_override' => 'foo.test.google.fr', - 'credentials' => $credentials - ])); + $opts)); echo "Connecting to $server_address\n"; echo "Running test case $args[test_case]\n"; -switch($args['test_case']) { +switch ($args['test_case']) { case 'empty_unary': emptyUnary($stub); break; @@ -242,6 +298,9 @@ switch($args['test_case']) { case 'cancel_after_first_response': cancelAfterFirstResponse($stub); break; + case 'service_account_creds': + serviceAccountCreds($stub, $args); + break; default: exit(1); } |