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