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

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

Issue 11415290: Add a callback to SecureSocket for certificates that fail to be authenticated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years 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) 2012, 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 // VMOptions=
6 // VMOptions=--short_socket_read
7 // The --short_socket_write option does not work with external server
8 // www.google.dk. Add this to the test when we have secure server sockets.
9 // See TODO below.
10
11 #import("dart:isolate");
12 #import("dart:io");
13
14 void WriteAndClose(Socket socket, String message) {
15 var data = message.charCodes;
16 int written = 0;
17 void write() {
18 written += socket.writeList(data, written, data.length - written);
19 if (written < data.length) {
20 socket.onWrite = write;
21 } else {
22 socket.close(true);
23 }
24 }
25 write();
26 }
27
28 void main() {
29 SecureSocket.initialize(useBuiltinRoots: false);
30 testCertificateCallback(host: "www.google.dk",
31 acceptCertificate: false,
32 then: () {
33 testCertificateCallback(host: "www.google.dk",
34 acceptCertificate: true,
35 then: () {
36 // TODO(7153): Open a receive port, and close it when we get here.
37 // Currently, it can happen that neither onClosed or onError is called.
38 // So we never reach this point. Diagnose this and fix.
39 });
40 });
41 }
42
43 void testCertificateCallback({String host,
Mads Ager (google) 2012/12/05 12:40:53 Please return a Future from here and use the 'then
Bill Hesse 2012/12/05 12:58:25 Done.
44 bool acceptCertificate,
45 Function then}) {
46 var secure = new SecureSocket(host, 443);
47 List<String> chunks = <String>[];
48 secure.onConnect = () {
49 Expect.isTrue(acceptCertificate);
50 WriteAndClose(secure, "GET / HTTP/1.0\r\nHost: $host\r\n\r\n");
51 };
52 secure.onBadCertificate = (_) { };
53 secure.onBadCertificate = null;
54 Expect.throws(() => secure.onBadCertificate = 7,
55 (e) => e is TypeError || e is SocketIOException);
56 secure.onBadCertificate = (X509Certificate certificate) {
57 Expect.isTrue(certificate.subject.contains("O=Google Inc"));
58 Expect.isTrue(certificate.startValidity < new Date.now());
59 Expect.isTrue(certificate.endValidity > new Date.now());
60 return acceptCertificate;
61 };
62 secure.onData = (){
63 Expect.isTrue(acceptCertificate);
64 chunks.add(new String.fromCharCodes(secure.read()));
65 };
66 secure.onClosed = () {
67 Expect.isTrue(acceptCertificate);
68 String fullPage = Strings.concatAll(chunks);
69 Expect.isTrue(fullPage.contains('</body></html>'));
70 then();
71 };
72 secure.onError = (e) {
73 Expect.isFalse(acceptCertificate);
74 then();
75 };
76 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_server_test.dart ('k') | tests/standalone/io/secure_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698