| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "package:path/path.dart"; | 6 import "package:path/path.dart"; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 | 8 |
| 9 import "dart:async"; | 9 import "dart:async"; |
| 10 import "dart:io"; | 10 import "dart:io"; |
| 11 import "dart:typed_data"; | 11 import "dart:typed_data"; |
| 12 | 12 |
| 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 13 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 14 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | |
| 15 | 14 |
| 16 SecurityContext serverContext = new SecurityContext() | 15 SecurityContext serverContext = new SecurityContext() |
| 17 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 16 ..useCertificateChainSync(localFile('certificates/server_chain.pem')) |
| 18 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 17 ..usePrivateKeySync(localFile('certificates/server_key.pem'), |
| 19 password: 'dartdart'); | 18 password: 'dartdart'); |
| 20 | 19 |
| 21 SecurityContext clientContext = new SecurityContext() | 20 SecurityContext clientContext = new SecurityContext() |
| 22 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 21 ..setTrustedCertificatesSync(localFile('certificates/trusted_certs.pem')); |
| 23 | 22 |
| 24 // 10 KiB of i%256 data. | 23 // 10 KiB of i%256 data. |
| 25 Uint8List DATA = new Uint8List.fromList( | 24 Uint8List DATA = new Uint8List.fromList( |
| 26 new List.generate(10 * 1024, (i) => i % 256)); | 25 new List.generate(10 * 1024, (i) => i % 256)); |
| 27 | 26 |
| 28 Future<SecureServerSocket> startServer() { | 27 Future<SecureServerSocket> startServer() { |
| 29 return SecureServerSocket.bind("localhost", | 28 return SecureServerSocket.bind("localhost", |
| 30 0, | 29 0, |
| 31 serverContext).then((server) { | 30 serverContext).then((server) { |
| 32 server.listen((SecureSocket request) async { | 31 server.listen((SecureSocket request) async { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Expect.fail('Unexpected error: $e'); | 71 Expect.fail('Unexpected error: $e'); |
| 73 }, onDone: () { | 72 }, onDone: () { |
| 74 Expect.equals(body.length, DATA.length); | 73 Expect.equals(body.length, DATA.length); |
| 75 for (int i = 0; i < body.length; i++) { | 74 for (int i = 0; i < body.length; i++) { |
| 76 Expect.equals(body[i], DATA[i]); | 75 Expect.equals(body[i], DATA[i]); |
| 77 } | 76 } |
| 78 server.close(); | 77 server.close(); |
| 79 asyncEnd(); | 78 asyncEnd(); |
| 80 }); | 79 }); |
| 81 } | 80 } |
| OLD | NEW |