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 the bad certificate callback works in HttpClient. | 5 // This test verifies that the bad certificate callback works in HttpClient. |
6 | 6 |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 | 9 |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
11 | 11 |
12 final HOST_NAME = 'localhost'; | 12 final HOST_NAME = 'localhost'; |
13 | 13 |
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(); |
15 | 16 |
16 SecurityContext serverContext = new SecurityContext() | 17 SecurityContext serverContext = new SecurityContext() |
17 ..useCertificateChain(localFile('certificates/server_chain.pem')) | 18 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
18 ..usePrivateKey(localFile('certificates/server_key.pem'), | 19 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), |
19 password: 'dartdart'); | 20 password: 'dartdart'); |
20 | 21 |
21 class CustomException {} | 22 class CustomException {} |
22 | 23 |
23 main() async { | 24 main() async { |
24 var HOST = (await InternetAddress.lookup(HOST_NAME)).first; | 25 var HOST = (await InternetAddress.lookup(HOST_NAME)).first; |
25 var server = await HttpServer.bindSecure(HOST, 0, serverContext, backlog: 5); | 26 var server = await HttpServer.bindSecure(HOST, 0, serverContext, backlog: 5); |
26 server.listen((request) { | 27 server.listen((request) { |
27 request.listen((_) { | 28 request.listen((_) { |
28 }, onDone: () { | 29 }, onDone: () { |
29 request.response.close(); | 30 request.response.close(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 Expect.notEquals(result, 'pass'); | 73 Expect.notEquals(result, 'pass'); |
73 if (result == 'fail') { | 74 if (result == 'fail') { |
74 Expect.isTrue(error is HandshakeException); | 75 Expect.isTrue(error is HandshakeException); |
75 } else if (result == 'throw') { | 76 } else if (result == 'throw') { |
76 Expect.isTrue(error is CustomException); | 77 Expect.isTrue(error is CustomException); |
77 } else { | 78 } else { |
78 Expect.fail('Unknown expectation $result'); | 79 Expect.fail('Unknown expectation $result'); |
79 } | 80 } |
80 } | 81 } |
81 } | 82 } |
OLD | NEW |