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

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

Issue 16858011: dart:io | Enable multithreaded secure networking encryption. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // between client and server before the connection is secured. This argument 148 // between client and server before the connection is secured. This argument
149 // only makes sense when both listenSecure and connectSecure are false. 149 // only makes sense when both listenSecure and connectSecure are false.
150 // 150 //
151 // postponeSecure 151 // postponeSecure
152 // When this argument is false the securing of the server end will 152 // When this argument is false the securing of the server end will
153 // happen as soon as the last byte of the handshake before securing 153 // happen as soon as the last byte of the handshake before securing
154 // has been written. When this argument is true the securing of the 154 // has been written. When this argument is true the securing of the
155 // server will not happen until the first TLS handshake data has been 155 // server will not happen until the first TLS handshake data has been
156 // received from the client. This argument only takes effect when 156 // received from the client. This argument only takes effect when
157 // handshakeBeforeSecure is true. 157 // handshakeBeforeSecure is true.
158 void testSimpleReadWrite(bool listenSecure, 158 void testSimpleReadWrite({bool listenSecure,
159 bool connectSecure, 159 bool connectSecure,
160 bool handshakeBeforeSecure, 160 bool handshakeBeforeSecure,
161 [bool postponeSecure = false]) { 161 bool postponeSecure,
162 bool dropReads}) {
163 int clientReads = 0;
164 int serverReads = 0;
162 if (handshakeBeforeSecure == true && 165 if (handshakeBeforeSecure == true &&
163 (listenSecure == true || connectSecure == true)) { 166 (listenSecure == true || connectSecure == true)) {
164 Expect.fail("Invalid arguments to testSimpleReadWrite"); 167 Expect.fail("Invalid arguments to testSimpleReadWrite");
165 } 168 }
166 169
167 ReceivePort port = new ReceivePort(); 170 ReceivePort port = new ReceivePort();
168 171
169 const messageSize = 1000; 172 const messageSize = 1000;
170 const handshakeMessageSize = 100; 173 const handshakeMessageSize = 100;
171 174
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 Future runServer(RawSocket client) { 207 Future runServer(RawSocket client) {
205 var completer = new Completer(); 208 var completer = new Completer();
206 int bytesRead = 0; 209 int bytesRead = 0;
207 int bytesWritten = 0; 210 int bytesWritten = 0;
208 List<int> data = new List<int>(messageSize); 211 List<int> data = new List<int>(messageSize);
209 client.writeEventsEnabled = false; 212 client.writeEventsEnabled = false;
210 var subscription; 213 var subscription;
211 subscription = client.listen((event) { 214 subscription = client.listen((event) {
212 switch (event) { 215 switch (event) {
213 case RawSocketEvent.READ: 216 case RawSocketEvent.READ:
217 if (dropReads) {
218 if (serverReads != 10) {
219 ++serverReads;
220 break;
221 } else {
222 serverReads = 0;
223 }
224 }
214 Expect.isTrue(bytesWritten == 0); 225 Expect.isTrue(bytesWritten == 0);
215 Expect.isTrue(client.available() > 0); 226 Expect.isTrue(client.available() > 0);
216 var buffer = client.read(); 227 var buffer = client.read();
217 if (buffer != null) { 228 if (buffer != null) {
218 data.setRange(bytesRead, bytesRead + buffer.length, buffer); 229 data.setRange(bytesRead, bytesRead + buffer.length, buffer);
219 bytesRead += buffer.length; 230 bytesRead += buffer.length;
220 for (var value in buffer) { 231 for (var value in buffer) {
221 Expect.isTrue(value is int); 232 Expect.isTrue(value is int);
222 Expect.isTrue(value < 256 && value >= 0); 233 Expect.isTrue(value < 256 && value >= 0);
223 } 234 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 Future<RawSocket> runClient(RawSocket socket) { 266 Future<RawSocket> runClient(RawSocket socket) {
256 var completer = new Completer(); 267 var completer = new Completer();
257 int bytesRead = 0; 268 int bytesRead = 0;
258 int bytesWritten = 0; 269 int bytesWritten = 0;
259 List<int> dataSent = createTestData(); 270 List<int> dataSent = createTestData();
260 List<int> dataReceived = new List<int>(dataSent.length); 271 List<int> dataReceived = new List<int>(dataSent.length);
261 socket.listen((event) { 272 socket.listen((event) {
262 switch (event) { 273 switch (event) {
263 case RawSocketEvent.READ: 274 case RawSocketEvent.READ:
264 Expect.isTrue(socket.available() > 0); 275 Expect.isTrue(socket.available() > 0);
276 if (dropReads) {
277 if (clientReads != 10) {
278 ++clientReads;
279 break;
280 } else {
281 clientReads = 0;
282 }
283 }
265 var buffer = socket.read(); 284 var buffer = socket.read();
266 if (buffer != null) { 285 if (buffer != null) {
267 dataReceived.setRange(bytesRead, bytesRead + buffer.length, buffer); 286 dataReceived.setRange(bytesRead, bytesRead + buffer.length, buffer);
268 bytesRead += buffer.length; 287 bytesRead += buffer.length;
269 } 288 }
270 break; 289 break;
271 case RawSocketEvent.WRITE: 290 case RawSocketEvent.WRITE:
272 Expect.isTrue(bytesRead == 0); 291 Expect.isTrue(bytesRead == 0);
273 Expect.isFalse(socket.writeEventsEnabled); 292 Expect.isFalse(socket.writeEventsEnabled);
274 bytesWritten += socket.write( 293 bytesWritten += socket.write(
(...skipping 19 matching lines...) Expand all
294 List<int> data = new List<int>(handshakeMessageSize); 313 List<int> data = new List<int>(handshakeMessageSize);
295 client.writeEventsEnabled = false; 314 client.writeEventsEnabled = false;
296 var subscription; 315 var subscription;
297 subscription = client.listen((event) { 316 subscription = client.listen((event) {
298 switch (event) { 317 switch (event) {
299 case RawSocketEvent.READ: 318 case RawSocketEvent.READ:
300 if (bytesRead < data.length) { 319 if (bytesRead < data.length) {
301 Expect.isTrue(bytesWritten == 0); 320 Expect.isTrue(bytesWritten == 0);
302 } 321 }
303 Expect.isTrue(client.available() > 0); 322 Expect.isTrue(client.available() > 0);
323 if (dropReads) {
324 if (serverReads != 10) {
325 ++serverReads;
326 break;
327 } else {
328 serverReads = 0;
329 }
330 }
304 var buffer = client.read(); 331 var buffer = client.read();
305 if (buffer != null) { 332 if (buffer != null) {
306 if (bytesRead == data.length) { 333 if (bytesRead == data.length) {
307 // Read first part of TLS handshake from client. 334 // Read first part of TLS handshake from client.
308 Expect.isTrue(postponeSecure); 335 Expect.isTrue(postponeSecure);
309 completer.complete([subscription, buffer]); 336 completer.complete([subscription, buffer]);
310 client.readEventsEnabled = false; 337 client.readEventsEnabled = false;
311 return; 338 return;
312 } 339 }
313 data.setRange(bytesRead, bytesRead + buffer.length, buffer); 340 data.setRange(bytesRead, bytesRead + buffer.length, buffer);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 Future<RawSocket> runClientHandshake(RawSocket socket) { 379 Future<RawSocket> runClientHandshake(RawSocket socket) {
353 var completer = new Completer(); 380 var completer = new Completer();
354 int bytesRead = 0; 381 int bytesRead = 0;
355 int bytesWritten = 0; 382 int bytesWritten = 0;
356 List<int> dataSent = createHandshakeTestData(); 383 List<int> dataSent = createHandshakeTestData();
357 List<int> dataReceived = new List<int>(dataSent.length); 384 List<int> dataReceived = new List<int>(dataSent.length);
358 var subscription; 385 var subscription;
359 subscription = socket.listen((event) { 386 subscription = socket.listen((event) {
360 switch (event) { 387 switch (event) {
361 case RawSocketEvent.READ: 388 case RawSocketEvent.READ:
389 if (dropReads) {
390 if (clientReads != 10) {
391 ++clientReads;
392 break;
393 } else {
394 clientReads = 0;
395 }
396 }
362 Expect.isTrue(socket.available() > 0); 397 Expect.isTrue(socket.available() > 0);
363 var buffer = socket.read(); 398 var buffer = socket.read();
364 if (buffer != null) { 399 if (buffer != null) {
365 dataReceived.setRange(bytesRead, bytesRead + buffer.length, buffer); 400 dataReceived.setRange(bytesRead, bytesRead + buffer.length, buffer);
366 bytesRead += buffer.length; 401 bytesRead += buffer.length;
367 if (bytesRead == dataSent.length) { 402 if (bytesRead == dataSent.length) {
368 verifyHandshakeTestData(dataReceived); 403 verifyHandshakeTestData(dataReceived);
369 completer.complete(subscription); 404 completer.complete(subscription);
370 } 405 }
371 } 406 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } else if (!handshakeBeforeSecure) { 446 } else if (!handshakeBeforeSecure) {
412 RawSecureSocket.secureServer(client, CERTIFICATE).then((client) { 447 RawSecureSocket.secureServer(client, CERTIFICATE).then((client) {
413 runServer(client).then((_) => server.close()); 448 runServer(client).then((_) => server.close());
414 }); 449 });
415 } else { 450 } else {
416 runServerHandshake(client).then((secure) { 451 runServerHandshake(client).then((secure) {
417 RawSecureSocket.secureServer( 452 RawSecureSocket.secureServer(
418 client, 453 client,
419 CERTIFICATE, 454 CERTIFICATE,
420 subscription: secure[0], 455 subscription: secure[0],
421 carryOverData: secure[1]).then((client) { 456 bufferedData: secure[1]).then((client) {
422 runServer(client).then((_) => server.close()); 457 runServer(client).then((_) => server.close());
423 }); 458 });
424 }); 459 });
425 } 460 }
426 }); 461 });
427 462
428 connectClient(server.port).then(runClient).then((socket) { 463 connectClient(server.port).then(runClient).then((socket) {
429 socket.close(); 464 socket.close();
430 port.close(); 465 port.close();
431 }); 466 });
(...skipping 15 matching lines...) Expand all
447 useBuiltinRoots: false); 482 useBuiltinRoots: false);
448 testSimpleBind(); 483 testSimpleBind();
449 testInvalidBind(); 484 testInvalidBind();
450 testSimpleConnect(CERTIFICATE); 485 testSimpleConnect(CERTIFICATE);
451 testSimpleConnect("CN=localhost"); 486 testSimpleConnect("CN=localhost");
452 testSimpleConnectFail("not_a_nickname", false); 487 testSimpleConnectFail("not_a_nickname", false);
453 testSimpleConnectFail("CN=notARealDistinguishedName", false); 488 testSimpleConnectFail("CN=notARealDistinguishedName", false);
454 testSimpleConnectFail("not_a_nickname", true); 489 testSimpleConnectFail("not_a_nickname", true);
455 testSimpleConnectFail("CN=notARealDistinguishedName", true); 490 testSimpleConnectFail("CN=notARealDistinguishedName", true);
456 testServerListenAfterConnect(); 491 testServerListenAfterConnect();
457 testSimpleReadWrite(true, true, false); 492 testSimpleReadWrite(listenSecure: true,
458 testSimpleReadWrite(true, false, false); 493 connectSecure: true,
459 testSimpleReadWrite(false, true, false); 494 handshakeBeforeSecure: false,
460 testSimpleReadWrite(false, false, false); 495 postponeSecure: false,
461 testSimpleReadWrite(false, false, true, true); 496 dropReads: false);
462 testSimpleReadWrite(false, false, true, false); 497 testSimpleReadWrite(listenSecure: true,
498 connectSecure: false,
499 handshakeBeforeSecure: false,
500 postponeSecure: false,
501 dropReads: false);
502 testSimpleReadWrite(listenSecure: false,
503 connectSecure: true,
504 handshakeBeforeSecure: false,
505 postponeSecure: false,
506 dropReads: false);
507 testSimpleReadWrite(listenSecure: false,
508 connectSecure: false,
509 handshakeBeforeSecure: false,
510 postponeSecure: false,
511 dropReads: false);
512 testSimpleReadWrite(listenSecure: false,
513 connectSecure: false,
514 handshakeBeforeSecure: true,
515 postponeSecure: true,
516 dropReads: false);
517 testSimpleReadWrite(listenSecure: false,
518 connectSecure: false,
519 handshakeBeforeSecure: true,
520 postponeSecure: false,
521 dropReads: false);
522 testSimpleReadWrite(listenSecure: true,
523 connectSecure: true,
524 handshakeBeforeSecure: false,
525 postponeSecure: false,
526 dropReads: true);
527 testSimpleReadWrite(listenSecure: false,
528 connectSecure: false,
529 handshakeBeforeSecure: true,
530 postponeSecure: true,
531 dropReads: true);
463 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698