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

Unified Diff: tests/standalone/io/secure_bad_certificate_test.dart

Issue 20316002: dart:io | Fix handling of exceptions from onBadCertificate callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: try again Created 7 years, 5 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_bad_certificate_test.dart
diff --git a/tests/standalone/io/secure_bad_certificate_test.dart b/tests/standalone/io/secure_bad_certificate_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ccdbf324b9d589dd6b1792bd8c28077e2550179e
--- /dev/null
+++ b/tests/standalone/io/secure_bad_certificate_test.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// This test verifies that the bad certificate callback works.
+
+import "package:expect/expect.dart";
+import "package:path/path.dart";
+import "dart:async";
+import "dart:io";
+
+const HOST_NAME = "localhost";
+const CERTIFICATE = "localhost_cert";
+
+
+String certificateDatabase() =>
+ join(dirname(new Options().script), 'pkcert');
+
+Future<SecureServerSocket> runServer() {
+ SecureSocket.initialize(database: certificateDatabase(),
+ password: 'dartdart');
+
+ return SecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE)
+ .then((SecureServerSocket server) {
+ server.listen((SecureSocket socket) {
+ socket.listen((_) { },
+ onDone: () {
+ socket.close();
+ });
+ }, onError: (e) => Expect.isTrue(e is HandshakeException));
+ return server;
+ });
+}
+
+
+void main() {
+ final options = new Options();
+ var clientScript = join(dirname(options.script),
+ 'secure_bad_certificate_client.dart');
+
+ Future clientProcess(int port, String acceptCertificate) {
+ return Process.run(options.executable,
+ [clientScript, port.toString(), acceptCertificate])
+ .then((ProcessResult result) {
+ if (result.exitCode != 0) {
+ print("Client failed, stdout:");
+ print(result.stdout);
+ print(" stderr:");
+ print(result.stderr);
+ Expect.fail('Client subprocess exit code: ${result.exitCode}');
+ }
+ });
+ }
+
+ runServer().then((server) {
+ Future.wait([clientProcess(server.port, 'true'),
+ clientProcess(server.port, 'false'),
+ clientProcess(server.port, 'fisk'),
+ clientProcess(server.port, 'exception')]).then((_) {
+ server.close();
+ });
+ });
+}
« no previous file with comments | « tests/standalone/io/secure_bad_certificate_client.dart ('k') | tests/standalone/io/secure_server_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698