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 if (listenSecure) { | 466 if (listenSecure) { |
467 RawSecureServerSocket.bind( | 467 RawSecureServerSocket.bind( |
468 HOST, 0, CERTIFICATE).then(serverReady); | 468 HOST, 0, CERTIFICATE).then(serverReady); |
469 } else { | 469 } else { |
470 RawServerSocket.bind(HOST, 0).then(serverReady); | 470 RawServerSocket.bind(HOST, 0).then(serverReady); |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { | 474 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { |
475 bool expectFail = pausedServer || pausedClient; | |
476 | |
477 asyncStart(); | 475 asyncStart(); |
478 var clientComplete = new Completer(); | 476 var clientComplete = new Completer(); |
479 RawServerSocket.bind(HOST, 0).then((server) { | 477 RawServerSocket.bind(HOST, 0).then((server) { |
480 server.listen((client) { | 478 server.listen((client) { |
481 var subscription; | 479 var subscription; |
482 subscription = client.listen((_) { | 480 subscription = client.listen((_) { |
483 if (pausedServer) { | 481 if (pausedServer) { |
484 subscription.pause(); | 482 subscription.pause(); |
485 } | 483 } |
486 RawSecureSocket.secureServer( | 484 void done() { |
487 client, CERTIFICATE, subscription: subscription).then((client) { | |
488 if (expectFail) { | |
489 Expect.fail("secureServer succeeded with paused subscription"); | |
490 } | |
491 }).catchError((e) { | |
492 if (!expectFail) { | |
493 Expect.fail("secureServer failed with non-paused subscriptions"); | |
494 } | |
495 if (pausedServer) { | |
496 Expect.isTrue(e is StateError); | |
497 } | |
498 }).whenComplete(() { | |
499 server.close(); | 485 server.close(); |
500 clientComplete.future.then((_) { | 486 clientComplete.future.then((_) { |
501 client.close(); | 487 client.close(); |
502 asyncEnd(); | 488 asyncEnd(); |
503 }); | 489 }); |
504 }); | 490 } |
| 491 try { |
| 492 RawSecureSocket.secureServer( |
| 493 client, CERTIFICATE, subscription: subscription) |
| 494 .catchError((_) {}) |
| 495 .whenComplete(() { |
| 496 if (pausedServer) { |
| 497 Expect.fail("secureServer succeeded with paused subscription"); |
| 498 } |
| 499 done(); |
| 500 }); |
| 501 } catch (e) { |
| 502 if (!pausedServer) { |
| 503 Expect.fail("secureServer failed with non-paused subscriptions"); |
| 504 } |
| 505 if (pausedServer) { |
| 506 Expect.isTrue(e is ArgumentError); |
| 507 } |
| 508 done(); |
| 509 } |
505 }); | 510 }); |
506 }); | 511 }); |
507 | 512 |
508 RawSocket.connect(HOST, server.port).then((socket) { | 513 RawSocket.connect(HOST, server.port).then((socket) { |
509 var subscription; | 514 var subscription; |
510 subscription = socket.listen((_) { | 515 subscription = socket.listen((_) { |
511 if (pausedClient) { | 516 if (pausedClient) { |
512 subscription.pause(); | 517 subscription.pause(); |
513 } | 518 } |
514 RawSecureSocket.secure( | 519 try { |
515 socket, subscription: subscription).then((socket) { | 520 RawSecureSocket.secure( |
516 if (expectFail) { | 521 socket, subscription: subscription) |
517 Expect.fail("secure succeeded with paused subscription"); | 522 .catchError((_) {}) |
518 } | 523 .whenComplete(() { |
519 socket.close(); | 524 if (pausedClient) { |
520 }).catchError((e) { | 525 Expect.fail("secure succeeded with paused subscription"); |
521 if (!expectFail) { | 526 } |
| 527 socket.close(); |
| 528 clientComplete.complete(null); |
| 529 }); |
| 530 } catch (e) { |
| 531 if (!pausedClient) { |
522 Expect.fail("secure failed with non-paused subscriptions ($e)"); | 532 Expect.fail("secure failed with non-paused subscriptions ($e)"); |
523 } | 533 } |
524 if (pausedClient) { | 534 if (pausedClient) { |
525 Expect.isTrue(e is StateError); | 535 Expect.isTrue(e is ArgumentError); |
526 } | 536 } |
527 }).whenComplete(() { | |
528 clientComplete.complete(null); | 537 clientComplete.complete(null); |
529 }); | 538 } |
530 }); | 539 }); |
531 }); | 540 }); |
532 }); | 541 }); |
533 } | 542 } |
534 | 543 |
535 main() { | 544 main() { |
536 asyncStart(); | 545 asyncStart(); |
537 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); | 546 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); |
538 SecureSocket.initialize(database: certificateDatabase, | 547 SecureSocket.initialize(database: certificateDatabase, |
539 password: 'dartdart', | 548 password: 'dartdart', |
540 useBuiltinRoots: false); | 549 useBuiltinRoots: false); |
541 InternetAddress.lookup("localhost").then((hosts) { | 550 InternetAddress.lookup("localhost").then((hosts) { |
542 HOST = hosts.first; | 551 HOST = hosts.first; |
543 runTests(); | 552 runTests(); |
544 asyncEnd(); | 553 asyncEnd(); |
545 }); | 554 }); |
546 } | 555 } |
547 | 556 |
548 runTests() { | 557 runTests() { |
549 testSimpleBind(); | 558 testSimpleBind(); |
550 testInvalidBind(); | 559 testInvalidBind(); |
551 testSimpleConnect(CERTIFICATE); | 560 testSimpleConnect(CERTIFICATE); |
552 testSimpleConnect("CN=localhost"); | 561 testSimpleConnect("CN=localhost"); |
553 testSimpleConnectFail("not_a_nickname", false); | 562 testSimpleConnectFail("not_a_nickname", false); |
554 testSimpleConnectFail("CN=notARealDistinguishedName", false); | 563 testSimpleConnectFail("CN=notARealDistinguishedName", false); |
555 testSimpleConnectFail("not_a_nickname", true); | 564 testSimpleConnectFail("not_a_nickname", true); |
556 testSimpleConnectFail("CN=notARealDistinguishedName", true); | 565 testSimpleConnectFail("CN=notARealDistinguishedName", true); |
557 testServerListenAfterConnect(); | 566 testServerListenAfterConnect(); |
| 567 |
558 testSimpleReadWrite(listenSecure: true, | 568 testSimpleReadWrite(listenSecure: true, |
559 connectSecure: true, | 569 connectSecure: true, |
560 handshakeBeforeSecure: false, | 570 handshakeBeforeSecure: false, |
561 postponeSecure: false, | 571 postponeSecure: false, |
562 dropReads: false); | 572 dropReads: false); |
563 testSimpleReadWrite(listenSecure: true, | 573 testSimpleReadWrite(listenSecure: true, |
564 connectSecure: false, | 574 connectSecure: false, |
565 handshakeBeforeSecure: false, | 575 handshakeBeforeSecure: false, |
566 postponeSecure: false, | 576 postponeSecure: false, |
567 dropReads: false); | 577 dropReads: false); |
(...skipping 25 matching lines...) Expand all Loading... |
593 testSimpleReadWrite(listenSecure: false, | 603 testSimpleReadWrite(listenSecure: false, |
594 connectSecure: false, | 604 connectSecure: false, |
595 handshakeBeforeSecure: true, | 605 handshakeBeforeSecure: true, |
596 postponeSecure: true, | 606 postponeSecure: true, |
597 dropReads: true); | 607 dropReads: true); |
598 testPausedSecuringSubscription(false, false); | 608 testPausedSecuringSubscription(false, false); |
599 testPausedSecuringSubscription(true, false); | 609 testPausedSecuringSubscription(true, false); |
600 testPausedSecuringSubscription(false, true); | 610 testPausedSecuringSubscription(false, true); |
601 testPausedSecuringSubscription(true, true); | 611 testPausedSecuringSubscription(true, true); |
602 } | 612 } |
OLD | NEW |