| OLD | NEW |
| 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"; |
| 11 import "dart:io"; |
| 12 import "dart:typed_data"; |
| 13 |
| 14 import "package:async_helper/async_helper.dart"; |
| 10 import "package:expect/expect.dart"; | 15 import "package:expect/expect.dart"; |
| 11 import "package:path/path.dart"; | 16 import "package:path/path.dart"; |
| 12 import "dart:async"; | |
| 13 import "dart:io"; | |
| 14 import "dart:isolate"; | |
| 15 import "dart:typed_data"; | |
| 16 | 17 |
| 17 const String CERT_NAME = 'localhost_cert'; | 18 const String CERT_NAME = 'localhost_cert'; |
| 18 const String HOST_NAME = 'localhost'; | 19 const String HOST_NAME = 'localhost'; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * A SecurityConfiguration lets us run the tests over HTTP or HTTPS. | 22 * A SecurityConfiguration lets us run the tests over HTTP or HTTPS. |
| 22 */ | 23 */ |
| 23 class SecurityConfiguration { | 24 class SecurityConfiguration { |
| 24 final bool secure; | 25 final bool secure; |
| 25 | 26 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 int closeStatus, | 42 int closeStatus, |
| 42 String closeReason) { | 43 String closeReason) { |
| 43 createServer().then((server) { | 44 createServer().then((server) { |
| 44 server.transform(new WebSocketTransformer()).listen((webSocket) { | 45 server.transform(new WebSocketTransformer()).listen((webSocket) { |
| 45 webSocket.listen( | 46 webSocket.listen( |
| 46 webSocket.add, | 47 webSocket.add, |
| 47 onDone: () { | 48 onDone: () { |
| 48 Expect.equals(closeStatus == null | 49 Expect.equals(closeStatus == null |
| 49 ? WebSocketStatus.NO_STATUS_RECEIVED | 50 ? WebSocketStatus.NO_STATUS_RECEIVED |
| 50 : closeStatus, webSocket.closeCode); | 51 : closeStatus, webSocket.closeCode); |
| 51 Expect.equals(closeReason == null ? "" : closeReason, webSocket.cl
oseReason); | 52 Expect.equals( |
| 53 closeReason == null ? "" |
| 54 : closeReason, webSocket.closeReason); |
| 52 }); | 55 }); |
| 53 }); | 56 }); |
| 54 | 57 |
| 55 int closeCount = 0; | 58 int closeCount = 0; |
| 56 String messageText = "Hello, world!"; | 59 String messageText = "Hello, world!"; |
| 57 for (int i = 0; i < totalConnections; i++) { | 60 for (int i = 0; i < totalConnections; i++) { |
| 58 int messageCount = 0; | 61 int messageCount = 0; |
| 59 createClient(server.port).then((webSocket) { | 62 createClient(server.port).then((webSocket) { |
| 60 webSocket.add(messageText); | 63 webSocket.add(messageText); |
| 61 webSocket.listen( | 64 webSocket.listen( |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 244 |
| 242 createClient(server.port).catchError((error) { | 245 createClient(server.port).catchError((error) { |
| 243 server.close(); | 246 server.close(); |
| 244 }); | 247 }); |
| 245 }); | 248 }); |
| 246 } | 249 } |
| 247 | 250 |
| 248 | 251 |
| 249 void testUsePOST() { | 252 void testUsePOST() { |
| 250 createServer().then((server) { | 253 createServer().then((server) { |
| 251 var errorPort = new ReceivePort(); | 254 asyncStart(); |
| 252 server.transform(new WebSocketTransformer()).listen((webSocket) { | 255 server.transform(new WebSocketTransformer()).listen((webSocket) { |
| 253 Expect.fail("No connection expected"); | 256 Expect.fail("No connection expected"); |
| 254 }, onError: (e) { | 257 }, onError: (e) { |
| 255 errorPort.close(); | 258 asyncEnd(); |
| 256 }); | 259 }); |
| 257 | 260 |
| 258 HttpClient client = new HttpClient(); | 261 HttpClient client = new HttpClient(); |
| 259 client.postUrl(Uri.parse( | 262 client.postUrl(Uri.parse( |
| 260 "${secure ? 'https:' : 'http:'}//$HOST_NAME:${server.port}/")) | 263 "${secure ? 'https:' : 'http:'}//$HOST_NAME:${server.port}/")) |
| 261 .then((request) => request.close()) | 264 .then((request) => request.close()) |
| 262 .then((response) { | 265 .then((response) { |
| 263 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode); | 266 Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode); |
| 264 client.close(); | 267 client.close(); |
| 265 server.close(); | 268 server.close(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 SecureSocket.initialize(database: testPkcertDatabase, | 412 SecureSocket.initialize(database: testPkcertDatabase, |
| 410 password: "dartdart"); | 413 password: "dartdart"); |
| 411 } | 414 } |
| 412 | 415 |
| 413 | 416 |
| 414 main() { | 417 main() { |
| 415 new SecurityConfiguration(secure: false).runTests(); | 418 new SecurityConfiguration(secure: false).runTests(); |
| 416 initializeSSL(); | 419 initializeSSL(); |
| 417 new SecurityConfiguration(secure: true).runTests(); | 420 new SecurityConfiguration(secure: true).runTests(); |
| 418 } | 421 } |
| OLD | NEW |