test both insecure&secure channel

pull/25303/head
Hannah Shi 4 years ago
parent 185e80373a
commit 89d28e7dc9
  1. 2
      src/php/bin/run_gen_code_test.sh
  2. 26
      src/php/tests/generated_code/AbstractGeneratedCodeTest.php
  3. 5
      src/php/tests/generated_code/GeneratedCodeTest.php
  4. 4
      src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php
  5. 7
      src/php/tests/generated_code/math_server.js

@ -17,6 +17,8 @@ set -e
cd $(dirname $0) cd $(dirname $0)
source ./determine_extension_dir.sh source ./determine_extension_dir.sh
export GRPC_TEST_HOST=localhost:50051 export GRPC_TEST_HOST=localhost:50051
export GRPC_TEST_INSECURE_HOST=localhost:50052
php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \ php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \
../tests/generated_code/GeneratedCodeTest.php ../tests/generated_code/GeneratedCodeTest.php
php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \ php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \

@ -134,29 +134,33 @@ abstract class AbstractGeneratedCodeTest extends \PHPUnit\Framework\TestCase
public function testCallCredentialsCallback() public function testCallCredentialsCallback()
{ {
$div_arg = new Math\DivArgs(); $div_arg = new Math\DivArgs();
$div_arg->setDividend(7);
$div_arg->setDivisor(4);
$call = self::$client->Div($div_arg, array(), array( $call = self::$client->Div($div_arg, array(), array(
'call_credentials_callback' => function ($context) { 'call_credentials_callback' => function ($context) {
return array(); return array();
}, },
)); ));
$call->cancel();
list($response, $status) = $call->wait(); list($response, $status) = $call->wait();
$this->assertSame(\Grpc\STATUS_CANCELLED, $status->code); $this->assertSame(\Grpc\STATUS_OK, $status->code);
} }
public function testCallCredentialsCallback2() public function testInsecureChannelCallCredentialsCallback()
{ {
$div_arg = new Math\DivArgs(); $div_arg = new Math\DivArgs();
$call = self::$client->Div($div_arg); $div_arg->setDividend(7);
$call_credentials = Grpc\CallCredentials::createFromPlugin( $div_arg->setDivisor(4);
function ($context) { $client = new Math\MathClient(
getenv('GRPC_TEST_INSECURE_HOST'), [
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);
$call = $client->Div($div_arg, array(), array(
'call_credentials_callback' => function ($context) {
return array(); return array();
} },
); ));
$call->setCallCredentials($call_credentials);
$call->cancel();
list($response, $status) = $call->wait(); list($response, $status) = $call->wait();
$this->assertSame(\Grpc\STATUS_CANCELLED, $status->code); $this->assertSame(\Grpc\STATUS_UNAUTHENTICATED, $status->code);
} }
public function testInvalidMethodName() public function testInvalidMethodName()

@ -24,7 +24,10 @@ class GeneratedCodeTest extends AbstractGeneratedCodeTest
{ {
self::$client = new Math\MathClient( self::$client = new Math\MathClient(
getenv('GRPC_TEST_HOST'), [ getenv('GRPC_TEST_HOST'), [
'credentials' => Grpc\ChannelCredentials::createInsecure(), 'credentials' => Grpc\ChannelCredentials::createSsl(
file_get_contents(dirname(__FILE__).'/../data/ca.pem')),
'grpc.ssl_target_name_override' => 'foo.test.google.fr',
]); ]);
} }

@ -24,7 +24,9 @@ class GeneratedCodeWithCallbackTest extends AbstractGeneratedCodeTest
{ {
self::$client = new Math\MathClient( self::$client = new Math\MathClient(
getenv('GRPC_TEST_HOST'), getenv('GRPC_TEST_HOST'),
['credentials' => Grpc\ChannelCredentials::createInsecure(), ['credentials' => Grpc\ChannelCredentials::createSsl(
file_get_contents(dirname(__FILE__).'/../data/ca.pem')),
'grpc.ssl_target_name_override' => 'foo.test.google.fr',
'update_metadata' => function ($a_hash, 'update_metadata' => function ($a_hash,
$client = []) { $client = []) {
$a_copy = $a_hash; $a_copy = $a_hash;

@ -120,7 +120,12 @@ function main() {
Sum: Sum, Sum: Sum,
DivMany: DivMany, DivMany: DivMany,
}); });
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); server.bind('0.0.0.0:50052', grpc.ServerCredentials.createInsecure());
var fs = require('fs');
var key_data = fs.readFileSync(__dirname + '/../data/server1.key');
var pem_data = fs.readFileSync(__dirname + '/../data/server1.pem');
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createSsl(null, [{private_key: key_data,
cert_chain: pem_data}]));
server.start(); server.start();
} }

Loading…
Cancel
Save