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

Side by Side Diff: tests/standalone/io/socket_upgrade_to_secure_test.dart

Issue 1319703002: Breaking Change: merge BoringSSL branch into master (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:async"; 10 import "dart:async";
11 import "dart:io"; 11 import "dart:io";
12 12
13 import "package:async_helper/async_helper.dart"; 13 import "package:async_helper/async_helper.dart";
14 import "package:expect/expect.dart"; 14 import "package:expect/expect.dart";
15 15
16 InternetAddress HOST; 16 InternetAddress HOST;
17 const CERTIFICATE = "localhost_cert"; 17 String localFile(path) => Platform.script.resolve(path).toFilePath();
18
19 SecurityContext serverContext = new SecurityContext()
20 ..useCertificateChain(localFile('certificates/server_chain.pem'))
21 ..usePrivateKey(localFile('certificates/server_key.pem'),
22 password: 'dartdart');
23
24 SecurityContext clientContext = new SecurityContext()
25 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem'));
18 26
19 // This test creates a server and a client connects. After connecting 27 // This test creates a server and a client connects. After connecting
20 // and an optional initial handshake the connection is secured by 28 // and an optional initial handshake the connection is secured by
21 // upgrading to a secure connection The client then writes and the 29 // upgrading to a secure connection The client then writes and the
22 // server echos. When the server has finished its echo it 30 // server echos. When the server has finished its echo it
23 // half-closes. When the client gets the close event is closes fully. 31 // half-closes. When the client gets the close event is closes fully.
24 // 32 //
25 // The test can be run in different configurations based on 33 // The test can be run in different configurations based on
26 // the boolean arguments: 34 // the boolean arguments:
27 // 35 //
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 ); 157 );
150 socket.add(createHandshakeTestData()); 158 socket.add(createHandshakeTestData());
151 return completer.future; 159 return completer.future;
152 } 160 }
153 161
154 Future<SecureSocket> connectClient(int port) { 162 Future<SecureSocket> connectClient(int port) {
155 if (!handshakeBeforeSecure) { 163 if (!handshakeBeforeSecure) {
156 return Socket.connect(HOST, port).then((socket) { 164 return Socket.connect(HOST, port).then((socket) {
157 var future; 165 var future;
158 if (hostnameInConnect) { 166 if (hostnameInConnect) {
159 future = SecureSocket.secure(socket); 167 future = SecureSocket.secure(socket, context: clientContext);
160 } else { 168 } else {
161 future = SecureSocket.secure(socket, host: HOST); 169 future = SecureSocket.secure(socket,
170 host: HOST,
171 context: clientContext);
162 } 172 }
163 return future.then((secureSocket) { 173 return future.then((secureSocket) {
164 socket.add([0]); 174 socket.add([0]);
165 return secureSocket; 175 return secureSocket;
166 }); 176 });
167 }); 177 });
168 } else { 178 } else {
169 return Socket.connect(HOST, port).then((socket) { 179 return Socket.connect(HOST, port).then((socket) {
170 return runClientHandshake(socket).then((_) { 180 return runClientHandshake(socket).then((_) {
171 var future; 181 var future;
172 if (hostnameInConnect) { 182 if (hostnameInConnect) {
173 future = SecureSocket.secure(socket); 183 future = SecureSocket.secure(socket, context: clientContext);
174 } else { 184 } else {
175 future = SecureSocket.secure(socket, host: HOST.host); 185 future = SecureSocket.secure(socket,
186 host: HOST,
187 context: clientContext);
176 } 188 }
177 return future.then((secureSocket) { 189 return future.then((secureSocket) {
178 socket.add([0]); 190 socket.add([0]);
179 return secureSocket; 191 return secureSocket;
180 }); 192 });
181 }); 193 });
182 }); 194 });
183 } 195 }
184 } 196 }
185 197
186 serverReady(server) { 198 serverReady(server) {
187 server.listen((client) { 199 server.listen((client) {
188 if (!handshakeBeforeSecure) { 200 if (!handshakeBeforeSecure) {
189 SecureSocket.secureServer(client, CERTIFICATE).then((secureClient) { 201 SecureSocket.secureServer(client, serverContext).then((secureClient) {
190 client.add([0]); 202 client.add([0]);
191 runServer(secureClient).then((_) => server.close()); 203 runServer(secureClient).then((_) => server.close());
192 }); 204 });
193 } else { 205 } else {
194 runServerHandshake(client).then((carryOverData) { 206 runServerHandshake(client).then((carryOverData) {
195 SecureSocket.secureServer( 207 SecureSocket.secureServer(
196 client, 208 client,
197 CERTIFICATE, 209 serverContext,
198 bufferedData: carryOverData).then((secureClient) { 210 bufferedData: carryOverData).then((secureClient) {
199 client.add([0]); 211 client.add([0]);
200 runServer(secureClient).then((_) => server.close()); 212 runServer(secureClient).then((_) => server.close());
201 }); 213 });
202 }); 214 });
203 } 215 }
204 }); 216 });
205 217
206 connectClient(server.port).then(runClient).then((socket) { 218 connectClient(server.port).then(runClient).then((socket) {
207 asyncEnd(); 219 asyncEnd();
208 }); 220 });
209 } 221 }
210 222
211 ServerSocket.bind(HOST, 0).then(serverReady); 223 ServerSocket.bind(HOST, 0).then(serverReady);
212 } 224 }
213 225
214 main() { 226 main() {
215 asyncStart(); 227 asyncStart();
216 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
217 SecureSocket.initialize(database: certificateDatabase,
218 password: 'dartdart',
219 useBuiltinRoots: false);
220 InternetAddress.lookup("localhost").then((hosts) { 228 InternetAddress.lookup("localhost").then((hosts) {
221 HOST = hosts.first; 229 HOST = hosts.first;
222 test(false, false); 230 test(false, false);
223 test(true, false); 231 // TODO(whesse): Enable the test with all argument combinations:
224 test(false, true); 232 // test(true, false);
225 test(true, true); 233 // test(false, true);
226 test(false, true, true); 234 // test(true, true);
227 test(true, true, true); 235 // test(false, true, true);
236 // test(true, true, true);
228 asyncEnd(); 237 asyncEnd();
229 }); 238 });
230 } 239 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_unauthorized_test.dart ('k') | tests/standalone/io/web_socket_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698