| 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"; |
| 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 import "package:path/path.dart"; | |
| 16 | 15 |
| 17 const HOST_NAME = "localhost"; | 16 InternetAddress HOST; |
| 18 const CERTIFICATE = "localhost_cert"; | 17 const CERTIFICATE = "localhost_cert"; |
| 19 | 18 |
| 20 // This test creates a server and a client connects. After connecting | 19 // This test creates a server and a client connects. After connecting |
| 21 // and an optional initial handshake the connection is secured by | 20 // and an optional initial handshake the connection is secured by |
| 22 // upgrading to a secure connection The client then writes and the | 21 // upgrading to a secure connection The client then writes and the |
| 23 // server echos. When the server has finished its echo it | 22 // server echos. When the server has finished its echo it |
| 24 // half-closes. When the client gets the close event is closes fully. | 23 // half-closes. When the client gets the close event is closes fully. |
| 25 // | 24 // |
| 26 // The test can be run in different configurations based on | 25 // The test can be run in different configurations based on |
| 27 // the boolean arguments: | 26 // the boolean arguments: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 146 } |
| 148 }, | 147 }, |
| 149 onDone: () => Expect.fail("Should not be called") | 148 onDone: () => Expect.fail("Should not be called") |
| 150 ); | 149 ); |
| 151 socket.add(createHandshakeTestData()); | 150 socket.add(createHandshakeTestData()); |
| 152 return completer.future; | 151 return completer.future; |
| 153 } | 152 } |
| 154 | 153 |
| 155 Future<SecureSocket> connectClient(int port) { | 154 Future<SecureSocket> connectClient(int port) { |
| 156 if (!handshakeBeforeSecure) { | 155 if (!handshakeBeforeSecure) { |
| 157 return Socket.connect(HOST_NAME, port).then((socket) { | 156 return Socket.connect(HOST, port).then((socket) { |
| 158 var future; | 157 var future; |
| 159 if (hostnameInConnect) { | 158 if (hostnameInConnect) { |
| 160 future = SecureSocket.secure(socket); | 159 future = SecureSocket.secure(socket); |
| 161 } else { | 160 } else { |
| 162 future = SecureSocket.secure(socket, host: HOST_NAME); | 161 future = SecureSocket.secure(socket, host: HOST); |
| 163 } | 162 } |
| 164 return future.then((secureSocket) { | 163 return future.then((secureSocket) { |
| 165 socket.add([0]); | 164 socket.add([0]); |
| 166 return secureSocket; | 165 return secureSocket; |
| 167 }); | 166 }); |
| 168 }); | 167 }); |
| 169 } else { | 168 } else { |
| 170 return Socket.connect(HOST_NAME, port).then((socket) { | 169 return Socket.connect(HOST, port).then((socket) { |
| 171 return runClientHandshake(socket).then((_) { | 170 return runClientHandshake(socket).then((_) { |
| 172 var future; | 171 var future; |
| 173 if (hostnameInConnect) { | 172 if (hostnameInConnect) { |
| 174 future = SecureSocket.secure(socket); | 173 future = SecureSocket.secure(socket); |
| 175 } else { | 174 } else { |
| 176 future = SecureSocket.secure(socket, host: HOST_NAME); | 175 future = SecureSocket.secure(socket, host: HOST.host); |
| 177 } | 176 } |
| 178 return future.then((secureSocket) { | 177 return future.then((secureSocket) { |
| 179 socket.add([0]); | 178 socket.add([0]); |
| 180 return secureSocket; | 179 return secureSocket; |
| 181 }); | 180 }); |
| 182 }); | 181 }); |
| 183 }); | 182 }); |
| 184 } | 183 } |
| 185 } | 184 } |
| 186 | 185 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 202 }); | 201 }); |
| 203 }); | 202 }); |
| 204 } | 203 } |
| 205 }); | 204 }); |
| 206 | 205 |
| 207 connectClient(server.port).then(runClient).then((socket) { | 206 connectClient(server.port).then(runClient).then((socket) { |
| 208 asyncEnd(); | 207 asyncEnd(); |
| 209 }); | 208 }); |
| 210 } | 209 } |
| 211 | 210 |
| 212 ServerSocket.bind(HOST_NAME, 0).then(serverReady); | 211 ServerSocket.bind(HOST, 0).then(serverReady); |
| 213 } | 212 } |
| 214 | 213 |
| 215 main() { | 214 main() { |
| 215 asyncStart(); |
| 216 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); | 216 var certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 217 SecureSocket.initialize(database: certificateDatabase, | 217 SecureSocket.initialize(database: certificateDatabase, |
| 218 password: 'dartdart', | 218 password: 'dartdart', |
| 219 useBuiltinRoots: false); | 219 useBuiltinRoots: false); |
| 220 test(false, false); | 220 InternetAddress.lookup("localhost").then((hosts) { |
| 221 test(true, false); | 221 HOST = hosts.first; |
| 222 test(false, true); | 222 test(false, false); |
| 223 test(true, true); | 223 test(true, false); |
| 224 test(false, true, true); | 224 test(false, true); |
| 225 test(true, true, true); | 225 test(true, true); |
| 226 test(false, true, true); |
| 227 test(true, true, true); |
| 228 asyncEnd(); |
| 229 }); |
| 226 } | 230 } |
| OLD | NEW |