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

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

Issue 23583002: Make dart:io SecureSocket builtin root certificate test more robust, merge test files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "package:path/path.dart";
6 import "dart:io"; 7 import "dart:io";
7 import "dart:isolate"; 8 import "dart:isolate";
8 import "dart:async"; 9 import "dart:async";
9 10
10 void testGoogleUrl() { 11 void main() {
11 ReceivePort keepAlive = new ReceivePort(); 12 var args = new Options().arguments;
12 HttpClient client = new HttpClient(); 13 if (!args.contains('--child')) {
13 client.getUrl(Uri.parse('https://www.google.com')) 14 runAllTestsInChildProcesses();
14 .then((request) => request.close()) 15 } else {
15 .then((response) => response.last) 16 InitializeSSL(useDatabase: args.contains('--database'),
16 .then((_) { 17 useBuiltinRoots: args.contains('--builtin-roots'));
17 client.close(); 18 testGoogleUrl(args.contains('--builtin-roots'));
18 keepAlive.close(); 19 }
19 });
20 } 20 }
21 21
22 void InitializeSSL() { 22 void InitializeSSL({bool useDatabase, bool useBuiltinRoots}) {
23 // If the built-in root certificates aren't loaded, the connection 23 // If the built-in root certificates aren't loaded, the connection
24 // should signal an error. 24 // should signal an error. Even when an external database is loaded,
25 SecureSocket.initialize(useBuiltinRoots: true); 25 // they should not be loaded.
26 if (useDatabase) {
27 var certificateDatabase = join(dirname(Platform.script), 'pkcert');
28 SecureSocket.initialize(database: certificateDatabase,
29 password: 'dartdart',
30 useBuiltinRoots: useBuiltinRoots);
31 } else {
32 SecureSocket.initialize(useBuiltinRoots: useBuiltinRoots);
33 }
26 } 34 }
27 35
28 void main() { 36 void testGoogleUrl(bool expectSuccess) {
29 InitializeSSL(); 37 // We need to use an external server that is backed by a
30 testGoogleUrl(); 38 // built-in root certificate authority.
39
40 // First, check if the lookup fails. If not then run the test.
41 InternetAddress.lookup('www.google.com').then((_) {
42 HttpClient client = new HttpClient();
43 client.getUrl(Uri.parse('https://www.google.com'))
44 .then((request) => request.close())
45 .then((response) {
46 Expect.isTrue(expectSuccess, "Unexpected successful connection");
47 print('SUCCESS');
Søren Gjesse 2013/08/27 12:16:46 Debug print.
Bill Hesse 2013/08/27 12:21:33 This is not debug printing. This is communication
48 return response.last;
49 })
50 .catchError((error) {
51 // Allow SocketExceptions if www.google.com is unreachable or down.
52 Expect.isTrue((!expectSuccess && error is HandshakeException) ||
53 error is SocketException);
54 print('SUCCESS');
Søren Gjesse 2013/08/27 12:16:46 Ditto.
55 })
56 .whenComplete(client.close);
57 },
58 onError: (e) {
59 // Lookup failed.
60 Expect.isTrue(e is SocketException);
61 print('SUCCESS');
62 });
31 } 63 }
64
65 void runAllTestsInChildProcesses() {
66 Future runChild(List<String> scriptArguments) {
67 return Process.run(Platform.executable,
68 []..addAll(Platform.executableArguments)
69 ..add(Platform.script)
70 ..addAll(scriptArguments))
71 .then((ProcessResult result) {
72 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) {
73 print("Client failed");
74 print(" stdout:");
75 print(result.stdout);
76 print(" stderr:");
77 print(result.stderr);
78 Expect.fail('Client subprocess exit code: ${result.exitCode}');
79 }
80 });
81 }
82
83 ReceivePort keepAlive = new ReceivePort();
84 Future.wait([runChild(['--child']),
85 runChild(['--child', '--database']),
86 runChild(['--child', '--builtin-roots']),
87 runChild(['--child', '--builtin-roots', '--database'])])
88 .then((_) => keepAlive.close());
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698