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

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

Issue 14493015: Add HTTP proxy tunnel support (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import "dart:async"; 11 import "dart:async";
12 import "dart:io"; 12 import "dart:io";
13 import "dart:isolate"; 13 import "dart:isolate";
14 14
15 const HOST_IP = "127.0.0.1";
15 const HOST_NAME = "localhost"; 16 const HOST_NAME = "localhost";
16 const CERTIFICATE = "localhost_cert"; 17 const CERTIFICATE = "localhost_cert";
17 18
18 // This test creates a server and a client connects. After connecting 19 // This test creates a server and a client connects. After connecting
19 // and an optional initial handshake the connection is secured by 20 // and an optional initial handshake the connection is secured by
20 // upgrading to a secure connection The client then writes and the 21 // upgrading to a secure connection The client then writes and the
21 // server echos. When the server has finished its echo it 22 // server echos. When the server has finished its echo it
22 // half-closes. When the client gets the close event is closes fully. 23 // half-closes. When the client gets the close event is closes fully.
23 // 24 //
24 // The test can be run in different configurations based on 25 // The test can be run in different configurations based on
25 // the boolean arguments: 26 // the boolean arguments:
26 // 27 //
27 // handshakeBeforeSecure 28 // handshakeBeforeSecure
28 // When this argument is true some initial clear text handshake is done 29 // When this argument is true some initial clear text handshake is done
29 // between client and server before the connection is secured. This argument 30 // between client and server before the connection is secured. This argument
30 // only makes sense when both listenSecure and connectSecure are false. 31 // only makes sense when both listenSecure and connectSecure are false.
31 // 32 //
32 // postponeSecure 33 // postponeSecure
33 // When this argument is false the securing of the server end will 34 // When this argument is false the securing of the server end will
34 // happen as soon as the last byte of the handshake before securing 35 // happen as soon as the last byte of the handshake before securing
35 // has been written. When this argument is true the securing of the 36 // has been written. When this argument is true the securing of the
36 // server will not happen until the first TLS handshake data has been 37 // server will not happen until the first TLS handshake data has been
37 // received from the client. This argument only takes effect when 38 // received from the client. This argument only takes effect when
38 // handshakeBeforeSecure is true. 39 // handshakeBeforeSecure is true.
39 void test(bool handshakeBeforeSecure, 40 void test(bool hostnameInConnect,
41 bool handshakeBeforeSecure,
40 [bool postponeSecure = false]) { 42 [bool postponeSecure = false]) {
41 ReceivePort port = new ReceivePort(); 43 ReceivePort port = new ReceivePort();
42 44
43 const messageSize = 1000; 45 const messageSize = 1000;
44 const handshakeMessageSize = 100; 46 const handshakeMessageSize = 100;
45 47
46 List<int> createTestData() { 48 List<int> createTestData() {
47 List<int> data = new List<int>(messageSize); 49 List<int> data = new List<int>(messageSize);
48 for (int i = 0; i < messageSize; i++) { 50 for (int i = 0; i < messageSize; i++) {
49 data[i] = i & 0xff; 51 data[i] = i & 0xff;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 completer.complete(null); 145 completer.complete(null);
144 } 146 }
145 }, 147 },
146 onDone: () => Expect.fail("Should not be called") 148 onDone: () => Expect.fail("Should not be called")
147 ); 149 );
148 socket.add(createHandshakeTestData()); 150 socket.add(createHandshakeTestData());
149 return completer.future; 151 return completer.future;
150 } 152 }
151 153
152 Future<SecureSocket> connectClient(int port) { 154 Future<SecureSocket> connectClient(int port) {
155 var host = hostnameInConnect ? HOST_NAME : HOST_IP;
153 if (!handshakeBeforeSecure) { 156 if (!handshakeBeforeSecure) {
154 return Socket.connect(HOST_NAME, port).then((socket) { 157 return Socket.connect(host, port).then((socket) {
155 return SecureSocket.secure(socket).then((secureSocket) { 158 var future;
159 if (hostnameInConnect) {
160 future = SecureSocket.secure(socket);
161 } else {
162 future = SecureSocket.secure(socket, host: HOST_NAME);
163 }
164 return future.then((secureSocket) {
156 Expect.throws(() => socket.add([0])); 165 Expect.throws(() => socket.add([0]));
157 return secureSocket; 166 return secureSocket;
158 }); 167 });
159 }); 168 });
160 } else { 169 } else {
161 return Socket.connect(HOST_NAME, port).then((socket) { 170 return Socket.connect(host, port).then((socket) {
162 return runClientHandshake(socket).then((_) { 171 return runClientHandshake(socket).then((_) {
163 return SecureSocket.secure(socket).then((secureSocket) { 172 var future;
173 if (hostnameInConnect) {
174 future = SecureSocket.secure(socket);
175 } else {
176 future = SecureSocket.secure(socket, host: HOST_NAME);
177 }
178 return future.then((secureSocket) {
164 Expect.throws(() => socket.add([0])); 179 Expect.throws(() => socket.add([0]));
165 return secureSocket; 180 return secureSocket;
166 }); 181 });
167 }); 182 });
168 }); 183 });
169 } 184 }
170 } 185 }
171 186
172 serverReady(server) { 187 serverReady(server) {
173 server.listen((client) { 188 server.listen((client) {
(...skipping 22 matching lines...) Expand all
196 211
197 ServerSocket.bind(HOST_NAME, 0, 5).then(serverReady); 212 ServerSocket.bind(HOST_NAME, 0, 5).then(serverReady);
198 } 213 }
199 214
200 main() { 215 main() {
201 Path scriptDir = new Path(new Options().script).directoryPath; 216 Path scriptDir = new Path(new Options().script).directoryPath;
202 Path certificateDatabase = scriptDir.append('pkcert'); 217 Path certificateDatabase = scriptDir.append('pkcert');
203 SecureSocket.initialize(database: certificateDatabase.toNativePath(), 218 SecureSocket.initialize(database: certificateDatabase.toNativePath(),
204 password: 'dartdart', 219 password: 'dartdart',
205 useBuiltinRoots: false); 220 useBuiltinRoots: false);
206 test(false); 221 test(false, false);
207 test(true); 222 test(true, false);
223 test(false, true);
208 test(true, true); 224 test(true, true);
225 test(false, true, true);
226 test(true, true, true);
209 } 227 }
OLDNEW
« sdk/lib/io/http_impl.dart ('K') | « tests/standalone/io/http_proxy_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698