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_socket_bad_data_test.dart

Issue 201993002: Fix SecureSocket tests to look up localhost only once, where possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove useless change to https_client_certificate_test.dart Created 6 years, 9 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 "dart:async"; 10 import "dart:async";
11 import "dart:io"; 11 import "dart:io";
12 12
13 import "package:async_helper/async_helper.dart"; 13 import "package:async_helper/async_helper.dart";
14 import "package:expect/expect.dart"; 14 import "package:expect/expect.dart";
15 import "package:path/path.dart";
16 15
17 const HOST_NAME = "localhost"; 16 InternetAddress HOST;
18 const CERTIFICATE = "localhost_cert"; 17 const CERTIFICATE = "localhost_cert";
19 18
20 // This test sends corrupt data in the middle of a secure network connection. 19 // This test sends corrupt data in the middle of a secure network connection.
21 // This tests the error handling of RawSecureSocket. 20 // This tests the error handling of RawSecureSocket.
22 // A RawSocket connection is upgraded to a secure connection, so that we 21 // A RawSocket connection is upgraded to a secure connection, so that we
23 // have a reference to the underlying socket. Then we send some 22 // have a reference to the underlying socket. Then we send some
24 // unencrypted data on it, in the middle of an encrypted data transfer. 23 // unencrypted data on it, in the middle of an encrypted data transfer.
25 24
26 25
27 // This test creates a server and then connects a client to the server. 26 // This test creates a server and then connects a client to the server.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 }, 125 },
127 onError: (e) { 126 onError: (e) {
128 Expect.isTrue(e is IOException); 127 Expect.isTrue(e is IOException);
129 tryComplete(); 128 tryComplete();
130 }); 129 });
131 return completer.future; 130 return completer.future;
132 } 131 }
133 132
134 133
135 Future<List> connectClient(int port, bool hostnameInConnect) => 134 Future<List> connectClient(int port, bool hostnameInConnect) =>
136 RawSocket.connect(HOST_NAME, port) 135 RawSocket.connect(HOST, port)
137 .then((socket) => 136 .then((socket) =>
138 (hostnameInConnect ? RawSecureSocket.secure(socket) 137 (hostnameInConnect ? RawSecureSocket.secure(socket)
139 : RawSecureSocket.secure(socket, host: HOST_NAME)) 138 : RawSecureSocket.secure(socket, host: HOST))
140 .then((secureSocket) => [socket, secureSocket])); 139 .then((secureSocket) => [socket, secureSocket]));
141 140
142 141
143 Future test(bool hostnameInConnect) { 142 Future test(bool hostnameInConnect) {
144 return RawServerSocket.bind(HOST_NAME, 0).then((server) { 143 return RawServerSocket.bind(HOST, 0).then((server) {
145 server.listen((client) { 144 server.listen((client) {
146 RawSecureSocket.secureServer(client, CERTIFICATE) 145 RawSecureSocket.secureServer(client, CERTIFICATE)
147 .then((secureClient) { 146 .then((secureClient) {
148 Expect.throws(() => client.add([0])); 147 Expect.throws(() => client.add([0]));
149 return runServer(secureClient); 148 return runServer(secureClient);
150 }, 149 },
151 onError: (e) { 150 onError: (e) {
152 Expect.isTrue(e is HandshakeException); 151 Expect.isTrue(e is HandshakeException);
153 }) 152 })
154 .whenComplete(server.close); 153 .whenComplete(server.close);
155 }); 154 });
156 return connectClient(server.port, hostnameInConnect).then(runClient); 155 return connectClient(server.port, hostnameInConnect).then(runClient);
157 }); 156 });
158 } 157 }
159 158
160 159
161 main() { 160 main() {
162 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); 161 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
163 SecureSocket.initialize(database: certificateDatabase, 162 SecureSocket.initialize(database: certificateDatabase,
164 password: 'dartdart', 163 password: 'dartdart',
165 useBuiltinRoots: false); 164 useBuiltinRoots: false);
166 asyncStart(); 165 asyncStart();
167 Future.wait([test(false), test(true)]) 166 InternetAddress.lookup("localhost").then((hosts) {
168 .then((_) => asyncEnd()); 167 HOST = hosts.first;
168 return Future.wait([test(false), test(true)]);
169 }).then((_) => asyncEnd());
169 } 170 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_session_resume_test.dart ('k') | tests/standalone/io/socket_upgrade_to_secure_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698