Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
test both insecure&secure channel
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahShiSFB committed Feb 5, 2021
1 parent 185e803 commit 89d28e7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/php/bin/run_gen_code_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set -e
cd $(dirname $0)
source ./determine_extension_dir.sh
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 \
../tests/generated_code/GeneratedCodeTest.php
php $extension_dir -d max_execution_time=300 $(which phpunit) -v --debug \
Expand Down
26 changes: 15 additions & 11 deletions src/php/tests/generated_code/AbstractGeneratedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,33 @@ public function testCancel()
public function testCallCredentialsCallback()
{
$div_arg = new Math\DivArgs();
$div_arg->setDividend(7);
$div_arg->setDivisor(4);
$call = self::$client->Div($div_arg, array(), array(
'call_credentials_callback' => function ($context) {
return array();
},
));
$call->cancel();
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();
$call = self::$client->Div($div_arg);
$call_credentials = Grpc\CallCredentials::createFromPlugin(
function ($context) {
$div_arg->setDividend(7);
$div_arg->setDivisor(4);
$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();
}
);
$call->setCallCredentials($call_credentials);
$call->cancel();
},
));
list($response, $status) = $call->wait();
$this->assertSame(\Grpc\STATUS_CANCELLED, $status->code);
$this->assertSame(\Grpc\STATUS_UNAUTHENTICATED, $status->code);
}

public function testInvalidMethodName()
Expand Down
5 changes: 4 additions & 1 deletion src/php/tests/generated_code/GeneratedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public function setUp(): void
{
self::$client = new Math\MathClient(
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',

]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function setUp(): void
{
self::$client = new Math\MathClient(
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,
$client = []) {
$a_copy = $a_hash;
Expand Down
7 changes: 6 additions & 1 deletion src/php/tests/generated_code/math_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ function main() {
Sum: Sum,
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();
}

Expand Down

0 comments on commit 89d28e7

Please sign in to comment.