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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Client for secure_bad_certificate_test, that runs in a subprocess.
6 // The test verifies that the client bad certificate callback works.
7
8 import "dart:async";
9 import "dart:io";
10
11 class ExpectException implements Exception {
12 ExpectException(this.message);
13 String toString() => "ExpectException: $message";
14 String message;
15 }
16
17 void expect(condition) {
18 if (!condition) {
19 throw new ExpectException('');
20 }
21 }
22
23 const HOST_NAME = "localhost";
24
25 void runClient(int port, result) {
26 bool badCertificateCallback(X509Certificate certificate) {
27 expect('CN=localhost' == certificate.subject);
28 expect('CN=myauthority' == certificate.issuer);
29 expect(result != 'exception'); // Throw exception if one is requested.
30 if (result == 'true') result = true;
31 if (result == 'false') result = false;
32 return result;
33 }
34
35 SecureSocket.connect(HOST_NAME,
36 port,
37 onBadCertificate: badCertificateCallback)
38 .then((SecureSocket socket) {
39 expect(result);
40 socket.close();
41 },
42 onError: (error) {
43 expect(result != true);
44 if (result == false) {
45 expect(error is HandshakeException);
46 } else if (result == 'exception') {
47 expect(error is ExpectException);
48 } else {
49 expect(error is ArgumentError);
50 }
51 });
52 }
53
54
55 void main() {
56 final args = new Options().arguments;
57 SecureSocket.initialize();
58 runClient(int.parse(args[0]), args[1]);
59 }
OLDNEW
« 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