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

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

Issue 22816008: dart:io | Add badCertificateCallback to HttpClient. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve documentation comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | tests/standalone/io/https_bad_certificate_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 https_bad_certificate_test, that runs in a subprocess.
6 // It verifies that the client bad certificate callback works in HttpClient.
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 Future runHttpClient(int port, result) {
26 bool badCertificateCallback(X509Certificate certificate,
27 String host,
28 int callbackPort) {
29 expect(HOST_NAME == host);
30 expect(callbackPort == port);
31 expect('CN=localhost' == certificate.subject);
32 expect('CN=myauthority' == certificate.issuer);
33 expect(result != 'exception'); // Throw exception if one is requested.
34 if (result == 'true') return true;
35 if (result == 'false') return false;
36 return result;
37 }
38
39 HttpClient client = new HttpClient();
40
41 var testFutures = [];
42 testFutures.add(client.getUrl(Uri.parse('https://$HOST_NAME:$port/$result'))
43 .then((HttpClientRequest request) { expect(false); },
44 onError: (e) { expect(e is HandshakeException); }));
45
46 client.badCertificateCallback = badCertificateCallback;
47 testFutures.add( client.getUrl(Uri.parse('https://$HOST_NAME:$port/$result'))
48 .then((HttpClientRequest request) {
49 expect(result == 'true');
50 request.close().then((result) { });
51 }, onError: (e) {
52 if (result == 'false') expect (e is HandshakeException);
53 else if (result == 'exception') expect (e is ExpectException);
54 else expect (e is ArgumentError);
55 }));
56
57 client.badCertificateCallback = null;
58 testFutures.add(client.getUrl(Uri.parse('https://$HOST_NAME:$port/$result'))
59 .then((HttpClientRequest request) {
60 expect(false);
61 }, onError: (e) {
62 expect(e is HandshakeException);
63 }));
64
65 return Future.wait(testFutures);
66 }
67
68 void main() {
69 final args = new Options().arguments;
70 SecureSocket.initialize();
71 int port = int.parse(args[0]);
72 runHttpClient(port, args[1])
73 .then((_) => print('SUCCESS'));
74 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | tests/standalone/io/https_bad_certificate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698