Chromium Code Reviews| OLD | NEW |
|---|---|
| (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: (){ | |
|
Mads Ager (google)
2012/12/05 07:30:53
Add space: () {
testCertificateCallback should re
| |
| 33 testCertificateCallback(host: "www.google.dk", | |
| 34 acceptCertificate: true, | |
| 35 then: (){ | |
|
Mads Ager (google)
2012/12/05 07:30:53
Ditto
| |
| 36 // TODO(whesse): Open a receive port, and close it when we get here. | |
|
Mads Ager (google)
2012/12/05 07:30:53
This is bad. Please file a high-priority bug repor
Bill Hesse
2012/12/05 12:35:38
Done.
| |
| 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, | |
| 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 | |
|
Mads Ager (google)
2012/12/05 07:30:53
Remove empty line?
Bill Hesse
2012/12/05 12:35:38
Done.
| |
| 59 Expect.isTrue(certificate.startValidity < new Date.now()); | |
| 60 Expect.isTrue(certificate.endValidity > new Date.now()); | |
| 61 return acceptCertificate; | |
| 62 }; | |
| 63 secure.onData = (){ | |
| 64 Expect.isTrue(acceptCertificate); | |
| 65 chunks.add(new String.fromCharCodes(secure.read())); | |
| 66 }; | |
| 67 secure.onClosed = () { | |
| 68 Expect.isTrue(acceptCertificate); | |
| 69 String fullPage = Strings.concatAll(chunks); | |
| 70 Expect.isTrue(fullPage.contains('</body></html>')); | |
| 71 then(); | |
| 72 }; | |
| 73 secure.onError = (e) { | |
| 74 Expect.isFalse(acceptCertificate); | |
| 75 then(); | |
| 76 }; | |
| 77 } | |
| OLD | NEW |