| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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 | 
|  | 3 // BSD-style license that can be found in the LICENSE file. | 
|  | 4 | 
|  | 5 // This test verifies that the bad certificate callback works. | 
|  | 6 | 
|  | 7 import "package:expect/expect.dart"; | 
|  | 8 import "package:path/path.dart"; | 
|  | 9 import "dart:async"; | 
|  | 10 import "dart:io"; | 
|  | 11 | 
|  | 12 const HOST_NAME = "localhost"; | 
|  | 13 const CERTIFICATE = "localhost_cert"; | 
|  | 14 | 
|  | 15 | 
|  | 16 String certificateDatabase() => | 
|  | 17     join(dirname(new Options().script), 'pkcert'); | 
|  | 18 | 
|  | 19 Future<SecureServerSocket> runServer() { | 
|  | 20   SecureSocket.initialize(database: certificateDatabase(), | 
|  | 21                           password: 'dartdart'); | 
|  | 22 | 
|  | 23   return SecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE) | 
|  | 24       .then((SecureServerSocket server) { | 
|  | 25     server.listen((SecureSocket socket) { | 
|  | 26       socket.listen((_) { }, | 
|  | 27                     onDone: () { | 
|  | 28                       socket.close(); | 
|  | 29                     }); | 
|  | 30     }, onError: (e) => Expect.isTrue(e is HandshakeException)); | 
|  | 31     return server; | 
|  | 32   }); | 
|  | 33 } | 
|  | 34 | 
|  | 35 | 
|  | 36 void main() { | 
|  | 37   final options = new Options(); | 
|  | 38   var clientScript = join(dirname(options.script), | 
|  | 39                           'secure_bad_certificate_client.dart'); | 
|  | 40 | 
|  | 41   Future clientProcess(int port, String acceptCertificate) { | 
|  | 42     return Process.run(options.executable, | 
|  | 43         [clientScript, port.toString(), acceptCertificate]) | 
|  | 44         .then((ProcessResult result) { | 
|  | 45       if (result.exitCode != 0) { | 
|  | 46         print("Client failed, stdout:"); | 
|  | 47         print(result.stdout); | 
|  | 48         print("  stderr:"); | 
|  | 49         print(result.stderr); | 
|  | 50         Expect.fail('Client subprocess exit code: ${result.exitCode}'); | 
|  | 51       } | 
|  | 52     }); | 
|  | 53   } | 
|  | 54 | 
|  | 55   runServer().then((server) { | 
|  | 56     Future.wait([clientProcess(server.port, 'true'), | 
|  | 57                  clientProcess(server.port, 'false'), | 
|  | 58                  clientProcess(server.port, 'fisk'), | 
|  | 59                  clientProcess(server.port, 'exception')]).then((_) { | 
|  | 60       server.close(); | 
|  | 61     }); | 
|  | 62   }); | 
|  | 63 } | 
| OLD | NEW | 
|---|