| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 Expect.listEquals(originalMessage, message); | 166 Expect.listEquals(originalMessage, message); |
| 167 webSocket.close(); | 167 webSocket.close(); |
| 168 }, | 168 }, |
| 169 onDone: server.close); | 169 onDone: server.close); |
| 170 webSocket.add(originalMessage); | 170 webSocket.add(originalMessage); |
| 171 }); | 171 }); |
| 172 }); | 172 }); |
| 173 } | 173 } |
| 174 | 174 |
| 175 | 175 |
| 176 void testCloseNoListen() { |
| 177 createServer().then((server) { |
| 178 server.transform(new WebSocketTransformer()).listen((webSocket) { |
| 179 server.close(); |
| 180 webSocket.close(); |
| 181 }); |
| 182 |
| 183 createClient(server.port).then((webSocket) { |
| 184 webSocket.close(); |
| 185 }); |
| 186 }); |
| 187 } |
| 188 |
| 189 |
| 190 void testListenAfterClose() { |
| 191 createServer().then((server) { |
| 192 server.transform(new WebSocketTransformer()).listen((webSocket) { |
| 193 server.close(); |
| 194 webSocket.close(); |
| 195 Expect.throws(() => webSocket.drain()); |
| 196 }); |
| 197 |
| 198 createClient(server.port).then((webSocket) { |
| 199 webSocket.close(); |
| 200 Expect.throws(() => webSocket.drain()); |
| 201 }); |
| 202 }); |
| 203 } |
| 204 |
| 205 |
| 176 void testDoubleCloseClient() { | 206 void testDoubleCloseClient() { |
| 177 createServer().then((server) { | 207 createServer().then((server) { |
| 178 server.transform(new WebSocketTransformer()).listen((webSocket) { | 208 server.transform(new WebSocketTransformer()).listen((webSocket) { |
| 179 server.close(); | 209 server.close(); |
| 180 webSocket.listen((_) { }, onDone: webSocket.close); | 210 webSocket.listen((_) { }, onDone: webSocket.close); |
| 181 }); | 211 }); |
| 182 | 212 |
| 183 createClient(server.port).then((webSocket) { | 213 createClient(server.port).then((webSocket) { |
| 184 webSocket.listen((_) { }, onDone: webSocket.close); | 214 webSocket.listen((_) { }, onDone: webSocket.close); |
| 185 webSocket.close(); | 215 webSocket.close(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 201 }); | 231 }); |
| 202 }); | 232 }); |
| 203 } | 233 } |
| 204 | 234 |
| 205 | 235 |
| 206 void testImmediateCloseServer() { | 236 void testImmediateCloseServer() { |
| 207 createServer().then((server) { | 237 createServer().then((server) { |
| 208 server.listen((request) { | 238 server.listen((request) { |
| 209 WebSocketTransformer.upgrade(request) | 239 WebSocketTransformer.upgrade(request) |
| 210 .then((webSocket) { | 240 .then((webSocket) { |
| 211 webSocket.close(); | |
| 212 webSocket.listen( | 241 webSocket.listen( |
| 213 (_) { Expect.fail("Unexpected message"); }, | 242 (_) { Expect.fail("Unexpected message"); }, |
| 214 onDone: server.close); | 243 onDone: server.close); |
| 244 webSocket.close(); |
| 215 }); | 245 }); |
| 216 }); | 246 }); |
| 217 | 247 |
| 218 createClient(server.port).then((webSocket) { | 248 createClient(server.port).then((webSocket) { |
| 219 webSocket.listen( | 249 webSocket.listen( |
| 220 (_) { Expect.fail("Unexpected message"); }, | 250 (_) { Expect.fail("Unexpected message"); }, |
| 221 onDone: webSocket.close); | 251 onDone: webSocket.close); |
| 222 }); | 252 }); |
| 223 }); | 253 }); |
| 224 } | 254 } |
| 225 | 255 |
| 226 | 256 |
| 227 void testImmediateCloseClient() { | 257 void testImmediateCloseClient() { |
| 228 createServer().then((server) { | 258 createServer().then((server) { |
| 229 server.listen((request) { | 259 server.listen((request) { |
| 230 WebSocketTransformer.upgrade(request) | 260 WebSocketTransformer.upgrade(request) |
| 231 .then((webSocket) { | 261 .then((webSocket) { |
| 232 webSocket.listen( | 262 webSocket.listen( |
| 233 (_) { Expect.fail("Unexpected message"); }, | 263 (_) { Expect.fail("Unexpected message"); }, |
| 234 onDone: () { | 264 onDone: () { |
| 235 server.close(); | 265 server.close(); |
| 236 webSocket.close(); | 266 webSocket.close(); |
| 237 }); | 267 }); |
| 238 }); | 268 }); |
| 239 }); | 269 }); |
| 240 | 270 |
| 241 createClient(server.port).then((webSocket) { | 271 createClient(server.port).then((webSocket) { |
| 242 webSocket.close(); | |
| 243 webSocket.listen( | 272 webSocket.listen( |
| 244 (_) { Expect.fail("Unexpected message"); }, | 273 (_) { Expect.fail("Unexpected message"); }, |
| 245 onDone: webSocket.close); | 274 onDone: webSocket.close); |
| 275 webSocket.close(); |
| 246 }); | 276 }); |
| 247 }); | 277 }); |
| 248 } | 278 } |
| 249 | 279 |
| 250 | 280 |
| 251 void testNoUpgrade() { | 281 void testNoUpgrade() { |
| 252 createServer().then((server) { | 282 createServer().then((server) { |
| 253 // Create a server which always responds with NOT_FOUND. | 283 // Create a server which always responds with NOT_FOUND. |
| 254 server.listen((request) { | 284 server.listen((request) { |
| 255 request.response.statusCode = HttpStatus.NOT_FOUND; | 285 request.response.statusCode = HttpStatus.NOT_FOUND; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 testRequestResponseClientCloses(2, 3001, null, 2); | 535 testRequestResponseClientCloses(2, 3001, null, 2); |
| 506 testRequestResponseClientCloses(2, 3002, "Got tired", 3); | 536 testRequestResponseClientCloses(2, 3002, "Got tired", 3); |
| 507 testRequestResponseServerCloses(2, null, null); | 537 testRequestResponseServerCloses(2, null, null); |
| 508 testRequestResponseServerCloses(2, 3001, null); | 538 testRequestResponseServerCloses(2, 3001, null); |
| 509 testRequestResponseServerCloses(2, 3002, "Got tired"); | 539 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 510 testMessageLength(125); | 540 testMessageLength(125); |
| 511 testMessageLength(126); | 541 testMessageLength(126); |
| 512 testMessageLength(127); | 542 testMessageLength(127); |
| 513 testMessageLength(65535); | 543 testMessageLength(65535); |
| 514 testMessageLength(65536); | 544 testMessageLength(65536); |
| 545 testCloseNoListen(); |
| 546 testListenAfterClose(); |
| 515 testDoubleCloseClient(); | 547 testDoubleCloseClient(); |
| 516 testDoubleCloseServer(); | 548 testDoubleCloseServer(); |
| 517 testImmediateCloseServer(); | 549 testImmediateCloseServer(); |
| 518 testImmediateCloseClient(); | 550 testImmediateCloseClient(); |
| 519 testNoUpgrade(); | 551 testNoUpgrade(); |
| 520 testUsePOST(); | 552 testUsePOST(); |
| 521 testConnections(10, 3002, "Got tired"); | 553 testConnections(10, 3002, "Got tired"); |
| 522 testIndividualUpgrade(5); | 554 testIndividualUpgrade(5); |
| 523 testFromUpgradedSocket(); | 555 testFromUpgradedSocket(); |
| 524 testAdditionalHeaders(); | 556 testAdditionalHeaders(); |
| 525 testBasicAuthentication(); | 557 testBasicAuthentication(); |
| 526 } | 558 } |
| 527 } | 559 } |
| 528 | 560 |
| 529 | 561 |
| 530 void initializeSSL() { | 562 void initializeSSL() { |
| 531 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); | 563 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); |
| 532 SecureSocket.initialize(database: testPkcertDatabase, | 564 SecureSocket.initialize(database: testPkcertDatabase, |
| 533 password: "dartdart"); | 565 password: "dartdart"); |
| 534 } | 566 } |
| 535 | 567 |
| 536 | 568 |
| 537 main() { | 569 main() { |
| 538 new SecurityConfiguration(secure: false).runTests(); | 570 new SecurityConfiguration(secure: false).runTests(); |
| 539 initializeSSL(); | 571 initializeSSL(); |
| 540 new SecurityConfiguration(secure: true).runTests(); | 572 new SecurityConfiguration(secure: true).runTests(); |
| 541 } | 573 } |
| OLD | NEW |