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

Side by Side Diff: third_party/grpc/src/php/tests/unit_tests/SecureEndToEndTest.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, 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 class SecureEndToEndTest extends PHPUnit_Framework_TestCase
35 {
36 public function setUp()
37 {
38 $credentials = Grpc\ChannelCredentials::createSsl(
39 file_get_contents(dirname(__FILE__).'/../data/ca.pem'));
40 $server_credentials = Grpc\ServerCredentials::createSsl(
41 null,
42 file_get_contents(dirname(__FILE__).'/../data/server1.key'),
43 file_get_contents(dirname(__FILE__).'/../data/server1.pem'));
44 $this->server = new Grpc\Server();
45 $this->port = $this->server->addSecureHttp2Port('0.0.0.0:0',
46 $server_credentials);
47 $this->server->start();
48 $this->host_override = 'foo.test.google.fr';
49 $this->channel = new Grpc\Channel(
50 'localhost:'.$this->port,
51 [
52 'grpc.ssl_target_name_override' => $this->host_override,
53 'grpc.default_authority' => $this->host_override,
54 'credentials' => $credentials,
55 ]
56 );
57 }
58
59 public function tearDown()
60 {
61 unset($this->channel);
62 unset($this->server);
63 }
64
65 public function testSimpleRequestBody()
66 {
67 $deadline = Grpc\Timeval::infFuture();
68 $status_text = 'xyz';
69 $call = new Grpc\Call($this->channel,
70 'dummy_method',
71 $deadline,
72 $this->host_override);
73
74 $event = $call->startBatch([
75 Grpc\OP_SEND_INITIAL_METADATA => [],
76 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
77 ]);
78
79 $this->assertTrue($event->send_metadata);
80 $this->assertTrue($event->send_close);
81
82 $event = $this->server->requestCall();
83 $this->assertSame('dummy_method', $event->method);
84 $server_call = $event->call;
85
86 $event = $server_call->startBatch([
87 Grpc\OP_SEND_INITIAL_METADATA => [],
88 Grpc\OP_SEND_STATUS_FROM_SERVER => [
89 'metadata' => [],
90 'code' => Grpc\STATUS_OK,
91 'details' => $status_text,
92 ],
93 Grpc\OP_RECV_CLOSE_ON_SERVER => true,
94 ]);
95
96 $this->assertTrue($event->send_metadata);
97 $this->assertTrue($event->send_status);
98 $this->assertFalse($event->cancelled);
99
100 $event = $call->startBatch([
101 Grpc\OP_RECV_INITIAL_METADATA => true,
102 Grpc\OP_RECV_STATUS_ON_CLIENT => true,
103 ]);
104
105 $this->assertSame([], $event->metadata);
106 $status = $event->status;
107 $this->assertSame([], $status->metadata);
108 $this->assertSame(Grpc\STATUS_OK, $status->code);
109 $this->assertSame($status_text, $status->details);
110
111 unset($call);
112 unset($server_call);
113 }
114
115 public function testMessageWriteFlags()
116 {
117 $deadline = Grpc\Timeval::infFuture();
118 $req_text = 'message_write_flags_test';
119 $status_text = 'xyz';
120 $call = new Grpc\Call($this->channel,
121 'dummy_method',
122 $deadline,
123 $this->host_override);
124
125 $event = $call->startBatch([
126 Grpc\OP_SEND_INITIAL_METADATA => [],
127 Grpc\OP_SEND_MESSAGE => ['message' => $req_text,
128 'flags' => Grpc\WRITE_NO_COMPRESS, ],
129 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
130 ]);
131
132 $this->assertTrue($event->send_metadata);
133 $this->assertTrue($event->send_close);
134
135 $event = $this->server->requestCall();
136 $this->assertSame('dummy_method', $event->method);
137 $server_call = $event->call;
138
139 $event = $server_call->startBatch([
140 Grpc\OP_SEND_INITIAL_METADATA => [],
141 Grpc\OP_SEND_STATUS_FROM_SERVER => [
142 'metadata' => [],
143 'code' => Grpc\STATUS_OK,
144 'details' => $status_text,
145 ],
146 ]);
147
148 $event = $call->startBatch([
149 Grpc\OP_RECV_INITIAL_METADATA => true,
150 Grpc\OP_RECV_STATUS_ON_CLIENT => true,
151 ]);
152
153 $this->assertSame([], $event->metadata);
154 $status = $event->status;
155 $this->assertSame([], $status->metadata);
156 $this->assertSame(Grpc\STATUS_OK, $status->code);
157 $this->assertSame($status_text, $status->details);
158
159 unset($call);
160 unset($server_call);
161 }
162
163 public function testClientServerFullRequestResponse()
164 {
165 $deadline = Grpc\Timeval::infFuture();
166 $req_text = 'client_server_full_request_response';
167 $reply_text = 'reply:client_server_full_request_response';
168 $status_text = 'status:client_server_full_response_text';
169
170 $call = new Grpc\Call($this->channel,
171 'dummy_method',
172 $deadline,
173 $this->host_override);
174
175 $event = $call->startBatch([
176 Grpc\OP_SEND_INITIAL_METADATA => [],
177 Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
178 Grpc\OP_SEND_MESSAGE => ['message' => $req_text],
179 ]);
180
181 $this->assertTrue($event->send_metadata);
182 $this->assertTrue($event->send_close);
183 $this->assertTrue($event->send_message);
184
185 $event = $this->server->requestCall();
186 $this->assertSame('dummy_method', $event->method);
187 $server_call = $event->call;
188
189 $event = $server_call->startBatch([
190 Grpc\OP_SEND_INITIAL_METADATA => [],
191 Grpc\OP_SEND_MESSAGE => ['message' => $reply_text],
192 Grpc\OP_SEND_STATUS_FROM_SERVER => [
193 'metadata' => [],
194 'code' => Grpc\STATUS_OK,
195 'details' => $status_text,
196 ],
197 Grpc\OP_RECV_MESSAGE => true,
198 Grpc\OP_RECV_CLOSE_ON_SERVER => true,
199 ]);
200
201 $this->assertTrue($event->send_metadata);
202 $this->assertTrue($event->send_status);
203 $this->assertTrue($event->send_message);
204 $this->assertFalse($event->cancelled);
205 $this->assertSame($req_text, $event->message);
206
207 $event = $call->startBatch([
208 Grpc\OP_RECV_INITIAL_METADATA => true,
209 Grpc\OP_RECV_MESSAGE => true,
210 Grpc\OP_RECV_STATUS_ON_CLIENT => true,
211 ]);
212
213 $this->assertSame([], $event->metadata);
214 $this->assertSame($reply_text, $event->message);
215 $status = $event->status;
216 $this->assertSame([], $status->metadata);
217 $this->assertSame(Grpc\STATUS_OK, $status->code);
218 $this->assertSame($status_text, $status->details);
219
220 unset($call);
221 unset($server_call);
222 }
223 }
OLDNEW
« no previous file with comments | « third_party/grpc/src/php/tests/unit_tests/EndToEndTest.php ('k') | third_party/grpc/src/php/tests/unit_tests/ServerTest.php » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698