| 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 verifies that failing secure connection attempts always complete | 5 // This test verifies that failing secure connection attempts always complete |
| 6 // their returned future. | 6 // their returned future. |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "package:path/path.dart"; | 9 import "package:path/path.dart"; |
| 10 import "dart:async"; | 10 import "dart:async"; |
| 11 import "dart:io"; | 11 import "dart:io"; |
| 12 | 12 |
| 13 const HOST_NAME = "localhost"; | 13 const HOST_NAME = "localhost"; |
| 14 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 14 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 15 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | |
| 16 | 15 |
| 17 SecurityContext serverContext = new SecurityContext() | 16 SecurityContext serverContext = new SecurityContext() |
| 18 ..useCertificateChainBytes(readLocalFile( | 17 ..useCertificateChainSync(localFile( |
| 19 'certificates/untrusted_server_chain.pem')) | 18 'certificates/untrusted_server_chain.pem')) |
| 20 ..usePrivateKeyBytes(readLocalFile('certificates/untrusted_server_key.pem'), | 19 ..usePrivateKeySync(localFile('certificates/untrusted_server_key.pem'), |
| 21 password: 'dartdart'); | 20 password: 'dartdart'); |
| 22 | 21 |
| 23 Future<SecureServerSocket> runServer() { | 22 Future<SecureServerSocket> runServer() { |
| 24 return SecureServerSocket.bind(HOST_NAME, 0, serverContext) | 23 return SecureServerSocket.bind(HOST_NAME, 0, serverContext) |
| 25 .then((SecureServerSocket server) { | 24 .then((SecureServerSocket server) { |
| 26 server.listen((SecureSocket socket) { | 25 server.listen((SecureSocket socket) { |
| 27 socket.listen((_) { }, | 26 socket.listen((_) { }, |
| 28 onDone: () { | 27 onDone: () { |
| 29 socket.close(); | 28 socket.close(); |
| 30 }); | 29 }); |
| 31 }, onError: (e) => Expect.isTrue(e is HandshakeException)); | 30 }, onError: (e) => Expect.isTrue(e is HandshakeException)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 } | 51 } |
| 53 }); | 52 }); |
| 54 } | 53 } |
| 55 | 54 |
| 56 runServer().then((server) { | 55 runServer().then((server) { |
| 57 clientProcess(server.port).then((_) { | 56 clientProcess(server.port).then((_) { |
| 58 server.close(); | 57 server.close(); |
| 59 }); | 58 }); |
| 60 }); | 59 }); |
| 61 } | 60 } |
| OLD | NEW |