interop_client.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <?php
  2. /*
  3. *
  4. * Copyright 2015-2016, Google Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following disclaimer
  15. * in the documentation and/or other materials provided with the
  16. * distribution.
  17. * * Neither the name of Google Inc. nor the names of its
  18. * contributors may be used to endorse or promote products derived from
  19. * this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. require_once realpath(dirname(__FILE__).'/../../vendor/autoload.php');
  35. require 'empty.php';
  36. require 'messages.php';
  37. require 'test.php';
  38. use Google\Auth\CredentialsLoader;
  39. use Google\Auth\ApplicationDefaultCredentials;
  40. use GuzzleHttp\ClientInterface;
  41. /**
  42. * Assertion function that always exits with an error code if the assertion is
  43. * falsy.
  44. *
  45. * @param $value Assertion value. Should be true.
  46. * @param $error_message Message to display if the assertion is false
  47. */
  48. function hardAssert($value, $error_message)
  49. {
  50. if (!$value) {
  51. echo $error_message."\n";
  52. exit(1);
  53. }
  54. }
  55. /**
  56. * Run the empty_unary test.
  57. *
  58. * @param $stub Stub object that has service methods
  59. */
  60. function emptyUnary($stub)
  61. {
  62. list($result, $status) = $stub->EmptyCall(new grpc\testing\EmptyMessage())->wait();
  63. hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
  64. hardAssert($result !== null, 'Call completed with a null response');
  65. }
  66. /**
  67. * Run the large_unary test.
  68. *
  69. * @param $stub Stub object that has service methods
  70. */
  71. function largeUnary($stub)
  72. {
  73. performLargeUnary($stub);
  74. }
  75. /**
  76. * Shared code between large unary test and auth test.
  77. *
  78. * @param $stub Stub object that has service methods
  79. * @param $fillUsername boolean whether to fill result with username
  80. * @param $fillOauthScope boolean whether to fill result with oauth scope
  81. */
  82. function performLargeUnary($stub, $fillUsername = false, $fillOauthScope = false,
  83. $callback = false)
  84. {
  85. $request_len = 271828;
  86. $response_len = 314159;
  87. $request = new grpc\testing\SimpleRequest();
  88. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  89. $request->setResponseSize($response_len);
  90. $payload = new grpc\testing\Payload();
  91. $payload->setType(grpc\testing\PayloadType::COMPRESSABLE);
  92. $payload->setBody(str_repeat("\0", $request_len));
  93. $request->setPayload($payload);
  94. $request->setFillUsername($fillUsername);
  95. $request->setFillOauthScope($fillOauthScope);
  96. $options = false;
  97. if ($callback) {
  98. $options['call_credentials_callback'] = $callback;
  99. }
  100. list($result, $status) = $stub->UnaryCall($request, [], $options)->wait();
  101. hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
  102. hardAssert($result !== null, 'Call returned a null response');
  103. $payload = $result->getPayload();
  104. hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
  105. 'Payload had the wrong type');
  106. hardAssert(strlen($payload->getBody()) === $response_len,
  107. 'Payload had the wrong length');
  108. hardAssert($payload->getBody() === str_repeat("\0", $response_len),
  109. 'Payload had the wrong content');
  110. return $result;
  111. }
  112. /**
  113. * Run the service account credentials auth test.
  114. *
  115. * @param $stub Stub object that has service methods
  116. * @param $args array command line args
  117. */
  118. function serviceAccountCreds($stub, $args)
  119. {
  120. if (!array_key_exists('oauth_scope', $args)) {
  121. throw new Exception('Missing oauth scope');
  122. }
  123. $jsonKey = json_decode(
  124. file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
  125. true);
  126. $result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
  127. hardAssert($result->getUsername() == $jsonKey['client_email'],
  128. 'invalid email returned');
  129. hardAssert(strpos($args['oauth_scope'], $result->getOauthScope()) !== false,
  130. 'invalid oauth scope returned');
  131. }
  132. /**
  133. * Run the compute engine credentials auth test.
  134. * Has not been run from gcloud as of 2015-05-05.
  135. *
  136. * @param $stub Stub object that has service methods
  137. * @param $args array command line args
  138. */
  139. function computeEngineCreds($stub, $args)
  140. {
  141. if (!array_key_exists('oauth_scope', $args)) {
  142. throw new Exception('Missing oauth scope');
  143. }
  144. if (!array_key_exists('default_service_account', $args)) {
  145. throw new Exception('Missing default_service_account');
  146. }
  147. $result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
  148. hardAssert($args['default_service_account'] == $result->getUsername(),
  149. 'invalid email returned');
  150. }
  151. /**
  152. * Run the jwt token credentials auth test.
  153. *
  154. * @param $stub Stub object that has service methods
  155. * @param $args array command line args
  156. */
  157. function jwtTokenCreds($stub, $args)
  158. {
  159. $jsonKey = json_decode(
  160. file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
  161. true);
  162. $result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
  163. hardAssert($result->getUsername() == $jsonKey['client_email'],
  164. 'invalid email returned');
  165. }
  166. /**
  167. * Run the oauth2_auth_token auth test.
  168. *
  169. * @param $stub Stub object that has service methods
  170. * @param $args array command line args
  171. */
  172. function oauth2AuthToken($stub, $args)
  173. {
  174. $jsonKey = json_decode(
  175. file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
  176. true);
  177. $result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true);
  178. hardAssert($result->getUsername() == $jsonKey['client_email'],
  179. 'invalid email returned');
  180. }
  181. function updateAuthMetadataCallback($context)
  182. {
  183. $authUri = $context->service_url;
  184. $methodName = $context->method_name;
  185. $auth_credentials = ApplicationDefaultCredentials::getCredentials();
  186. $metadata = [];
  187. $result = $auth_credentials->updateMetadata([], $authUri);
  188. foreach ($result as $key => $value) {
  189. $metadata[strtolower($key)] = $value;
  190. }
  191. return $metadata;
  192. }
  193. /**
  194. * Run the per_rpc_creds auth test.
  195. *
  196. * @param $stub Stub object that has service methods
  197. * @param $args array command line args
  198. */
  199. function perRpcCreds($stub, $args)
  200. {
  201. $jsonKey = json_decode(
  202. file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
  203. true);
  204. $result = performLargeUnary($stub, $fillUsername = true, $fillOauthScope = true,
  205. 'updateAuthMetadataCallback');
  206. hardAssert($result->getUsername() == $jsonKey['client_email'],
  207. 'invalid email returned');
  208. }
  209. /**
  210. * Run the client_streaming test.
  211. *
  212. * @param $stub Stub object that has service methods
  213. */
  214. function clientStreaming($stub)
  215. {
  216. $request_lengths = [27182, 8, 1828, 45904];
  217. $requests = array_map(
  218. function ($length) {
  219. $request = new grpc\testing\StreamingInputCallRequest();
  220. $payload = new grpc\testing\Payload();
  221. $payload->setBody(str_repeat("\0", $length));
  222. $request->setPayload($payload);
  223. return $request;
  224. }, $request_lengths);
  225. $call = $stub->StreamingInputCall();
  226. foreach ($requests as $request) {
  227. $call->write($request);
  228. }
  229. list($result, $status) = $call->wait();
  230. hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully');
  231. hardAssert($result->getAggregatedPayloadSize() === 74922,
  232. 'aggregated_payload_size was incorrect');
  233. }
  234. /**
  235. * Run the server_streaming test.
  236. *
  237. * @param $stub Stub object that has service methods.
  238. */
  239. function serverStreaming($stub)
  240. {
  241. $sizes = [31415, 9, 2653, 58979];
  242. $request = new grpc\testing\StreamingOutputCallRequest();
  243. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  244. foreach ($sizes as $size) {
  245. $response_parameters = new grpc\testing\ResponseParameters();
  246. $response_parameters->setSize($size);
  247. $request->addResponseParameters($response_parameters);
  248. }
  249. $call = $stub->StreamingOutputCall($request);
  250. $i = 0;
  251. foreach ($call->responses() as $value) {
  252. hardAssert($i < 4, 'Too many responses');
  253. $payload = $value->getPayload();
  254. hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
  255. 'Payload '.$i.' had the wrong type');
  256. hardAssert(strlen($payload->getBody()) === $sizes[$i],
  257. 'Response '.$i.' had the wrong length');
  258. $i += 1;
  259. }
  260. hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
  261. 'Call did not complete successfully');
  262. }
  263. /**
  264. * Run the ping_pong test.
  265. *
  266. * @param $stub Stub object that has service methods.
  267. */
  268. function pingPong($stub)
  269. {
  270. $request_lengths = [27182, 8, 1828, 45904];
  271. $response_lengths = [31415, 9, 2653, 58979];
  272. $call = $stub->FullDuplexCall();
  273. for ($i = 0; $i < 4; ++$i) {
  274. $request = new grpc\testing\StreamingOutputCallRequest();
  275. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  276. $response_parameters = new grpc\testing\ResponseParameters();
  277. $response_parameters->setSize($response_lengths[$i]);
  278. $request->addResponseParameters($response_parameters);
  279. $payload = new grpc\testing\Payload();
  280. $payload->setBody(str_repeat("\0", $request_lengths[$i]));
  281. $request->setPayload($payload);
  282. $call->write($request);
  283. $response = $call->read();
  284. hardAssert($response !== null, 'Server returned too few responses');
  285. $payload = $response->getPayload();
  286. hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE,
  287. 'Payload '.$i.' had the wrong type');
  288. hardAssert(strlen($payload->getBody()) === $response_lengths[$i],
  289. 'Payload '.$i.' had the wrong length');
  290. }
  291. $call->writesDone();
  292. hardAssert($call->read() === null, 'Server returned too many responses');
  293. hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
  294. 'Call did not complete successfully');
  295. }
  296. /**
  297. * Run the empty_stream test.
  298. *
  299. * @param $stub Stub object that has service methods.
  300. */
  301. function emptyStream($stub)
  302. {
  303. $call = $stub->FullDuplexCall();
  304. $call->writesDone();
  305. hardAssert($call->read() === null, 'Server returned too many responses');
  306. hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
  307. 'Call did not complete successfully');
  308. }
  309. /**
  310. * Run the cancel_after_begin test.
  311. *
  312. * @param $stub Stub object that has service methods.
  313. */
  314. function cancelAfterBegin($stub)
  315. {
  316. $call = $stub->StreamingInputCall();
  317. $call->cancel();
  318. list($result, $status) = $call->wait();
  319. hardAssert($status->code === Grpc\STATUS_CANCELLED,
  320. 'Call status was not CANCELLED');
  321. }
  322. /**
  323. * Run the cancel_after_first_response test.
  324. *
  325. * @param $stub Stub object that has service methods.
  326. */
  327. function cancelAfterFirstResponse($stub)
  328. {
  329. $call = $stub->FullDuplexCall();
  330. $request = new grpc\testing\StreamingOutputCallRequest();
  331. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  332. $response_parameters = new grpc\testing\ResponseParameters();
  333. $response_parameters->setSize(31415);
  334. $request->addResponseParameters($response_parameters);
  335. $payload = new grpc\testing\Payload();
  336. $payload->setBody(str_repeat("\0", 27182));
  337. $request->setPayload($payload);
  338. $call->write($request);
  339. $response = $call->read();
  340. $call->cancel();
  341. hardAssert($call->getStatus()->code === Grpc\STATUS_CANCELLED,
  342. 'Call status was not CANCELLED');
  343. }
  344. function timeoutOnSleepingServer($stub)
  345. {
  346. $call = $stub->FullDuplexCall([], ['timeout' => 1000]);
  347. $request = new grpc\testing\StreamingOutputCallRequest();
  348. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  349. $response_parameters = new grpc\testing\ResponseParameters();
  350. $response_parameters->setSize(8);
  351. $request->addResponseParameters($response_parameters);
  352. $payload = new grpc\testing\Payload();
  353. $payload->setBody(str_repeat("\0", 9));
  354. $request->setPayload($payload);
  355. $call->write($request);
  356. $response = $call->read();
  357. hardAssert($call->getStatus()->code === Grpc\STATUS_DEADLINE_EXCEEDED,
  358. 'Call status was not DEADLINE_EXCEEDED');
  359. }
  360. function customMetadata($stub)
  361. {
  362. $ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial';
  363. $ECHO_INITIAL_VALUE = 'test_initial_metadata_value';
  364. $ECHO_TRAILING_KEY = 'x-grpc-test-echo-trailing-bin';
  365. $ECHO_TRAILING_VALUE = 'ababab';
  366. $request_len = 271828;
  367. $response_len = 314159;
  368. $request = new grpc\testing\SimpleRequest();
  369. $request->setResponseType(grpc\testing\PayloadType::COMPRESSABLE);
  370. $request->setResponseSize($response_len);
  371. $payload = new grpc\testing\Payload();
  372. $payload->setType(grpc\testing\PayloadType::COMPRESSABLE);
  373. $payload->setBody(str_repeat("\0", $request_len));
  374. $request->setPayload($payload);
  375. $metadata = [
  376. $ECHO_INITIAL_KEY => [$ECHO_INITIAL_VALUE],
  377. $ECHO_TRAILING_KEY => [$ECHO_TRAILING_VALUE],
  378. ];
  379. $call = $stub->UnaryCall($request, $metadata);
  380. $initial_metadata = $call->getMetadata();
  381. hardAssert(array_key_exists($ECHO_INITIAL_KEY, $initial_metadata),
  382. 'Initial metadata does not contain expected key');
  383. hardAssert($initial_metadata[$ECHO_INITIAL_KEY][0] ==
  384. $ECHO_INITIAL_VALUE,
  385. 'Incorrect initial metadata value');
  386. list($result, $status) = $call->wait();
  387. hardAssert($status->code === Grpc\STATUS_OK,
  388. 'Call did not complete successfully');
  389. $trailing_metadata = $call->getTrailingMetadata();
  390. hardAssert(array_key_exists($ECHO_TRAILING_KEY, $trailing_metadata),
  391. 'Trailing metadata does not contain expected key');
  392. hardAssert($trailing_metadata[$ECHO_TRAILING_KEY][0] ==
  393. $ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value');
  394. $streaming_call = $stub->FullDuplexCall($metadata);
  395. $streaming_request = new grpc\testing\StreamingOutputCallRequest();
  396. $streaming_request->setPayload($payload);
  397. $streaming_call->write($streaming_request);
  398. $streaming_call->writesDone();
  399. hardAssert($streaming_call->getStatus()->code === Grpc\STATUS_OK,
  400. 'Call did not complete successfully');
  401. $streaming_trailing_metadata = $streaming_call->getTrailingMetadata();
  402. hardAssert(array_key_exists($ECHO_TRAILING_KEY,
  403. $streaming_trailing_metadata),
  404. 'Trailing metadata does not contain expected key');
  405. hardAssert($streaming_trailing_metadata[$ECHO_TRAILING_KEY][0] ==
  406. $ECHO_TRAILING_VALUE, 'Incorrect trailing metadata value');
  407. }
  408. function statusCodeAndMessage($stub)
  409. {
  410. $echo_status = new grpc\testing\EchoStatus();
  411. $echo_status->setCode(2);
  412. $echo_status->setMessage('test status message');
  413. $request = new grpc\testing\SimpleRequest();
  414. $request->setResponseStatus($echo_status);
  415. $call = $stub->UnaryCall($request);
  416. list($result, $status) = $call->wait();
  417. hardAssert($status->code === 2,
  418. 'Received unexpected status code');
  419. hardAssert($status->details === 'test status message',
  420. 'Received unexpected status details');
  421. $streaming_call = $stub->FullDuplexCall();
  422. $streaming_request = new grpc\testing\StreamingOutputCallRequest();
  423. $streaming_request->setResponseStatus($echo_status);
  424. $streaming_call->write($streaming_request);
  425. $streaming_call->writesDone();
  426. $status = $streaming_call->getStatus();
  427. hardAssert($status->code === 2,
  428. 'Received unexpected status code');
  429. hardAssert($status->details === 'test status message',
  430. 'Received unexpected status details');
  431. }
  432. function unimplementedMethod($stub)
  433. {
  434. $call = $stub->UnimplementedCall(new grpc\testing\EmptyMessage());
  435. list($result, $status) = $call->wait();
  436. hardAssert($status->code === Grpc\STATUS_UNIMPLEMENTED,
  437. 'Received unexpected status code');
  438. }
  439. function _makeStub($args)
  440. {
  441. if (!array_key_exists('server_host', $args)) {
  442. throw new Exception('Missing argument: --server_host is required');
  443. }
  444. if (!array_key_exists('server_port', $args)) {
  445. throw new Exception('Missing argument: --server_port is required');
  446. }
  447. if (!array_key_exists('test_case', $args)) {
  448. throw new Exception('Missing argument: --test_case is required');
  449. }
  450. if ($args['server_port'] == 443) {
  451. $server_address = $args['server_host'];
  452. } else {
  453. $server_address = $args['server_host'].':'.$args['server_port'];
  454. }
  455. $test_case = $args['test_case'];
  456. $host_override = 'foo.test.google.fr';
  457. if (array_key_exists('server_host_override', $args)) {
  458. $host_override = $args['server_host_override'];
  459. }
  460. $use_tls = false;
  461. if (array_key_exists('use_tls', $args) &&
  462. $args['use_tls'] != 'false') {
  463. $use_tls = true;
  464. }
  465. $use_test_ca = false;
  466. if (array_key_exists('use_test_ca', $args) &&
  467. $args['use_test_ca'] != 'false') {
  468. $use_test_ca = true;
  469. }
  470. $opts = [];
  471. if ($use_tls) {
  472. if ($use_test_ca) {
  473. $ssl_credentials = Grpc\ChannelCredentials::createSsl(
  474. file_get_contents(dirname(__FILE__).'/../data/ca.pem'));
  475. } else {
  476. $ssl_credentials = Grpc\ChannelCredentials::createSsl();
  477. }
  478. $opts['credentials'] = $ssl_credentials;
  479. $opts['grpc.ssl_target_name_override'] = $host_override;
  480. } else {
  481. $opts['credentials'] = Grpc\ChannelCredentials::createInsecure();
  482. }
  483. if (in_array($test_case, ['service_account_creds',
  484. 'compute_engine_creds', 'jwt_token_creds', ])) {
  485. if ($test_case == 'jwt_token_creds') {
  486. $auth_credentials = ApplicationDefaultCredentials::getCredentials();
  487. } else {
  488. $auth_credentials = ApplicationDefaultCredentials::getCredentials(
  489. $args['oauth_scope']
  490. );
  491. }
  492. $opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc();
  493. }
  494. if ($test_case == 'oauth2_auth_token') {
  495. $auth_credentials = ApplicationDefaultCredentials::getCredentials(
  496. $args['oauth_scope']
  497. );
  498. $token = $auth_credentials->fetchAuthToken();
  499. $update_metadata =
  500. function ($metadata,
  501. $authUri = null,
  502. ClientInterface $client = null) use ($token) {
  503. $metadata_copy = $metadata;
  504. $metadata_copy[CredentialsLoader::AUTH_METADATA_KEY] =
  505. [sprintf('%s %s',
  506. $token['token_type'],
  507. $token['access_token'])];
  508. return $metadata_copy;
  509. };
  510. $opts['update_metadata'] = $update_metadata;
  511. }
  512. if ($test_case == 'unimplemented_method') {
  513. $stub = new grpc\testing\UnimplementedServiceClient($server_address, $opts);
  514. } else {
  515. $stub = new grpc\testing\TestServiceClient($server_address, $opts);
  516. }
  517. return $stub;
  518. }
  519. function interop_main($args, $stub = false)
  520. {
  521. if (!$stub) {
  522. $stub = _makeStub($args);
  523. }
  524. $test_case = $args['test_case'];
  525. echo "Running test case $test_case\n";
  526. switch ($test_case) {
  527. case 'empty_unary':
  528. emptyUnary($stub);
  529. break;
  530. case 'large_unary':
  531. largeUnary($stub);
  532. break;
  533. case 'client_streaming':
  534. clientStreaming($stub);
  535. break;
  536. case 'server_streaming':
  537. serverStreaming($stub);
  538. break;
  539. case 'ping_pong':
  540. pingPong($stub);
  541. break;
  542. case 'empty_stream':
  543. emptyStream($stub);
  544. break;
  545. case 'cancel_after_begin':
  546. cancelAfterBegin($stub);
  547. break;
  548. case 'cancel_after_first_response':
  549. cancelAfterFirstResponse($stub);
  550. break;
  551. case 'timeout_on_sleeping_server':
  552. timeoutOnSleepingServer($stub);
  553. break;
  554. case 'custom_metadata':
  555. customMetadata($stub);
  556. break;
  557. case 'status_code_and_message':
  558. statusCodeAndMessage($stub);
  559. break;
  560. case 'unimplemented_method':
  561. unimplementedMethod($stub);
  562. break;
  563. case 'service_account_creds':
  564. serviceAccountCreds($stub, $args);
  565. break;
  566. case 'compute_engine_creds':
  567. computeEngineCreds($stub, $args);
  568. break;
  569. case 'jwt_token_creds':
  570. jwtTokenCreds($stub, $args);
  571. break;
  572. case 'oauth2_auth_token':
  573. oauth2AuthToken($stub, $args);
  574. break;
  575. case 'per_rpc_creds':
  576. perRpcCreds($stub, $args);
  577. break;
  578. default:
  579. echo "Unsupported test case $test_case\n";
  580. exit(1);
  581. }
  582. return $stub;
  583. }
  584. if (isset($_SERVER['PHP_SELF']) && preg_match('/interop_client/', $_SERVER['PHP_SELF'])) {
  585. $args = getopt('', ['server_host:', 'server_port:', 'test_case:',
  586. 'use_tls::', 'use_test_ca::',
  587. 'server_host_override:', 'oauth_scope:',
  588. 'default_service_account:', ]);
  589. interop_main($args);
  590. }