php: add use_tls and use_test_ca param to interop tests script
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 1f90305..3233a81 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -36,6 +36,8 @@
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 @@
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 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 @@
}
$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 @@
$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'];
}
-$ssl_cert_file = getenv('SSL_CERT_FILE');
-if (!$ssl_cert_file) {
- $ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem';
+$use_tls = false;
+if (array_key_exists('use_tls', $args) &&
+ $args['use_tls'] != 'false') {
+ $use_tls = true;
}
-$credentials = Grpc\Credentials::createSsl(file_get_contents($ssl_cert_file));
+$use_test_ca = false;
+if (array_key_exists('use_test_ca', $args) &&
+ $args['use_test_ca'] != 'false') {
+ $use_test_ca = true;
+}
-$opts = [
- 'grpc.ssl_target_name_override' => $args['server_host_override'],
- 'credentials' => $credentials,
- ];
+$opts = [];
-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 ($use_tls) {
+ if ($use_test_ca) {
+ $ssl_cert_file = dirname(__FILE__) . '/../data/ca.pem';
} else {
- $auth = Google\Auth\ApplicationDefaultCredentials::getCredentials(
- $args['oauth_scope']);
+ $ssl_cert_file = getenv('SSL_CERT_FILE');
}
- $opts['update_metadata'] = $auth->getUpdateMetadataFunc();
+ $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($test_case, array('service_account_creds',
+ 'compute_engine_creds', 'jwt_token_creds'))) {
+ if ($test_case == 'jwt_token_creds') {
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials();
+ } else {
+ $auth_credentials = ApplicationDefaultCredentials::getCredentials(
+ $args['oauth_scope']
+ );
+ }
+ $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 @@
jwtTokenCreds($stub, $args);
break;
default:
- echo "Unsupported test case $args[test_case]\n";
+ echo "Unsupported test case $test_case\n";
exit(1);
}