OLD | NEW |
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"; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 } | 465 } |
466 | 466 |
467 if (listenSecure) { | 467 if (listenSecure) { |
468 RawSecureServerSocket.bind( | 468 RawSecureServerSocket.bind( |
469 HOST_NAME, 0, CERTIFICATE).then(serverReady); | 469 HOST_NAME, 0, CERTIFICATE).then(serverReady); |
470 } else { | 470 } else { |
471 RawServerSocket.bind(HOST_NAME, 0).then(serverReady); | 471 RawServerSocket.bind(HOST_NAME, 0).then(serverReady); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
| 475 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { |
| 476 bool expectFail = pausedServer || pausedClient; |
| 477 |
| 478 asyncStart(); |
| 479 var clientComplete = new Completer(); |
| 480 RawServerSocket.bind(HOST_NAME, 0).then((server) { |
| 481 server.listen((client) { |
| 482 var subscription; |
| 483 subscription = client.listen((_) { |
| 484 if (pausedServer) { |
| 485 subscription.pause(); |
| 486 } |
| 487 RawSecureSocket.secureServer( |
| 488 client, CERTIFICATE, subscription: subscription).then((client) { |
| 489 if (expectFail) { |
| 490 Expect.fail("secureServer succeeded with paused subscription"); |
| 491 } |
| 492 }).catchError((e) { |
| 493 if (!expectFail) { |
| 494 Expect.fail("secureServer failed with non-paused subscriptions"); |
| 495 } |
| 496 if (pausedServer) { |
| 497 Expect.isTrue(e is StateError); |
| 498 } |
| 499 }).whenComplete(() { |
| 500 server.close(); |
| 501 clientComplete.future.then((_) { |
| 502 client.close(); |
| 503 asyncEnd(); |
| 504 }); |
| 505 }); |
| 506 }); |
| 507 }); |
| 508 |
| 509 RawSocket.connect(HOST_NAME, server.port).then((socket) { |
| 510 var subscription; |
| 511 subscription = socket.listen((_) { |
| 512 if (pausedClient) { |
| 513 subscription.pause(); |
| 514 } |
| 515 RawSecureSocket.secure( |
| 516 socket, subscription: subscription).then((socket) { |
| 517 if (expectFail) { |
| 518 Expect.fail("secure succeeded with paused subscription"); |
| 519 } |
| 520 socket.close(); |
| 521 }).catchError((e) { |
| 522 if (!expectFail) { |
| 523 Expect.fail("secure failed with non-paused subscriptions ($e)"); |
| 524 } |
| 525 if (pausedClient) { |
| 526 Expect.isTrue(e is StateError); |
| 527 } |
| 528 }).whenComplete(() { |
| 529 clientComplete.complete(null); |
| 530 }); |
| 531 }); |
| 532 }); |
| 533 }); |
| 534 } |
| 535 |
475 main() { | 536 main() { |
476 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); | 537 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); |
477 SecureSocket.initialize(database: certificateDatabase, | 538 SecureSocket.initialize(database: certificateDatabase, |
478 password: 'dartdart', | 539 password: 'dartdart', |
479 useBuiltinRoots: false); | 540 useBuiltinRoots: false); |
480 testSimpleBind(); | 541 testSimpleBind(); |
481 testInvalidBind(); | 542 testInvalidBind(); |
482 testSimpleConnect(CERTIFICATE); | 543 testSimpleConnect(CERTIFICATE); |
483 testSimpleConnect("CN=localhost"); | 544 testSimpleConnect("CN=localhost"); |
484 testSimpleConnectFail("not_a_nickname", false); | 545 testSimpleConnectFail("not_a_nickname", false); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 testSimpleReadWrite(listenSecure: true, | 580 testSimpleReadWrite(listenSecure: true, |
520 connectSecure: true, | 581 connectSecure: true, |
521 handshakeBeforeSecure: false, | 582 handshakeBeforeSecure: false, |
522 postponeSecure: false, | 583 postponeSecure: false, |
523 dropReads: true); | 584 dropReads: true); |
524 testSimpleReadWrite(listenSecure: false, | 585 testSimpleReadWrite(listenSecure: false, |
525 connectSecure: false, | 586 connectSecure: false, |
526 handshakeBeforeSecure: true, | 587 handshakeBeforeSecure: true, |
527 postponeSecure: true, | 588 postponeSecure: true, |
528 dropReads: true); | 589 dropReads: true); |
| 590 testPausedSecuringSubscription(false, false); |
| 591 testPausedSecuringSubscription(true, false); |
| 592 testPausedSecuringSubscription(false, true); |
| 593 testPausedSecuringSubscription(true, true); |
529 } | 594 } |
OLD | NEW |