aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/interop
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-10-15 11:00:50 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-10-15 11:00:50 -0700
commitba0cb56b32921f16e082d0dff072720b68743304 (patch)
tree86de063f77ca63b0ea1042d782766c0b12e677c9 /src/php/tests/interop
parentca7ed0f9906235ace9dce61095119876da2d13bf (diff)
php: add use_tls and use_test_ca param to interop tests script
Diffstat (limited to 'src/php/tests/interop')
-rwxr-xr-xsrc/php/tests/interop/interop_client.php79
1 files changed, 51 insertions, 28 deletions
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 1f903053a7..3233a816ea 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -36,6 +36,8 @@ require 'empty.php';
require 'message_set.php';
require 'messages.php';
require 'test.php';
+use Google\Auth\CredentialsLoader;
+use Google\Auth\ApplicationDefaultCredentials;
/**
* Assertion function that always exits with an error code if the assertion is
@@ -114,7 +116,7 @@ function serviceAccountCreds($stub, $args) {
throw new Exception('Missing oauth scope');
}
$jsonKey = json_decode(
- file_get_contents(getenv(Google\Auth\CredentialsLoader::ENV_VAR)),
+ file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername=true, $fillOauthScope=true);
hardAssert($result->getUsername() == $jsonKey['client_email'],
@@ -149,7 +151,7 @@ function computeEngineCreds($stub, $args) {
*/
function jwtTokenCreds($stub, $args) {
$jsonKey = json_decode(
- file_get_contents(getenv(Google\Auth\CredentialsLoader::ENV_VAR)),
+ file_get_contents(getenv(CredentialsLoader::ENV_VAR)),
true);
$result = performLargeUnary($stub, $fillUsername=true, $fillOauthScope=true);
hardAssert($result->getUsername() == $jsonKey['client_email'],
@@ -319,12 +321,17 @@ function timeoutOnSleepingServer($stub) {
}
$args = getopt('', array('server_host:', 'server_port:', 'test_case:',
+ 'use_tls::', 'use_test_ca::',
'server_host_override:', 'oauth_scope:',
'default_service_account:'));
-if (!array_key_exists('server_host', $args) ||
- !array_key_exists('server_port', $args) ||
- !array_key_exists('test_case', $args)) {
- throw new Exception('Missing argument');
+if (!array_key_exists('server_host', $args)) {
+ throw new Exception('Missing argument: --server_host is required');
+}
+if (!array_key_exists('server_port', $args)) {
+ throw new Exception('Missing argument: --server_port is required');
+}
+if (!array_key_exists('test_case', $args)) {
+ throw new Exception('Missing argument: --test_case is required');
}
if ($args['server_port'] == 443) {
@@ -333,41 +340,57 @@ if ($args['server_port'] == 443) {
$server_address = $args['server_host'] . ':' . $args['server_port'];
}
-if (!array_key_exists('server_host_override', $args)) {
- $args['server_host_override'] = 'foo.test.google.fr';
+$test_case = $args['test_case'];
+
+$host_override = 'foo.test.google.fr';
+if (array_key_exists('server_host_override', $args)) {
+ $host_override = $args['server_host_override'];
+}
+
+$use_tls = false;
+if (array_key_exists('use_tls', $args) &&
+ $args['use_tls'] != 'false') {
+ $use_tls = true;
}
-$ssl_cert_file = getenv('SSL_CERT_FILE');
-if (!$ssl_cert_file) {
- $ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem';
+$use_test_ca = false;
+if (array_key_exists('use_test_ca', $args) &&
+ $args['use_test_ca'] != 'false') {
+ $use_test_ca = true;
}
-$credentials = Grpc\Credentials::createSsl(file_get_contents($ssl_cert_file));
+$opts = [];
-$opts = [
- 'grpc.ssl_target_name_override' => $args['server_host_override'],
- 'credentials' => $credentials,
- ];
+if ($use_tls) {
+ if ($use_test_ca) {
+ $ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem';
+ } else {
+ $ssl_cert_file = getenv('SSL_CERT_FILE');
+ }
+ $ssl_credentials = Grpc\Credentials::createSsl(
+ file_get_contents($ssl_cert_file));
+ $opts['credentials'] = $ssl_credentials;
+ $opts['grpc.ssl_target_name_override'] = $host_override;
+}
-if (in_array($args['test_case'], array(
- 'service_account_creds',
- 'compute_engine_creds',
- 'jwt_token_creds'))) {
- if ($args['test_case'] == 'jwt_token_creds') {
- $auth = Google\Auth\ApplicationDefaultCredentials::getCredentials();
+if (in_array($test_case, array('service_account_creds',
+ 'compute_engine_creds', 'jwt_token_creds'))) {
+ if ($test_case == 'jwt_token_creds') {
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials();
} else {
- $auth = Google\Auth\ApplicationDefaultCredentials::getCredentials(
- $args['oauth_scope']);
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials(
+ $args['oauth_scope']
+ );
}
- $opts['update_metadata'] = $auth->getUpdateMetadataFunc();
+ $opts['update_metadata'] = $auth_credentials->getUpdateMetadataFunc();
}
$stub = new grpc\testing\TestServiceClient($server_address, $opts);
echo "Connecting to $server_address\n";
-echo "Running test case $args[test_case]\n";
+echo "Running test case $test_case\n";
-switch ($args['test_case']) {
+switch ($test_case) {
case 'empty_unary':
emptyUnary($stub);
break;
@@ -405,6 +428,6 @@ switch ($args['test_case']) {
jwtTokenCreds($stub, $args);
break;
default:
- echo "Unsupported test case $args[test_case]\n";
+ echo "Unsupported test case $test_case\n";
exit(1);
}