| 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"; | 10 import "dart:async"; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 })); | 379 })); |
| 380 } | 380 } |
| 381 | 381 |
| 382 Future.wait(futures).then((_) { | 382 Future.wait(futures).then((_) { |
| 383 server.close(); | 383 server.close(); |
| 384 client.close(); | 384 client.close(); |
| 385 }); | 385 }); |
| 386 }); | 386 }); |
| 387 } | 387 } |
| 388 | 388 |
| 389 testFromSocket() { | 389 testFromUpgradedSocket() { |
| 390 asyncStart(); |
| 390 createServer().then((server) { | 391 createServer().then((server) { |
| 391 server.listen((request) { | 392 server.listen((request) { |
| 392 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); | 393 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); |
| 393 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); | 394 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); |
| 394 | 395 |
| 395 var key = request.headers.value('Sec-WebSocket-Key'); | 396 var key = request.headers.value('Sec-WebSocket-Key'); |
| 396 var sha1 = new SHA1()..add("$key$WEB_SOCKET_GUID".codeUnits); | 397 var sha1 = new SHA1()..add("$key$WEB_SOCKET_GUID".codeUnits); |
| 397 var accept = CryptoUtils.bytesToBase64(sha1.close()); | 398 var accept = CryptoUtils.bytesToBase64(sha1.close()); |
| 398 request.response | 399 request.response |
| 399 ..statusCode = HttpStatus.SWITCHING_PROTOCOLS | 400 ..statusCode = HttpStatus.SWITCHING_PROTOCOLS |
| 400 ..headers.add(HttpHeaders.CONNECTION, "Upgrade") | 401 ..headers.add(HttpHeaders.CONNECTION, "Upgrade") |
| 401 ..headers.add(HttpHeaders.UPGRADE, "websocket") | 402 ..headers.add(HttpHeaders.UPGRADE, "websocket") |
| 402 ..headers.add("Sec-WebSocket-Accept", accept); | 403 ..headers.add("Sec-WebSocket-Accept", accept); |
| 403 request.response.contentLength = 0; | 404 request.response.contentLength = 0; |
| 404 return request.response.detachSocket() | 405 request.response.detachSocket().then((socket) { |
| 405 .then((socket) => new WebSocket.fromUpgradedSocket(socket)) | 406 return new WebSocket.fromUpgradedSocket(socket, serverSide: true); |
| 406 .then((websocket) { | 407 }).then((websocket) { |
| 407 websocket.add("Hello"); | 408 websocket.add("Hello"); |
| 408 websocket.close(); | 409 websocket.close(); |
| 410 asyncEnd(); |
| 409 }); | 411 }); |
| 410 }); | 412 }); |
| 411 | 413 |
| 412 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; | 414 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; |
| 413 | 415 |
| 414 var client = new HttpClient(); | |
| 415 var completer = new Completer(); | |
| 416 WebSocket.connect(url).then((websocket) { | 416 WebSocket.connect(url).then((websocket) { |
| 417 return websocket.listen((message) { | 417 return websocket.listen((message) { |
| 418 Expect.equals("Hello", message); | 418 Expect.equals("Hello", message); |
| 419 websocket.close(); | 419 websocket.close(); |
| 420 }).asFuture(); | 420 }).asFuture(); |
| 421 }).then((_) => server.close()); | 421 }).then((_) => server.close()); |
| 422 }); | 422 }); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void runTests() { | 425 void runTests() { |
| 426 testRequestResponseClientCloses(2, null, null); | 426 testRequestResponseClientCloses(2, null, null); |
| 427 testRequestResponseClientCloses(2, 3001, null); | 427 testRequestResponseClientCloses(2, 3001, null); |
| 428 testRequestResponseClientCloses(2, 3002, "Got tired"); | 428 testRequestResponseClientCloses(2, 3002, "Got tired"); |
| 429 testRequestResponseServerCloses(2, null, null); | 429 testRequestResponseServerCloses(2, null, null); |
| 430 testRequestResponseServerCloses(2, 3001, null); | 430 testRequestResponseServerCloses(2, 3001, null); |
| 431 testRequestResponseServerCloses(2, 3002, "Got tired"); | 431 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 432 testMessageLength(125); | 432 testMessageLength(125); |
| 433 testMessageLength(126); | 433 testMessageLength(126); |
| 434 testMessageLength(127); | 434 testMessageLength(127); |
| 435 testMessageLength(65535); | 435 testMessageLength(65535); |
| 436 testMessageLength(65536); | 436 testMessageLength(65536); |
| 437 testDoubleCloseClient(); | 437 testDoubleCloseClient(); |
| 438 testDoubleCloseServer(); | 438 testDoubleCloseServer(); |
| 439 testImmediateCloseServer(); | 439 testImmediateCloseServer(); |
| 440 testImmediateCloseClient(); | 440 testImmediateCloseClient(); |
| 441 testNoUpgrade(); | 441 testNoUpgrade(); |
| 442 testUsePOST(); | 442 testUsePOST(); |
| 443 testConnections(10, 3002, "Got tired"); | 443 testConnections(10, 3002, "Got tired"); |
| 444 testIndividualUpgrade(5); | 444 testIndividualUpgrade(5); |
| 445 testFromSocket(); | 445 testFromUpgradedSocket(); |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 void initializeSSL() { | 450 void initializeSSL() { |
| 451 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); | 451 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 452 SecureSocket.initialize(database: testPkcertDatabase, | 452 SecureSocket.initialize(database: testPkcertDatabase, |
| 453 password: "dartdart"); | 453 password: "dartdart"); |
| 454 } | 454 } |
| 455 | 455 |
| 456 | 456 |
| 457 main() { | 457 main() { |
| 458 asyncStart(); | 458 asyncStart(); |
| 459 new SecurityConfiguration(secure: false).runTests(); | 459 new SecurityConfiguration(secure: false).runTests(); |
| 460 initializeSSL(); | 460 initializeSSL(); |
| 461 new SecurityConfiguration(secure: true).runTests(); | 461 new SecurityConfiguration(secure: true).runTests(); |
| 462 asyncEnd(); | 462 asyncEnd(); |
| 463 } | 463 } |
| OLD | NEW |