Chromium Code Reviews| 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 // OtherResources=certificates/server_chain.pem | 9 // OtherResources=certificates/server_chain.pem |
| 10 // OtherResources=certificates/server_key.pem | 10 // OtherResources=certificates/server_key.pem |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 SecurityContext serverContext = new SecurityContext() | 24 SecurityContext serverContext = new SecurityContext() |
| 25 ..useCertificateChain(localFile('certificates/server_chain.pem')) | 25 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
| 26 ..usePrivateKey(localFile('certificates/server_key.pem'), | 26 ..usePrivateKey(localFile('certificates/server_key.pem'), |
| 27 password: 'dartdart'); | 27 password: 'dartdart'); |
| 28 | 28 |
| 29 SecurityContext clientContext = new SecurityContext() | 29 SecurityContext clientContext = new SecurityContext() |
| 30 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem')); | 30 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem')); |
| 31 | 31 |
| 32 void testSimpleBind() { | 32 void testSimpleBind() { |
| 33 print("asyncStart testSimpleBind"); | |
| 33 asyncStart(); | 34 asyncStart(); |
| 34 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { | 35 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { |
| 35 Expect.isTrue(s.port > 0); | 36 Expect.isTrue(s.port > 0); |
| 36 s.close(); | 37 s.close(); |
| 38 print("asyncEnd testSimpleBind"); | |
| 37 asyncEnd(); | 39 asyncEnd(); |
| 38 }); | 40 }); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void testInvalidBind() { | 43 void testInvalidBind() { |
| 42 int count = 0; | 44 int count = 0; |
| 43 | 45 |
| 44 // Bind to a unknown DNS name. | 46 // Bind to a unknown DNS name. |
| 45 asyncStart(); | 47 asyncStart(); |
| 48 print("asyncStart testInvalidBind"); | |
| 46 RawSecureServerSocket.bind("ko.faar.__hest__", 0, serverContext).then((_) { | 49 RawSecureServerSocket.bind("ko.faar.__hest__", 0, serverContext).then((_) { |
| 47 Expect.fail("Failure expected"); | 50 Expect.fail("Failure expected"); |
| 48 }).catchError((error) { | 51 }).catchError((error) { |
| 49 Expect.isTrue(error is SocketException); | 52 Expect.isTrue(error is SocketException); |
| 53 print("asyncEnd testInvalidBind"); | |
| 50 asyncEnd(); | 54 asyncEnd(); |
| 51 }); | 55 }); |
| 52 | 56 |
| 53 // Bind to an unavaliable IP-address. | 57 // Bind to an unavaliable IP-address. |
| 54 asyncStart(); | 58 asyncStart(); |
| 59 print("asyncStart testInvalidBind 2"); | |
| 55 RawSecureServerSocket.bind("8.8.8.8", 0, serverContext).then((_) { | 60 RawSecureServerSocket.bind("8.8.8.8", 0, serverContext).then((_) { |
| 56 Expect.fail("Failure expected"); | 61 Expect.fail("Failure expected"); |
| 57 }).catchError((error) { | 62 }).catchError((error) { |
| 58 Expect.isTrue(error is SocketException); | 63 Expect.isTrue(error is SocketException); |
| 64 print("asyncEnd testInvalidBind 2"); | |
| 59 asyncEnd(); | 65 asyncEnd(); |
| 60 }); | 66 }); |
| 61 | 67 |
| 62 // Bind to a port already in use. | 68 // Bind to a port already in use. |
| 63 asyncStart(); | 69 asyncStart(); |
| 70 print("asyncStart testInvalidBind 3"); | |
| 64 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { | 71 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { |
| 65 RawSecureServerSocket.bind(HOST, | 72 RawSecureServerSocket.bind(HOST, |
| 66 s.port, | 73 s.port, |
| 67 serverContext).then((t) { | 74 serverContext).then((t) { |
| 68 s.close(); | 75 s.close(); |
| 69 t.close(); | 76 t.close(); |
| 70 Expect.fail("Multiple listens on same port"); | 77 Expect.fail("Multiple listens on same port"); |
| 71 }) | 78 }) |
| 72 .catchError((error) { | 79 .catchError((error) { |
| 73 Expect.isTrue(error is SocketException); | 80 Expect.isTrue(error is SocketException); |
| 74 s.close(); | 81 s.close(); |
| 82 print("asyncEnd testInvalidBind 3"); | |
| 75 asyncEnd(); | 83 asyncEnd(); |
| 76 }); | 84 }); |
| 77 }); | 85 }); |
| 78 } | 86 } |
| 79 | 87 |
| 80 void testSimpleConnect() { | 88 void testSimpleConnect() { |
| 89 print("asyncStart testSimpleConnect"); | |
| 81 asyncStart(); | 90 asyncStart(); |
| 82 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { | 91 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { |
| 83 var clientEndFuture = | 92 var clientEndFuture = |
| 84 RawSecureSocket.connect(HOST, server.port, context: clientContext); | 93 RawSecureSocket.connect(HOST, server.port, context: clientContext); |
| 85 server.listen((serverEnd) { | 94 server.listen((serverEnd) { |
| 86 clientEndFuture.then((clientEnd) { | 95 clientEndFuture.then((clientEnd) { |
| 87 // TODO(whesse): Shutdown(SEND) not supported on secure sockets. | 96 // TODO(whesse): Shutdown(SEND) not supported on secure sockets. |
| 88 clientEnd.shutdown(SocketDirection.SEND); | 97 clientEnd.shutdown(SocketDirection.SEND); |
| 89 serverEnd.shutdown(SocketDirection.SEND); | 98 serverEnd.shutdown(SocketDirection.SEND); |
| 90 server.close(); | 99 server.close(); |
| 100 print("asyncEnd testSimpleConnect"); | |
| 91 asyncEnd(); | 101 asyncEnd(); |
| 92 }); | 102 }); |
| 93 }); | 103 }); |
| 94 }); | 104 }); |
| 95 } | 105 } |
| 96 | 106 |
| 107 int debugTestSimpleConnectFailCounter = 0; | |
| 97 void testSimpleConnectFail(SecurityContext context, bool cancelOnError) { | 108 void testSimpleConnectFail(SecurityContext context, bool cancelOnError) { |
| 109 var counter = debugTestSimpleConnectFailCounter++; | |
| 110 print("asyncStart testSimpleConnectFail $counter"); | |
| 98 asyncStart(); | 111 asyncStart(); |
| 99 RawSecureServerSocket.bind(HOST, 0, context).then((server) { | 112 RawSecureServerSocket.bind(HOST, 0, context).then((server) { |
| 100 var clientEndFuture = | 113 var clientEndFuture = |
| 101 RawSecureSocket.connect(HOST, server.port, context: clientContext) | 114 RawSecureSocket.connect(HOST, server.port, context: clientContext) |
| 102 .then((clientEnd) { | 115 .then((clientEnd) { |
| 103 Expect.fail("No client connection expected."); | 116 Expect.fail("No client connection expected."); |
| 104 }) | 117 }) |
| 105 .catchError((error) { | 118 .catchError((error) { |
| 106 Expect.isTrue(error is SocketException || | 119 Expect.isTrue(error is SocketException || |
| 107 error is HandshakeException); | 120 error is HandshakeException); |
| 108 }); | 121 }); |
| 109 server.listen((serverEnd) { | 122 server.listen((serverEnd) { |
| 110 Expect.fail("No server connection expected."); | 123 Expect.fail("No server connection expected."); |
| 111 }, | 124 }, |
| 112 onError: (error) { | 125 onError: (error) { |
| 113 Expect.isTrue(error is SocketException || | 126 Expect.isTrue(error is SocketException || |
| 114 error is HandshakeException); | 127 error is HandshakeException); |
| 115 clientEndFuture.then((_) { | 128 clientEndFuture.then((_) { |
| 116 if (!cancelOnError) server.close(); | 129 if (!cancelOnError) server.close(); |
| 130 print("asyncEnd testSimpleConnectFail $counter"); | |
| 117 asyncEnd(); | 131 asyncEnd(); |
| 118 }); | 132 }); |
| 119 }, | 133 }, |
| 120 cancelOnError: cancelOnError); | 134 cancelOnError: cancelOnError); |
| 121 }); | 135 }); |
| 122 } | 136 } |
| 123 | 137 |
| 124 void testServerListenAfterConnect() { | 138 void testServerListenAfterConnect() { |
| 139 print("asyncStart testServerListenAfterConnect"); | |
| 125 asyncStart(); | 140 asyncStart(); |
| 126 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { | 141 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { |
| 127 Expect.isTrue(server.port > 0); | 142 Expect.isTrue(server.port > 0); |
| 128 var clientEndFuture = | 143 var clientEndFuture = |
| 129 RawSecureSocket.connect(HOST, server.port, context: clientContext); | 144 RawSecureSocket.connect(HOST, server.port, context: clientContext); |
| 130 new Timer(const Duration(milliseconds: 500), () { | 145 new Timer(const Duration(milliseconds: 500), () { |
| 131 server.listen((serverEnd) { | 146 server.listen((serverEnd) { |
| 132 clientEndFuture.then((clientEnd) { | 147 clientEndFuture.then((clientEnd) { |
| 133 clientEnd.shutdown(SocketDirection.SEND); | 148 clientEnd.shutdown(SocketDirection.SEND); |
| 134 serverEnd.shutdown(SocketDirection.SEND); | 149 serverEnd.shutdown(SocketDirection.SEND); |
| 135 server.close(); | 150 server.close(); |
| 151 print("asyncEnd testServerListenAfterConnect"); | |
| 136 asyncEnd(); | 152 asyncEnd(); |
| 137 }); | 153 }); |
| 138 }); | 154 }); |
| 139 }); | 155 }); |
| 140 }); | 156 }); |
| 141 } | 157 } |
| 142 | 158 |
| 143 // This test creates a server and a client connects. The client then | 159 // This test creates a server and a client connects. The client then |
| 144 // writes and the server echos. When the server has finished its echo | 160 // writes and the server echos. When the server has finished its echo |
| 145 // it half-closes. When the client gets the close event is closes | 161 // it half-closes. When the client gets the close event is closes |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 175 bool handshakeBeforeSecure, | 191 bool handshakeBeforeSecure, |
| 176 bool postponeSecure, | 192 bool postponeSecure, |
| 177 bool dropReads}) { | 193 bool dropReads}) { |
| 178 int clientReads = 0; | 194 int clientReads = 0; |
| 179 int serverReads = 0; | 195 int serverReads = 0; |
| 180 if (handshakeBeforeSecure == true && | 196 if (handshakeBeforeSecure == true && |
| 181 (listenSecure == true || connectSecure == true)) { | 197 (listenSecure == true || connectSecure == true)) { |
| 182 Expect.fail("Invalid arguments to testSimpleReadWrite"); | 198 Expect.fail("Invalid arguments to testSimpleReadWrite"); |
| 183 } | 199 } |
| 184 | 200 |
| 201 print("asyncStart testSimpleReadWrite($listenSecure, $connectSecure, " | |
| 202 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); | |
| 185 asyncStart(); | 203 asyncStart(); |
| 186 | 204 |
| 187 const messageSize = 1000; | 205 const messageSize = 1000; |
| 188 const handshakeMessageSize = 100; | 206 const handshakeMessageSize = 100; |
| 189 | 207 |
| 190 List<int> createTestData() { | 208 List<int> createTestData() { |
| 191 List<int> data = new List<int>(messageSize); | 209 List<int> data = new List<int>(messageSize); |
| 192 for (int i = 0; i < messageSize; i++) { | 210 for (int i = 0; i < messageSize; i++) { |
| 193 data[i] = i & 0xff; | 211 data[i] = i & 0xff; |
| 194 } | 212 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 subscription: secure[0], | 490 subscription: secure[0], |
| 473 bufferedData: secure[1]).then((client) { | 491 bufferedData: secure[1]).then((client) { |
| 474 runServer(client).then((_) => server.close()); | 492 runServer(client).then((_) => server.close()); |
| 475 }); | 493 }); |
| 476 }); | 494 }); |
| 477 } | 495 } |
| 478 }); | 496 }); |
| 479 | 497 |
| 480 connectClient(server.port).then(runClient).then((socket) { | 498 connectClient(server.port).then(runClient).then((socket) { |
| 481 socket.close(); | 499 socket.close(); |
| 500 print("asyncEnd testSimpleReadWrite($listenSecure, $connectSecure, " | |
| 501 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); | |
| 482 asyncEnd(); | 502 asyncEnd(); |
| 483 }); | 503 }); |
| 484 } | 504 } |
| 485 | 505 |
| 486 if (listenSecure) { | 506 if (listenSecure) { |
| 487 RawSecureServerSocket.bind( | 507 RawSecureServerSocket.bind( |
| 488 HOST, 0, serverContext).then(serverReady); | 508 HOST, 0, serverContext).then(serverReady); |
| 489 } else { | 509 } else { |
| 490 RawServerSocket.bind(HOST, 0).then(serverReady); | 510 RawServerSocket.bind(HOST, 0).then(serverReady); |
| 491 } | 511 } |
| 492 } | 512 } |
| 493 | 513 |
| 494 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { | 514 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { |
| 515 print( | |
| 516 "asyncStart testPausedSecuringSubscription $pausedServer $pausedClient"); | |
| 495 asyncStart(); | 517 asyncStart(); |
| 496 var clientComplete = new Completer(); | 518 var clientComplete = new Completer(); |
| 497 RawServerSocket.bind(HOST, 0).then((server) { | 519 RawServerSocket.bind(HOST, 0).then((server) { |
| 498 server.listen((client) { | 520 server.listen((client) { |
| 499 var subscription; | 521 var subscription; |
| 500 subscription = client.listen((_) { | 522 subscription = client.listen((_) { |
| 501 if (pausedServer) { | 523 if (pausedServer) { |
| 502 subscription.pause(); | 524 subscription.pause(); |
| 503 } | 525 } |
| 504 void done() { | 526 void done() { |
| 505 server.close(); | 527 server.close(); |
| 506 clientComplete.future.then((_) { | 528 clientComplete.future.then((_) { |
| 507 client.close(); | 529 client.close(); |
| 530 print("asyncEnd testPausedSecuringSubscription " | |
| 531 "$pausedServer $pausedClient"); | |
| 508 asyncEnd(); | 532 asyncEnd(); |
| 509 }); | 533 }); |
| 510 } | 534 } |
| 511 try { | 535 try { |
| 512 RawSecureSocket.secureServer( | 536 RawSecureSocket.secureServer( |
| 513 client, serverContext, subscription: subscription) | 537 client, serverContext, subscription: subscription) |
| 514 .catchError((_) {}) | 538 .catchError((_) {}) |
| 515 .whenComplete(() { | 539 .whenComplete(() { |
| 516 if (pausedServer) { | 540 if (pausedServer) { |
| 517 Expect.fail("secureServer succeeded with paused subscription"); | 541 Expect.fail("secureServer succeeded with paused subscription"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 Expect.isTrue(e is ArgumentError); | 579 Expect.isTrue(e is ArgumentError); |
| 556 } | 580 } |
| 557 clientComplete.complete(null); | 581 clientComplete.complete(null); |
| 558 } | 582 } |
| 559 }); | 583 }); |
| 560 }); | 584 }); |
| 561 }); | 585 }); |
| 562 } | 586 } |
| 563 | 587 |
| 564 main() { | 588 main() { |
| 589 print("asyncStart main"); | |
| 565 asyncStart(); | 590 asyncStart(); |
| 566 InternetAddress.lookup("localhost").then((hosts) { | 591 InternetAddress.lookup("localhost").then((hosts) { |
| 567 HOST = hosts.first; | 592 HOST = hosts.first; |
| 568 runTests(); | 593 runTests(); |
| 594 print("asyncEnd main"); | |
| 569 asyncEnd(); | 595 asyncEnd(); |
| 570 }); | 596 }); |
| 571 } | 597 } |
| 572 | 598 |
| 573 runTests() { | 599 runTests() { |
|
Florian Schneider
2016/12/13 18:27:20
Would it make sense to split this up as a multi-te
floitsch
2016/12/13 19:21:48
Unfortunately no: the test uses VMOptions which is
| |
| 574 testSimpleBind(); | 600 testSimpleBind(); |
| 575 testInvalidBind(); | 601 testInvalidBind(); |
| 576 testSimpleConnect(); | 602 testSimpleConnect(); |
| 577 SecurityContext context = new SecurityContext(); | 603 SecurityContext context = new SecurityContext(); |
| 578 testSimpleConnectFail(context, false); | 604 testSimpleConnectFail(context, false); |
| 579 testSimpleConnectFail(context, true); | 605 testSimpleConnectFail(context, true); |
| 580 var chain = | 606 var chain = |
| 581 Platform.script.resolve('certificates/untrusted_server_chain.pem') | 607 Platform.script.resolve('certificates/untrusted_server_chain.pem') |
| 582 .toFilePath(); | 608 .toFilePath(); |
| 583 context.useCertificateChain(chain); | 609 context.useCertificateChain(chain); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 testSimpleReadWrite(listenSecure: false, | 657 testSimpleReadWrite(listenSecure: false, |
| 632 connectSecure: false, | 658 connectSecure: false, |
| 633 handshakeBeforeSecure: true, | 659 handshakeBeforeSecure: true, |
| 634 postponeSecure: true, | 660 postponeSecure: true, |
| 635 dropReads: true); | 661 dropReads: true); |
| 636 testPausedSecuringSubscription(false, false); | 662 testPausedSecuringSubscription(false, false); |
| 637 testPausedSecuringSubscription(true, false); | 663 testPausedSecuringSubscription(true, false); |
| 638 testPausedSecuringSubscription(false, true); | 664 testPausedSecuringSubscription(false, true); |
| 639 testPausedSecuringSubscription(true, true); | 665 testPausedSecuringSubscription(true, true); |
| 640 } | 666 } |
| OLD | NEW |