Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1085)

Side by Side Diff: tests/standalone/io/https_bad_certificate_test.dart

Issue 22816008: dart:io | Add badCertificateCallback to HttpClient. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve documentation comments. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/io/https_bad_certificate_client.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. 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() {
16 SecureSocket.initialize(
17 database: join(dirname(new Options().script), 'pkcert'),
18 password: 'dartdart');
15 19
16 String certificateDatabase() => 20 return HttpServer.bindSecure(
17 join(dirname(new Options().script), 'pkcert'); 21 HOST_NAME, 0, backlog: 5, certificateName: 'localhost_cert')
18 22 .then((server) {
19 Future<SecureServerSocket> runServer() { 23 server.listen((HttpRequest request) {
20 SecureSocket.initialize(database: certificateDatabase(), 24 request.listen((_) { }, onDone: () { request.response.close(); });
21 password: 'dartdart'); 25 }, onError: (e) { if (e is! HandshakeException) throw e; });
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; 26 return server;
32 }); 27 });
33 } 28 }
34 29
35
36 void main() { 30 void main() {
37 final options = new Options(); 31 final options = new Options();
38 var clientScript = join(dirname(options.script), 32 var clientScript =
39 'secure_bad_certificate_client.dart'); 33 join(dirname(options.script), 'https_bad_certificate_client.dart');
40 34
41 Future clientProcess(int port, String acceptCertificate) { 35 Future clientProcess(int port, String acceptCertificate) {
42 return Process.run(options.executable, 36 return Process.run(options.executable,
43 [clientScript, port.toString(), acceptCertificate]) 37 [clientScript, port.toString(), acceptCertificate])
44 .then((ProcessResult result) { 38 .then((ProcessResult result) {
45 if (result.exitCode != 0) { 39 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) {
46 print("Client failed, stdout:"); 40 print("Client failed, acceptCertificate: $acceptCertificate");
41 print(" stdout:");
47 print(result.stdout); 42 print(result.stdout);
48 print(" stderr:"); 43 print(" stderr:");
49 print(result.stderr); 44 print(result.stderr);
50 Expect.fail('Client subprocess exit code: ${result.exitCode}'); 45 Expect.fail('Client subprocess exit code: ${result.exitCode}');
51 } 46 }
52 }); 47 });
53 } 48 }
54 49
55 runServer().then((server) { 50 runServer().then((server) {
56 Future.wait([clientProcess(server.port, 'true'), 51 Future.wait([clientProcess(server.port, 'true'),
57 clientProcess(server.port, 'false'), 52 clientProcess(server.port, 'false'),
58 clientProcess(server.port, 'fisk'), 53 clientProcess(server.port, 'fisk'),
59 clientProcess(server.port, 'exception')]).then((_) { 54 clientProcess(server.port, 'exception')]).then((_) {
60 server.close(); 55 server.close();
61 }); 56 });
62 }); 57 });
63 } 58 }
OLDNEW
« no previous file with comments | « tests/standalone/io/https_bad_certificate_client.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698