Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: tests/standalone/io/web_socket_test.dart

Issue 897323002: Add support for user info on ws: and wss: URLs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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";
11 import "dart:convert";
11 import "dart:io"; 12 import "dart:io";
12 import "dart:typed_data"; 13 import "dart:typed_data";
13 14
14 import "package:async_helper/async_helper.dart"; 15 import "package:async_helper/async_helper.dart";
15 import "package:crypto/crypto.dart"; 16 import "package:crypto/crypto.dart";
16 import "package:expect/expect.dart"; 17 import "package:expect/expect.dart";
17 import "package:path/path.dart"; 18 import "package:path/path.dart";
18 19
19 const WEB_SOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 20 const WEB_SOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
20 21
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 Expect.equals('my-value-1, my-value-2', header[0]); 446 Expect.equals('my-value-1, my-value-2', header[0]);
446 WebSocketTransformer.upgrade(request).then((webSocket) { 447 WebSocketTransformer.upgrade(request).then((webSocket) {
447 webSocket.listen((_) { webSocket.close(); }); 448 webSocket.listen((_) { webSocket.close(); });
448 webSocket.add("Hello"); 449 webSocket.add("Hello");
449 }); 450 });
450 }); 451 });
451 452
452 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/'; 453 var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/';
453 var headers = {'My-Header': 'my-value', 454 var headers = {'My-Header': 'my-value',
454 'My-Header-Multiple': ['my-value-1', 'my-value-2']}; 455 '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) { 456 WebSocket.connect(url, headers: headers).then((websocket) {
459 return websocket.listen((message) { 457 return websocket.listen((message) {
460 Expect.equals("Hello", message); 458 Expect.equals("Hello", message);
461 websocket.close(); 459 websocket.close();
462 }).asFuture(); 460 }).asFuture();
463 }).then((_) { 461 }).then((_) {
464 server.close(); 462 server.close();
465 asyncEnd(); 463 asyncEnd();
466 }); 464 });
467 }); 465 });
468 } 466 }
469 467
470 468
469 void testBasicAuthentication() {
470 var userInfo = 'user:password';
471
472 asyncStart();
473 createServer().then((server) {
474 server.listen((request) {
475 Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request));
476 String auth =
477 CryptoUtils.bytesToBase64(UTF8.encode(userInfo));
478 Expect.equals('Basic $auth', request.headers['Authorization'][0]);
479 Expect.equals(1, request.headers['Authorization'].length);
480 WebSocketTransformer.upgrade(request).then((webSocket) {
481 webSocket.listen((_) { webSocket.close(); });
482 webSocket.add("Hello");
kustermann 2015/02/06 13:13:46 Why do you close inside listen and add one line af
Søren Gjesse 2015/02/09 10:38:59 This test just sends "Hello" back, but no data is
483 });
484 });
485
486 var url =
487 '${secure ? "wss" : "ws"}://$userInfo@$HOST_NAME:${server.port}/';
488 WebSocket.connect(url).then((websocket) {
489 return websocket.listen((message) {
490 Expect.equals("Hello", message);
491 websocket.close();
kustermann 2015/02/06 13:13:46 -> `return websocket.close()`
Søren Gjesse 2015/02/09 10:38:59 Why? The future is the asFuture on the stream subs
492 }).asFuture();
493 }).then((_) {
494 server.close();
kustermann 2015/02/06 13:13:46 -> `return server.close();` before asyncEnd()
Søren Gjesse 2015/02/09 10:38:59 Done. Moved asyncEnd to whenComplete.
495 asyncEnd();
496 });
497 });
498 }
499
471 void runTests() { 500 void runTests() {
472 testRequestResponseClientCloses(2, null, null, 1); 501 testRequestResponseClientCloses(2, null, null, 1);
473 testRequestResponseClientCloses(2, 3001, null, 2); 502 testRequestResponseClientCloses(2, 3001, null, 2);
474 testRequestResponseClientCloses(2, 3002, "Got tired", 3); 503 testRequestResponseClientCloses(2, 3002, "Got tired", 3);
475 testRequestResponseServerCloses(2, null, null); 504 testRequestResponseServerCloses(2, null, null);
476 testRequestResponseServerCloses(2, 3001, null); 505 testRequestResponseServerCloses(2, 3001, null);
477 testRequestResponseServerCloses(2, 3002, "Got tired"); 506 testRequestResponseServerCloses(2, 3002, "Got tired");
478 testMessageLength(125); 507 testMessageLength(125);
479 testMessageLength(126); 508 testMessageLength(126);
480 testMessageLength(127); 509 testMessageLength(127);
481 testMessageLength(65535); 510 testMessageLength(65535);
482 testMessageLength(65536); 511 testMessageLength(65536);
483 testDoubleCloseClient(); 512 testDoubleCloseClient();
484 testDoubleCloseServer(); 513 testDoubleCloseServer();
485 testImmediateCloseServer(); 514 testImmediateCloseServer();
486 testImmediateCloseClient(); 515 testImmediateCloseClient();
487 testNoUpgrade(); 516 testNoUpgrade();
488 testUsePOST(); 517 testUsePOST();
489 testConnections(10, 3002, "Got tired"); 518 testConnections(10, 3002, "Got tired");
490 testIndividualUpgrade(5); 519 testIndividualUpgrade(5);
491 testFromUpgradedSocket(); 520 testFromUpgradedSocket();
492 testAdditionalHeaders(); 521 testAdditionalHeaders();
522 testBasicAuthentication();
493 } 523 }
494 } 524 }
495 525
496 526
497 void initializeSSL() { 527 void initializeSSL() {
498 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); 528 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
499 SecureSocket.initialize(database: testPkcertDatabase, 529 SecureSocket.initialize(database: testPkcertDatabase,
500 password: "dartdart"); 530 password: "dartdart");
501 } 531 }
502 532
503 533
504 main() { 534 main() {
505 new SecurityConfiguration(secure: false).runTests(); 535 new SecurityConfiguration(secure: false).runTests();
506 initializeSSL(); 536 initializeSSL();
507 new SecurityConfiguration(secure: true).runTests(); 537 new SecurityConfiguration(secure: true).runTests();
508 } 538 }
OLDNEW
« sdk/lib/io/websocket_impl.dart ('K') | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698