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

Unified Diff: tests/standalone/io/secure_bad_certificate_client.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_client.dart
diff --git a/tests/standalone/io/secure_bad_certificate_client.dart b/tests/standalone/io/secure_bad_certificate_client.dart
new file mode 100644
index 0000000000000000000000000000000000000000..440bca2a4a5bc08973b6953bab080b14137bd7bc
--- /dev/null
+++ b/tests/standalone/io/secure_bad_certificate_client.dart
@@ -0,0 +1,59 @@
+// 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.
+
+// Client for secure_bad_certificate_test, that runs in a subprocess.
+// The test verifies that the client bad certificate callback works.
+
+import "dart:async";
+import "dart:io";
+
+class ExpectException implements Exception {
+ ExpectException(this.message);
+ String toString() => "ExpectException: $message";
+ String message;
+}
+
+void expect(condition) {
+ if (!condition) {
+ throw new ExpectException('');
+ }
+}
+
+const HOST_NAME = "localhost";
+
+void runClient(int port, result) {
+ bool badCertificateCallback(X509Certificate certificate) {
+ expect('CN=localhost' == certificate.subject);
+ expect('CN=myauthority' == certificate.issuer);
+ expect(result != 'exception'); // Throw exception if one is requested.
+ if (result == 'true') result = true;
+ if (result == 'false') result = false;
+ return result;
+ }
+
+ SecureSocket.connect(HOST_NAME,
+ port,
+ onBadCertificate: badCertificateCallback)
+ .then((SecureSocket socket) {
+ expect(result);
+ socket.close();
+ },
+ onError: (error) {
+ expect(result != true);
+ if (result == false) {
+ expect(error is HandshakeException);
+ } else if (result == 'exception') {
+ expect(error is ExpectException);
+ } else {
+ expect(error is ArgumentError);
+ }
+ });
+}
+
+
+void main() {
+ final args = new Options().arguments;
+ SecureSocket.initialize();
+ runClient(int.parse(args[0]), args[1]);
+}
« no previous file with comments | « tests/standalone/io/raw_secure_server_socket_test.dart ('k') | tests/standalone/io/secure_bad_certificate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698