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

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

Issue 11308271: Add built-in root certificates to dart:io SecureSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 import "dart:io"; 5 import "dart:io";
6 import "dart:uri"; 6 import "dart:uri";
7 import "dart:isolate"; 7 import "dart:isolate";
8 8
9
10 int testGoogleUrlCount = 0;
11 void testGoogleUrl() { 9 void testGoogleUrl() {
12 HttpClient client = new HttpClient(); 10 HttpClient client = new HttpClient();
13 11
14 void testUrl(String url) { 12 void testUrl(String url) {
15 var requestUri = new Uri.fromString(url); 13 var requestUri = new Uri.fromString(url);
16 var conn = client.getUrl(requestUri); 14 var conn = client.getUrl(requestUri);
17 15
18 conn.onRequest = (HttpClientRequest request) { 16 conn.onRequest = (HttpClientRequest request) {
19 request.outputStream.close(); 17 request.outputStream.close();
20 }; 18 };
21 conn.onResponse = (HttpClientResponse response) { 19 conn.onResponse = (HttpClientResponse response) {
22 testGoogleUrlCount++;
23 Expect.isTrue(response.statusCode < 500); 20 Expect.isTrue(response.statusCode < 500);
24 if (requestUri.path.length == 0) { 21 Expect.isTrue(response.statusCode != 404);
25 Expect.isTrue(response.statusCode != 404);
26 }
27 response.inputStream.onData = () { 22 response.inputStream.onData = () {
28 response.inputStream.read(); 23 response.inputStream.read();
29 }; 24 };
30 response.inputStream.onClosed = () { 25 response.inputStream.onClosed = () {
31 if (testGoogleUrlCount == 4) client.shutdown(); 26 client.shutdown();
32 }; 27 };
33 }; 28 };
34 conn.onError = (error) => Expect.fail("Unexpected IO error $error"); 29 conn.onError = (error) => Expect.fail("Unexpected IO error $error");
35 } 30 }
36 31
37 testUrl('https://www.google.dk'); 32 testUrl('https://www.google.com');
38 testUrl('https://www.google.dk');
39 testUrl('https://www.google.dk/#q=foo');
40 testUrl('https://www.google.dk/#hl=da&q=foo');
41 }
42
43 void testBadHostName() {
44 HttpClient client = new HttpClient();
45 HttpClientConnection connection = client.getUrl(
46 new Uri.fromString("https://some.bad.host.name.7654321/"));
47 connection.onRequest = (HttpClientRequest request) {
48 Expect.fail("Should not open a request on bad hostname");
49 };
50 ReceivePort port = new ReceivePort();
51 connection.onError = (Exception error) {
52 port.close(); // We expect onError to be called, due to bad host name.
53 };
54 } 33 }
55 34
56 void InitializeSSL() { 35 void InitializeSSL() {
57 var testPkcertDatabase = 36 // The pkcert_empty database contains no certificates, so the built-in roots
58 new Path.fromNative(new Options().script).directoryPath.append('pkcert/'); 37 // must be loaded correctly for the secure connection to work.
38 var testPkcertDatabase = new Path.fromNative(new Options().script).
39 directoryPath.append('pkcert_empty');
59 SecureSocket.setCertificateDatabase(testPkcertDatabase.toNativePath()); 40 SecureSocket.setCertificateDatabase(testPkcertDatabase.toNativePath());
Mads Ager (google) 2012/11/29 20:13:05 This is where it would be nice to just call Secure
Bill Hesse 2012/11/30 12:51:16 Done.
60 } 41 }
61 42
62 void main() { 43 void main() {
63 InitializeSSL(); 44 InitializeSSL();
64 testGoogleUrl(); 45 testGoogleUrl();
65 testBadHostName();
66 } 46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698