Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: third_party/grpc/src/php/tests/unit_tests/CallCredentials2Test.php

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
35 class CallCredentials2Test extends PHPUnit_Framework_TestCase
36 {
37 public function setUp()
38 {
39 $credentials = Grpc\ChannelCredentials::createSsl(
40 file_get_contents(dirname(__FILE__).'/../data/ca.pem'));
41 $server_credentials = Grpc\ServerCredentials::createSsl(
42 null,
43 file_get_contents(dirname(__FILE__).'/../data/server1.key'),
44 file_get_contents(dirname(__FILE__).'/../data/server1.pem'));
45 $this->server = new Grpc\Server();
46 $this->port = $this->server->addSecureHttp2Port('0.0.0.0:0',
47 $server_credentials);
48 $this->server->start();
49 $this->host_override = 'foo.test.google.fr';
50 $this->channel = new Grpc\Channel(
51 'localhost:'.$this->port,
52 [
53 'grpc.ssl_target_name_override' => $this->host_override,
54 'grpc.default_authority' => $this->host_override,
55 'credentials' => $credentials,
56 ]
57 );
58 }
59
60 public function tearDown()
61 {
62 unset($this->channel);
63 unset($this->server);
64 }
65
66 public function callbackFunc($context)
67 {
68 $this->assertTrue(is_string($context->service_url));
69 $this->assertTrue(is_string($context->method_name));
70
71 return ['k1' => ['v1'], 'k2' => ['v2']];
72 }
73
74 public function testCreateFromPlugin()
75 {
76 $deadline = Grpc\Timeval::infFuture();
77 $status_text = 'xyz';
78 $call = new Grpc\Call($this->channel,
79 '/abc/dummy_method',
80 $deadline,
81 $this->host_override);
82
83 $call_credentials = Grpc\CallCredentials::createFromPlugin(
84 array($this, 'callbackFunc'));
85 $call->setCredentials($call_credentials);
86
87 $event = $call->startBatch([
88 Grpc\OP_SEND_INITIAL_METADATA => [],
89 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
90 ]);
91
92 $this->assertTrue($event->send_metadata);
93 $this->assertTrue($event->send_close);
94
95 $event = $this->server->requestCall();
96
97 $this->assertTrue(is_array($event->metadata));
98 $metadata = $event->metadata;
99 $this->assertTrue(array_key_exists('k1', $metadata));
100 $this->assertTrue(array_key_exists('k2', $metadata));
101 $this->assertSame($metadata['k1'], ['v1']);
102 $this->assertSame($metadata['k2'], ['v2']);
103
104 $this->assertSame('/abc/dummy_method', $event->method);
105 $server_call = $event->call;
106
107 $event = $server_call->startBatch([
108 Grpc\OP_SEND_INITIAL_METADATA => [],
109 Grpc\OP_SEND_STATUS_FROM_SERVER => [
110 'metadata' => [],
111 'code' => Grpc\STATUS_OK,
112 'details' => $status_text,
113 ],
114 Grpc\OP_RECV_CLOSE_ON_SERVER => true,
115 ]);
116
117 $this->assertTrue($event->send_metadata);
118 $this->assertTrue($event->send_status);
119 $this->assertFalse($event->cancelled);
120
121 $event = $call->startBatch([
122 Grpc\OP_RECV_INITIAL_METADATA => true,
123 Grpc\OP_RECV_STATUS_ON_CLIENT => true,
124 ]);
125
126 $this->assertSame([], $event->metadata);
127 $status = $event->status;
128 $this->assertSame([], $status->metadata);
129 $this->assertSame(Grpc\STATUS_OK, $status->code);
130 $this->assertSame($status_text, $status->details);
131
132 unset($call);
133 unset($server_call);
134 }
135 }
OLDNEW
« no previous file with comments | « third_party/grpc/src/php/tests/interop/test.proto ('k') | third_party/grpc/src/php/tests/unit_tests/CallCredentials3Test.php » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698