| 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 // This test tests TLS session resume, by making multiple client connections | 5 // This test tests TLS session resume, by making multiple client connections |
| 6 // on the same port to the same server, with a delay of 200 ms between them. | 6 // on the same port to the same server, with a delay of 200 ms between them. |
| 7 // The unmodified secure_server_test creates all sessions simultaneously, | 7 // The unmodified secure_server_test creates all sessions simultaneously, |
| 8 // which means that no handshake completes and caches its keys in the session | 8 // which means that no handshake completes and caches its keys in the session |
| 9 // cache in time for other connections to use it. | 9 // cache in time for other connections to use it. |
| 10 // | 10 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 const SERVER_ADDRESS = "127.0.0.1"; | 23 const SERVER_ADDRESS = "127.0.0.1"; |
| 24 const HOST_NAME = "localhost"; | 24 const HOST_NAME = "localhost"; |
| 25 const CERTIFICATE = "localhost_cert"; | 25 const CERTIFICATE = "localhost_cert"; |
| 26 Future<SecureServerSocket> startServer() { | 26 Future<SecureServerSocket> startServer() { |
| 27 return SecureServerSocket.bind(SERVER_ADDRESS, | 27 return SecureServerSocket.bind(SERVER_ADDRESS, |
| 28 0, | 28 0, |
| 29 5, | 29 5, |
| 30 CERTIFICATE).then((server) { | 30 CERTIFICATE).then((server) { |
| 31 server.listen((SecureSocket client) { | 31 server.listen((SecureSocket client) { |
| 32 client.reduce(<int>[], (message, data) => message..addAll(data)) | 32 client.fold(<int>[], (message, data) => message..addAll(data)) |
| 33 .then((message) { | 33 .then((message) { |
| 34 String received = new String.fromCharCodes(message); | 34 String received = new String.fromCharCodes(message); |
| 35 Expect.isTrue(received.contains("Hello from client ")); | 35 Expect.isTrue(received.contains("Hello from client ")); |
| 36 String name = received.substring(received.indexOf("client ") + 7); | 36 String name = received.substring(received.indexOf("client ") + 7); |
| 37 client.write("Welcome, client $name"); | 37 client.write("Welcome, client $name"); |
| 38 client.close(); | 38 client.close(); |
| 39 }); | 39 }); |
| 40 }); | 40 }); |
| 41 return server; | 41 return server; |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 | 44 |
| 45 Future testClient(server, name) { | 45 Future testClient(server, name) { |
| 46 return SecureSocket.connect(HOST_NAME, server.port).then((socket) { | 46 return SecureSocket.connect(HOST_NAME, server.port).then((socket) { |
| 47 socket.write("Hello from client $name"); | 47 socket.write("Hello from client $name"); |
| 48 socket.close(); | 48 socket.close(); |
| 49 return socket.reduce(<int>[], (message, data) => message..addAll(data)) | 49 return socket.fold(<int>[], (message, data) => message..addAll(data)) |
| 50 .then((message) { | 50 .then((message) { |
| 51 Expect.listEquals("Welcome, client $name".codeUnits, message); | 51 Expect.listEquals("Welcome, client $name".codeUnits, message); |
| 52 return server; | 52 return server; |
| 53 }); | 53 }); |
| 54 }); | 54 }); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void main() { | 57 void main() { |
| 58 Path scriptDir = new Path(new Options().script).directoryPath; | 58 Path scriptDir = new Path(new Options().script).directoryPath; |
| 59 Path certificateDatabase = scriptDir.append('pkcert'); | 59 Path certificateDatabase = scriptDir.append('pkcert'); |
| 60 SecureSocket.initialize(database: certificateDatabase.toNativePath(), | 60 SecureSocket.initialize(database: certificateDatabase.toNativePath(), |
| 61 password: 'dartdart'); | 61 password: 'dartdart'); |
| 62 | 62 |
| 63 Duration delay = const Duration(milliseconds: 0); | 63 Duration delay = const Duration(milliseconds: 0); |
| 64 Duration delay_between_connections = const Duration(milliseconds: 300); | 64 Duration delay_between_connections = const Duration(milliseconds: 300); |
| 65 | 65 |
| 66 startServer() | 66 startServer() |
| 67 .then((server) => Future.wait( | 67 .then((server) => Future.wait( |
| 68 ['able', 'baker', 'charlie', 'dozen', 'elapse'] | 68 ['able', 'baker', 'charlie', 'dozen', 'elapse'] |
| 69 .map((name) { | 69 .map((name) { |
| 70 delay += delay_between_connections; | 70 delay += delay_between_connections; |
| 71 return new Future.delayed(delay, () => server) | 71 return new Future.delayed(delay, () => server) |
| 72 .then((server) => testClient(server, name)); | 72 .then((server) => testClient(server, name)); |
| 73 }))) | 73 }))) |
| 74 .then((servers) => servers.first.close()); | 74 .then((servers) => servers.first.close()); |
| 75 } | 75 } |
| OLD | NEW |