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

Side by Side Diff: tests/standalone/io/secure_socket_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: Free persistent handle upon destruction. 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // The --short_socket_write option does not work with external server 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. 8 // www.google.dk. Add this to the test when we have secure server sockets.
9 // See TODO below. 9 // See TODO below.
10 10
11 #import("dart:isolate"); 11 #import("dart:isolate");
12 #import("dart:io"); 12 #import("dart:io");
13 13
14 void WriteAndClose(Socket socket, String message) { 14 void WriteAndClose(Socket socket, String message) {
15 var data = message.charCodes; 15 var data = message.charCodes;
16 int written = 0; 16 int written = 0;
17 void write() { 17 void write() {
18 written += socket.writeList(data, written, data.length - written); 18 written += socket.writeList(data, written, data.length - written);
19 if (written < data.length) { 19 if (written < data.length) {
20 socket.onWrite = write; 20 socket.onWrite = write;
21 } else { 21 } else {
22 socket.close(true); 22 socket.close(true);
23 } 23 }
24 } 24 }
25 write(); 25 write();
26 } 26 }
27 27
28 void main() { 28 void main() {
29 ReceivePort keepAlive = new ReceivePort();
29 SecureSocket.initialize(); 30 SecureSocket.initialize();
30 // TODO(3593): Use a Dart HTTPS server for this test. 31 // TODO(3593): Use a Dart HTTPS server for this test.
31 // When we use a Dart HTTPS server, allow --short_socket_write. The flag 32 // When we use a Dart HTTPS server, allow --short_socket_write. The flag
32 // causes fragmentation of the client hello message, which doesn't seem to 33 // causes fragmentation of the client hello message, which doesn't seem to
33 // work with www.google.dk. 34 // work with www.google.dk.
34 var secure = new SecureSocket("www.google.dk", 443); 35 var secure = new SecureSocket("www.google.dk", 443);
35 List<String> chunks = <String>[]; 36 List<String> chunks = <String>[];
36 secure.onConnect = () { 37 secure.onConnect = () {
37 WriteAndClose(secure, "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n"); 38 WriteAndClose(secure, "GET / HTTP/1.0\r\nHost: www.google.dk\r\n\r\n");
38 }; 39 };
39 var useReadList; // Mutually recursive onData callbacks. 40 var useReadList; // Mutually recursive onData callbacks.
40 void useRead() { 41 void useRead() {
41 var data = secure.read(); 42 var data = secure.read();
42 var received = new String.fromCharCodes(data); 43 var received = new String.fromCharCodes(data);
43 chunks.add(received); 44 chunks.add(received);
44 secure.onData = useReadList; 45 secure.onData = useReadList;
45 } 46 }
46 useReadList = () { 47 useReadList = () {
47 var buffer = new List(2000); 48 var buffer = new List(2000);
48 int len = secure.readList(buffer, 0, 2000); 49 int len = secure.readList(buffer, 0, 2000);
49 var received = new String.fromCharCodes(buffer.getRange(0, len)); 50 var received = new String.fromCharCodes(buffer.getRange(0, len));
50 chunks.add(received); 51 chunks.add(received);
51 secure.onData = useRead; 52 secure.onData = useRead;
52 }; 53 };
53 secure.onData = useRead; 54 secure.onData = useRead;
54 secure.onClosed = () { 55 secure.onClosed = () {
55 String fullPage = Strings.concatAll(chunks); 56 String fullPage = Strings.concatAll(chunks);
56 Expect.isTrue(fullPage.contains('</body></html>')); 57 Expect.isTrue(fullPage.contains('</body></html>'));
58 keepAlive.close();
57 }; 59 };
58 } 60 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_socket_bad_certificate_test.dart ('k') | tests/standalone/io/secure_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698