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

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

Issue 1319703002: Breaking Change: merge BoringSSL branch into master (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
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:async"; 5 import "dart:async";
6 import "dart:io"; 6 import "dart:io";
7 import "dart:isolate"; 7 import "dart:isolate";
8 8
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 10
11 InternetAddress HOST; 11 InternetAddress HOST;
12 const CERTIFICATE = "localhost_cert"; 12
13 String localFile(path) => Platform.script.resolve(path).toFilePath();
14
15 SecurityContext serverContext = new SecurityContext()
16 ..useCertificateChain(localFile('certificates/server_chain.pem'))
17 ..usePrivateKey(localFile('certificates/server_key.pem'),
18 password: 'dartdart');
19
20 SecurityContext clientContext = new SecurityContext()
21 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem'));
13 22
14 void testListenOn() { 23 void testListenOn() {
15 void test(void onDone()) { 24 void test(void onDone()) {
16 HttpServer.bindSecure(HOST, 25 HttpServer.bindSecure(HOST,
17 0, 26 0,
18 backlog: 5, 27 serverContext,
19 certificateName: CERTIFICATE).then((server) { 28 backlog: 5).then((server) {
20 ReceivePort serverPort = new ReceivePort(); 29 ReceivePort serverPort = new ReceivePort();
21 server.listen((HttpRequest request) { 30 server.listen((HttpRequest request) {
22 request.listen( 31 request.listen(
23 (_) { }, 32 (_) { },
24 onDone: () { 33 onDone: () {
25 request.response.close(); 34 request.response.close();
26 serverPort.close(); 35 serverPort.close();
27 }); 36 });
28 }); 37 });
29 38
30 HttpClient client = new HttpClient(); 39 HttpClient client = new HttpClient(context: clientContext);
31 ReceivePort clientPort = new ReceivePort(); 40 ReceivePort clientPort = new ReceivePort();
32 client.getUrl(Uri.parse("https://${HOST.host}:${server.port}/")) 41 client.getUrl(Uri.parse("https://${HOST.host}:${server.port}/"))
33 .then((HttpClientRequest request) { 42 .then((HttpClientRequest request) {
34 return request.close(); 43 return request.close();
35 }) 44 })
36 .then((HttpClientResponse response) { 45 .then((HttpClientResponse response) {
37 response.listen( 46 response.listen(
38 (_) { }, 47 (_) { },
39 onDone: () { 48 onDone: () {
40 client.close(); 49 client.close();
(...skipping 10 matching lines...) Expand all
51 }); 60 });
52 }); 61 });
53 } 62 }
54 63
55 // Test two servers in succession. 64 // Test two servers in succession.
56 test(() { 65 test(() {
57 test(() { }); 66 test(() { });
58 }); 67 });
59 } 68 }
60 69
61 void InitializeSSL() {
62 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
63 SecureSocket.initialize(database: testPkcertDatabase,
64 password: 'dartdart');
65 }
66
67 void testEarlyClientClose() { 70 void testEarlyClientClose() {
68 HttpServer.bindSecure(HOST, 71 HttpServer.bindSecure(HOST,
69 0, 72 0,
70 certificateName: 'localhost_cert').then((server) { 73 serverContext).then((server) {
71 server.listen( 74 server.listen(
72 (request) { 75 (request) {
73 String name = Platform.script.toFilePath(); 76 String name = Platform.script.toFilePath();
74 new File(name).openRead().pipe(request.response) 77 new File(name).openRead().pipe(request.response)
75 .catchError((e) { /* ignore */ }); 78 .catchError((e) { /* ignore */ });
76 }); 79 });
77 80
78 var count = 0; 81 var count = 0;
79 makeRequest() { 82 makeRequest() {
80 Socket.connect(HOST, server.port).then((socket) { 83 Socket.connect(HOST, server.port).then((socket) {
81 var data = "Invalid TLS handshake"; 84 var data = "Invalid TLS handshake";
82 socket.write(data); 85 socket.write(data);
83 socket.close(); 86 socket.close();
84 socket.done.then((_) { 87 socket.done.then((_) {
85 socket.destroy(); 88 socket.destroy();
86 if (++count < 10) { 89 if (++count < 10) {
87 makeRequest(); 90 makeRequest();
88 } else { 91 } else {
89 server.close(); 92 server.close();
90 } 93 }
91 }); 94 });
92 }); 95 });
93 } 96 }
94 makeRequest(); 97 makeRequest();
95 }); 98 });
96 } 99 }
97 100
98 void main() { 101 void main() {
99 InitializeSSL();
100 InternetAddress.lookup("localhost").then((hosts) { 102 InternetAddress.lookup("localhost").then((hosts) {
101 HOST = hosts.first; 103 HOST = hosts.first;
102 testListenOn(); 104 testListenOn();
103 testEarlyClientClose(); 105 testEarlyClientClose();
104 }); 106 });
105 } 107 }
OLDNEW
« no previous file with comments | « tests/standalone/io/https_client_certificate_test.dart ('k') | tests/standalone/io/https_unauthorized_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698