| 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 secure connections that fail due to |
| 6 // unauthenticated certificates throw exceptions in HttpClient. |
| 6 | 7 |
| 7 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 8 import "package:path/path.dart"; | 9 import "package:path/path.dart"; |
| 9 import "dart:async"; | 10 import "dart:async"; |
| 10 import "dart:io"; | 11 import "dart:io"; |
| 11 | 12 |
| 12 const HOST_NAME = "localhost"; | 13 const HOST_NAME = "localhost"; |
| 13 const CERTIFICATE = "localhost_cert"; | 14 const CERTIFICATE = "localhost_cert"; |
| 14 | 15 |
| 15 Future<SecureServerSocket> runServer() { | 16 Future<SecureServerSocket> runServer() { |
| 16 SecureSocket.initialize( | 17 SecureSocket.initialize( |
| 17 database: join(dirname(new Options().script), 'pkcert'), | 18 database: join(dirname(new Options().script), 'pkcert'), |
| 18 password: 'dartdart'); | 19 password: 'dartdart'); |
| 19 | 20 |
| 20 return HttpServer.bindSecure( | 21 return HttpServer.bindSecure( |
| 21 HOST_NAME, 0, backlog: 5, certificateName: 'localhost_cert') | 22 HOST_NAME, 0, backlog: 5, certificateName: 'localhost_cert') |
| 22 .then((server) { | 23 .then((server) { |
| 23 server.listen((HttpRequest request) { | 24 server.listen((HttpRequest request) { |
| 24 request.listen((_) { }, onDone: () { request.response.close(); }); | 25 request.listen((_) { }, onDone: () { request.response.close(); }); |
| 25 }, onError: (e) { if (e is! HandshakeException) throw e; }); | 26 }, onError: (e) { if (e is! HandshakeException) throw e; }); |
| 26 return server; | 27 return server; |
| 27 }); | 28 }); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void main() { | 31 void main() { |
| 31 final options = new Options(); | 32 final options = new Options(); |
| 32 var clientScript = | 33 var clientScript = join(dirname(options.script), |
| 33 join(dirname(options.script), 'https_bad_certificate_client.dart'); | 34 'https_unauthorized_client.dart'); |
| 34 | 35 |
| 35 Future clientProcess(int port, String acceptCertificate) { | 36 Future clientProcess(int port) { |
| 36 return Process.run(options.executable, | 37 return Process.run(options.executable, |
| 37 [clientScript, port.toString(), acceptCertificate]) | 38 [clientScript, port.toString()]) |
| 38 .then((ProcessResult result) { | 39 .then((ProcessResult result) { |
| 39 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { | 40 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { |
| 40 print("Client failed, acceptCertificate: $acceptCertificate"); | 41 print("Client failed"); |
| 41 print(" stdout:"); | 42 print(" stdout:"); |
| 42 print(result.stdout); | 43 print(result.stdout); |
| 43 print(" stderr:"); | 44 print(" stderr:"); |
| 44 print(result.stderr); | 45 print(result.stderr); |
| 45 Expect.fail('Client subprocess exit code: ${result.exitCode}'); | 46 Expect.fail('Client subprocess exit code: ${result.exitCode}'); |
| 46 } | 47 } |
| 47 }); | 48 }); |
| 48 } | 49 } |
| 49 | 50 |
| 50 runServer().then((server) { | 51 runServer().then((server) { |
| 51 Future.wait([clientProcess(server.port, 'true'), | 52 clientProcess(server.port).then((_) { |
| 52 clientProcess(server.port, 'false'), | |
| 53 clientProcess(server.port, 'fisk'), | |
| 54 clientProcess(server.port, 'exception')]).then((_) { | |
| 55 server.close(); | 53 server.close(); |
| 56 }); | 54 }); |
| 57 }); | 55 }); |
| 58 } | 56 } |
| OLD | NEW |