| 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 // OtherResources=certificates/server_chain.pem | 9 // OtherResources=certificates/server_chain.pem |
| 10 // OtherResources=certificates/server_key.pem | 10 // OtherResources=certificates/server_key.pem |
| 11 | 11 |
| 12 library dart.io; | 12 library dart.io; |
| 13 | 13 |
| 14 import "dart:async"; | 14 import "dart:async"; |
| 15 import "dart:convert" show BASE64; | |
| 16 import "dart:io"; | 15 import "dart:io"; |
| 17 import "dart:math"; | 16 import "dart:math"; |
| 18 import "dart:typed_data"; | 17 import "dart:typed_data"; |
| 19 | 18 |
| 20 import "package:async_helper/async_helper.dart"; | 19 import "package:async_helper/async_helper.dart"; |
| 21 import "package:expect/expect.dart"; | 20 import "package:expect/expect.dart"; |
| 22 import "package:path/path.dart"; | 21 import "package:path/path.dart"; |
| 23 | 22 |
| 24 import "hash_utils.dart"; | 23 part "../../../sdk/lib/io/crypto.dart"; |
| 25 | 24 |
| 26 const String webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 25 const String webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 27 const String CERT_NAME = 'localhost_cert'; | 26 const String CERT_NAME = 'localhost_cert'; |
| 28 const String HOST_NAME = 'localhost'; | 27 const String HOST_NAME = 'localhost'; |
| 29 | 28 |
| 30 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 29 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 31 | 30 |
| 32 SecurityContext serverContext = new SecurityContext() | 31 SecurityContext serverContext = new SecurityContext() |
| 33 ..useCertificateChain(localFile('certificates/server_chain.pem')) | 32 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
| 34 ..usePrivateKey(localFile('certificates/server_key.pem'), | 33 ..usePrivateKey(localFile('certificates/server_key.pem'), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 54 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); | 53 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); |
| 55 | 54 |
| 56 void testForceCloseServerEnd(int totalConnections) { | 55 void testForceCloseServerEnd(int totalConnections) { |
| 57 createServer().then((server) { | 56 createServer().then((server) { |
| 58 server.listen((request) { | 57 server.listen((request) { |
| 59 var response = request.response; | 58 var response = request.response; |
| 60 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; | 59 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; |
| 61 response.headers.set(HttpHeaders.CONNECTION, "upgrade"); | 60 response.headers.set(HttpHeaders.CONNECTION, "upgrade"); |
| 62 response.headers.set(HttpHeaders.UPGRADE, "websocket"); | 61 response.headers.set(HttpHeaders.UPGRADE, "websocket"); |
| 63 String key = request.headers.value("Sec-WebSocket-Key"); | 62 String key = request.headers.value("Sec-WebSocket-Key"); |
| 64 var sha1 = new SHA1(); | 63 _SHA1 sha1 = new _SHA1(); |
| 65 sha1.add("$key$webSocketGUID".codeUnits); | 64 sha1.add("$key$webSocketGUID".codeUnits); |
| 66 String accept = BASE64.encode(sha1.close()); | 65 String accept = _CryptoUtils.bytesToBase64(sha1.close()); |
| 67 response.headers.add("Sec-WebSocket-Accept", accept); | 66 response.headers.add("Sec-WebSocket-Accept", accept); |
| 68 response.headers.contentLength = 0; | 67 response.headers.contentLength = 0; |
| 69 response.detachSocket().then((socket) { | 68 response.detachSocket().then((socket) { |
| 70 socket.destroy(); | 69 socket.destroy(); |
| 71 }); | 70 }); |
| 72 }); | 71 }); |
| 73 | 72 |
| 74 int closeCount = 0; | 73 int closeCount = 0; |
| 75 for (int i = 0; i < totalConnections; i++) { | 74 for (int i = 0; i < totalConnections; i++) { |
| 76 createClient(server.port).then((webSocket) { | 75 createClient(server.port).then((webSocket) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 main() { | 95 main() { |
| 97 asyncStart(); | 96 asyncStart(); |
| 98 new SecurityConfiguration(secure: false).runTests(); | 97 new SecurityConfiguration(secure: false).runTests(); |
| 99 // TODO(whesse): WebSocket.connect needs an optional context: parameter | 98 // TODO(whesse): WebSocket.connect needs an optional context: parameter |
| 100 // new SecurityConfiguration(secure: true).runTests(); | 99 // new SecurityConfiguration(secure: true).runTests(); |
| 101 asyncEnd(); | 100 asyncEnd(); |
| 102 } | 101 } |
| OLD | NEW |