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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 }); | 343 }); |
344 } | 344 } |
345 | 345 |
346 for (int i = 0; i < totalConnections; i++) { | 346 for (int i = 0; i < totalConnections; i++) { |
347 webSocketConnection(); | 347 webSocketConnection(); |
348 } | 348 } |
349 }); | 349 }); |
350 } | 350 } |
351 | 351 |
352 testIndividualUpgrade(int connections) { | 352 testIndividualUpgrade(int connections) { |
| 353 asyncStart(); |
353 createServer().then((server) { | 354 createServer().then((server) { |
354 server.listen((request) { | 355 server.listen((request) { |
355 if (WebSocketTransformer.isUpgradeRequest(request)) { | 356 if (WebSocketTransformer.isUpgradeRequest(request)) { |
356 WebSocketTransformer.upgrade(request).then((webSocket) { | 357 WebSocketTransformer.upgrade(request).then((webSocket) { |
357 webSocket.listen((_) { webSocket.close(); }); | 358 webSocket.listen((_) { webSocket.close(); }); |
358 webSocket.add("Hello"); | 359 webSocket.add("Hello"); |
359 }); | 360 }); |
360 } else { | 361 } else { |
361 Expect.isFalse(WebSocketTransformer.isUpgradeRequest(request)); | 362 Expect.isFalse(WebSocketTransformer.isUpgradeRequest(request)); |
362 request.response.statusCode = HttpStatus.OK; | 363 request.response.statusCode = HttpStatus.OK; |
(...skipping 22 matching lines...) Expand all Loading... |
385 .then((request) => request.close()) | 386 .then((request) => request.close()) |
386 .then((response) { | 387 .then((response) { |
387 response.listen((_) { }); | 388 response.listen((_) { }); |
388 Expect.equals(HttpStatus.OK, response.statusCode); | 389 Expect.equals(HttpStatus.OK, response.statusCode); |
389 })); | 390 })); |
390 } | 391 } |
391 | 392 |
392 Future.wait(futures).then((_) { | 393 Future.wait(futures).then((_) { |
393 server.close(); | 394 server.close(); |
394 client.close(); | 395 client.close(); |
| 396 asyncEnd(); |
395 }); | 397 }); |
396 }); | 398 }); |
397 } | 399 } |
398 | 400 |
399 testFromUpgradedSocket() { | 401 testFromUpgradedSocket() { |
400 asyncStart(); | 402 asyncStart(); |
401 createServer().then((server) { | 403 createServer().then((server) { |
402 server.listen((request) { | 404 server.listen((request) { |
403 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); | 405 Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION)); |
404 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); | 406 Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE)); |
(...skipping 20 matching lines...) Expand all Loading... |
425 | 427 |
426 WebSocket.connect(url).then((websocket) { | 428 WebSocket.connect(url).then((websocket) { |
427 return websocket.listen((message) { | 429 return websocket.listen((message) { |
428 Expect.equals("Hello", message); | 430 Expect.equals("Hello", message); |
429 websocket.close(); | 431 websocket.close(); |
430 }).asFuture(); | 432 }).asFuture(); |
431 }).then((_) => server.close()); | 433 }).then((_) => server.close()); |
432 }); | 434 }); |
433 } | 435 } |
434 | 436 |
| 437 void testAdditionalHeaders() { |
| 438 asyncStart(); |
| 439 createServer().then((server) { |
| 440 server.listen((request) { |
| 441 Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); |
| 442 Expect.equals('my-value', request.headers['My-Header'][0]); |
| 443 var header = request.headers['My-Header-Multiple']; |
| 444 Expect.equals(1, header.length); |
| 445 Expect.equals('my-value-1, my-value-2', header[0]); |
| 446 WebSocketTransformer.upgrade(request).then((webSocket) { |
| 447 webSocket.listen((_) { webSocket.close(); }); |
| 448 webSocket.add("Hello"); |
| 449 }); |
| 450 }); |
| 451 |
| 452 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; |
| 453 var headers = {'My-Header': 'my-value', |
| 454 'My-Header-Multiple': ['my-value-1', 'my-value-2']}; |
| 455 print(headers); |
| 456 print(headers['My-Header-Multiple'] is Iterable); |
| 457 print(headers['My-Header-Multiple'].length); |
| 458 WebSocket.connect(url, headers: headers).then((websocket) { |
| 459 return websocket.listen((message) { |
| 460 Expect.equals("Hello", message); |
| 461 websocket.close(); |
| 462 }).asFuture(); |
| 463 }).then((_) { |
| 464 server.close(); |
| 465 asyncEnd(); |
| 466 }); |
| 467 }); |
| 468 } |
| 469 |
| 470 |
435 void runTests() { | 471 void runTests() { |
436 testRequestResponseClientCloses(2, null, null, 1); | 472 testRequestResponseClientCloses(2, null, null, 1); |
437 testRequestResponseClientCloses(2, 3001, null, 2); | 473 testRequestResponseClientCloses(2, 3001, null, 2); |
438 testRequestResponseClientCloses(2, 3002, "Got tired", 3); | 474 testRequestResponseClientCloses(2, 3002, "Got tired", 3); |
439 testRequestResponseServerCloses(2, null, null); | 475 testRequestResponseServerCloses(2, null, null); |
440 testRequestResponseServerCloses(2, 3001, null); | 476 testRequestResponseServerCloses(2, 3001, null); |
441 testRequestResponseServerCloses(2, 3002, "Got tired"); | 477 testRequestResponseServerCloses(2, 3002, "Got tired"); |
442 testMessageLength(125); | 478 testMessageLength(125); |
443 testMessageLength(126); | 479 testMessageLength(126); |
444 testMessageLength(127); | 480 testMessageLength(127); |
445 testMessageLength(65535); | 481 testMessageLength(65535); |
446 testMessageLength(65536); | 482 testMessageLength(65536); |
447 testDoubleCloseClient(); | 483 testDoubleCloseClient(); |
448 testDoubleCloseServer(); | 484 testDoubleCloseServer(); |
449 testImmediateCloseServer(); | 485 testImmediateCloseServer(); |
450 testImmediateCloseClient(); | 486 testImmediateCloseClient(); |
451 testNoUpgrade(); | 487 testNoUpgrade(); |
452 testUsePOST(); | 488 testUsePOST(); |
453 testConnections(10, 3002, "Got tired"); | 489 testConnections(10, 3002, "Got tired"); |
454 testIndividualUpgrade(5); | 490 testIndividualUpgrade(5); |
455 testFromUpgradedSocket(); | 491 testFromUpgradedSocket(); |
| 492 testAdditionalHeaders(); |
456 } | 493 } |
457 } | 494 } |
458 | 495 |
459 | 496 |
460 void initializeSSL() { | 497 void initializeSSL() { |
461 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); | 498 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); |
462 SecureSocket.initialize(database: testPkcertDatabase, | 499 SecureSocket.initialize(database: testPkcertDatabase, |
463 password: "dartdart"); | 500 password: "dartdart"); |
464 } | 501 } |
465 | 502 |
466 | 503 |
467 main() { | 504 main() { |
468 new SecurityConfiguration(secure: false).runTests(); | 505 new SecurityConfiguration(secure: false).runTests(); |
469 initializeSSL(); | 506 initializeSSL(); |
470 new SecurityConfiguration(secure: true).runTests(); | 507 new SecurityConfiguration(secure: true).runTests(); |
471 } | 508 } |
OLD | NEW |