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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/io/secure_builtin_roots_test.dart
diff --git a/tests/standalone/io/secure_builtin_roots_test.dart b/tests/standalone/io/secure_builtin_roots_test.dart
index 32609a84c796c78d77d7a91dd4f15e270f4da767..be0a467322e519db5112c223d5650eccbddfd935 100644
--- a/tests/standalone/io/secure_builtin_roots_test.dart
+++ b/tests/standalone/io/secure_builtin_roots_test.dart
@@ -3,29 +3,87 @@
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
+import "package:path/path.dart";
import "dart:io";
import "dart:isolate";
import "dart:async";
-void testGoogleUrl() {
- ReceivePort keepAlive = new ReceivePort();
- HttpClient client = new HttpClient();
- client.getUrl(Uri.parse('https://www.google.com'))
- .then((request) => request.close())
- .then((response) => response.last)
- .then((_) {
- client.close();
- keepAlive.close();
- });
+void main() {
+ var args = new Options().arguments;
+ if (!args.contains('--child')) {
+ runAllTestsInChildProcesses();
+ } else {
+ InitializeSSL(useDatabase: args.contains('--database'),
+ useBuiltinRoots: args.contains('--builtin-roots'));
+ testGoogleUrl(args.contains('--builtin-roots'));
+ }
}
-void InitializeSSL() {
+void InitializeSSL({bool useDatabase, bool useBuiltinRoots}) {
// If the built-in root certificates aren't loaded, the connection
- // should signal an error.
- SecureSocket.initialize(useBuiltinRoots: true);
+ // should signal an error. Even when an external database is loaded,
+ // they should not be loaded.
+ if (useDatabase) {
+ var certificateDatabase = join(dirname(Platform.script), 'pkcert');
+ SecureSocket.initialize(database: certificateDatabase,
+ password: 'dartdart',
+ useBuiltinRoots: useBuiltinRoots);
+ } else {
+ SecureSocket.initialize(useBuiltinRoots: useBuiltinRoots);
+ }
}
-void main() {
- InitializeSSL();
- testGoogleUrl();
+void testGoogleUrl(bool expectSuccess) {
+ // We need to use an external server that is backed by a
+ // built-in root certificate authority.
+
+ // First, check if the lookup fails. If not then run the test.
+ InternetAddress.lookup('www.google.com').then((_) {
+ HttpClient client = new HttpClient();
+ client.getUrl(Uri.parse('https://www.google.com'))
+ .then((request) => request.close())
+ .then((response) {
+ Expect.isTrue(expectSuccess, "Unexpected successful connection");
+ 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
+ return response.last;
+ })
+ .catchError((error) {
+ // Allow SocketExceptions if www.google.com is unreachable or down.
+ Expect.isTrue((!expectSuccess && error is HandshakeException) ||
+ error is SocketException);
+ print('SUCCESS');
Søren Gjesse 2013/08/27 12:16:46 Ditto.
+ })
+ .whenComplete(client.close);
+ },
+ onError: (e) {
+ // Lookup failed.
+ Expect.isTrue(e is SocketException);
+ print('SUCCESS');
+ });
}
+
+void runAllTestsInChildProcesses() {
+ Future runChild(List<String> scriptArguments) {
+ return Process.run(Platform.executable,
+ []..addAll(Platform.executableArguments)
+ ..add(Platform.script)
+ ..addAll(scriptArguments))
+ .then((ProcessResult result) {
+ if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) {
+ print("Client failed");
+ print(" stdout:");
+ print(result.stdout);
+ print(" stderr:");
+ print(result.stderr);
+ Expect.fail('Client subprocess exit code: ${result.exitCode}');
+ }
+ });
+ }
+
+ ReceivePort keepAlive = new ReceivePort();
+ Future.wait([runChild(['--child']),
+ runChild(['--child', '--database']),
+ runChild(['--child', '--builtin-roots']),
+ runChild(['--child', '--builtin-roots', '--database'])])
+ .then((_) => keepAlive.close());
+ }

Powered by Google App Engine
This is Rietveld 408576698