| 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 secure connections that fail due to | 5 // This test verifies that secure connections that fail due to |
| 6 // unauthenticated certificates throw exceptions in HttpClient. | 6 // unauthenticated certificates throw exceptions in HttpClient. |
| 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 const CERTIFICATE = "localhost_cert"; | 14 const CERTIFICATE = "localhost_cert"; |
| 15 | 15 |
| 16 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 16 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 17 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | 17 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); |
| 18 | 18 |
| 19 SecurityContext untrustedServerContext = new SecurityContext() | 19 SecurityContext untrustedServerContext = new SecurityContext() |
| 20 ..useCertificateChainBytes(readLocalFile( | 20 ..useCertificateChainBytes(readLocalFile( |
| 21 'certificates/untrusted_server_chain.pem')) | 21 'certificates/untrusted_server_chain.pem')) |
| 22 ..usePrivateKeyBytes(readLocalFile('certificates/untrusted_server_key.pem'), | 22 ..usePrivateKeyBytes(readLocalFile('certificates/untrusted_server_key.pem'), |
| 23 password: 'dartdart'); | 23 password: 'dartdart'); |
| 24 | 24 |
| 25 SecurityContext clientContext = new SecurityContext() | 25 SecurityContext clientContext = new SecurityContext() |
| 26 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 26 ..setTrustedCertificatesBytes( |
| 27 readLocalFile('certificates/trusted_certs.pem')); |
| 27 | 28 |
| 28 Future<SecureServerSocket> runServer() { | 29 Future<SecureServerSocket> runServer() { |
| 29 return HttpServer.bindSecure( | 30 return HttpServer.bindSecure( |
| 30 HOST_NAME, 0, untrustedServerContext, backlog: 5) | 31 HOST_NAME, 0, untrustedServerContext, backlog: 5) |
| 31 .then((server) { | 32 .then((server) { |
| 32 server.listen((HttpRequest request) { | 33 server.listen((HttpRequest request) { |
| 33 request.listen((_) { }, onDone: () { request.response.close(); }); | 34 request.listen((_) { }, onDone: () { request.response.close(); }); |
| 34 }, onError: (e) { if (e is! HandshakeException) throw e; }); | 35 }, onError: (e) { if (e is! HandshakeException) throw e; }); |
| 35 return server; | 36 return server; |
| 36 }); | 37 }); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 54 } | 55 } |
| 55 }); | 56 }); |
| 56 } | 57 } |
| 57 | 58 |
| 58 runServer().then((server) { | 59 runServer().then((server) { |
| 59 clientProcess(server.port).then((_) { | 60 clientProcess(server.port).then((_) { |
| 60 server.close(); | 61 server.close(); |
| 61 }); | 62 }); |
| 62 }); | 63 }); |
| 63 } | 64 } |
| OLD | NEW |