OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 CreateAndConnectWithExtensions( | 556 CreateAndConnectWithExtensions( |
557 "permessage-deflate, permessage-deflate; client_max_window_bits=10"); | 557 "permessage-deflate, permessage-deflate; client_max_window_bits=10"); |
558 EXPECT_FALSE(stream_); | 558 EXPECT_FALSE(stream_); |
559 EXPECT_TRUE(has_failed()); | 559 EXPECT_TRUE(has_failed()); |
560 EXPECT_EQ( | 560 EXPECT_EQ( |
561 "Error during WebSocket handshake: " | 561 "Error during WebSocket handshake: " |
562 "Received duplicate permessage-deflate response", | 562 "Received duplicate permessage-deflate response", |
563 failure_message()); | 563 failure_message()); |
564 } | 564 } |
565 | 565 |
566 // permessage-deflate parameters may not be duplicated. | 566 // client_max_window_bits must have an argument |
567 TEST_F(WebSocketStreamCreateExtensionTest, NoDuplicateParameters) { | |
568 CreateAndConnectWithExtensions( | |
569 "permessage-deflate; client_no_context_takeover; " | |
570 "client_no_context_takeover"); | |
571 EXPECT_FALSE(stream_); | |
572 EXPECT_TRUE(has_failed()); | |
573 EXPECT_EQ( | |
574 "Error during WebSocket handshake: Error in permessage-deflate: " | |
575 "Received duplicate permessage-deflate extension parameter " | |
576 "client_no_context_takeover", | |
577 failure_message()); | |
578 } | |
579 | |
580 // permessage-deflate parameters must start with "client_" or "server_" | |
581 TEST_F(WebSocketStreamCreateExtensionTest, BadParameterPrefix) { | |
582 CreateAndConnectWithExtensions( | |
583 "permessage-deflate; absurd_no_context_takeover"); | |
584 EXPECT_FALSE(stream_); | |
585 EXPECT_TRUE(has_failed()); | |
586 EXPECT_EQ( | |
587 "Error during WebSocket handshake: Error in permessage-deflate: " | |
588 "Received an unexpected permessage-deflate extension parameter", | |
589 failure_message()); | |
590 } | |
591 | |
592 // permessage-deflate parameters must be either *_no_context_takeover or | |
593 // *_max_window_bits | |
594 TEST_F(WebSocketStreamCreateExtensionTest, BadParameterSuffix) { | |
595 CreateAndConnectWithExtensions( | |
596 "permessage-deflate; client_max_content_bits=5"); | |
597 EXPECT_FALSE(stream_); | |
598 EXPECT_TRUE(has_failed()); | |
599 EXPECT_EQ( | |
600 "Error during WebSocket handshake: Error in permessage-deflate: " | |
601 "Received an unexpected permessage-deflate extension parameter", | |
602 failure_message()); | |
603 } | |
604 | |
605 // *_no_context_takeover parameters must not have an argument | |
606 TEST_F(WebSocketStreamCreateExtensionTest, BadParameterValue) { | |
607 CreateAndConnectWithExtensions( | |
608 "permessage-deflate; client_no_context_takeover=true"); | |
609 EXPECT_FALSE(stream_); | |
610 EXPECT_TRUE(has_failed()); | |
611 EXPECT_EQ( | |
612 "Error during WebSocket handshake: Error in permessage-deflate: " | |
613 "Received invalid client_no_context_takeover parameter", | |
614 failure_message()); | |
615 } | |
616 | |
617 // *_max_window_bits must have an argument | |
618 TEST_F(WebSocketStreamCreateExtensionTest, NoMaxWindowBitsArgument) { | 567 TEST_F(WebSocketStreamCreateExtensionTest, NoMaxWindowBitsArgument) { |
619 CreateAndConnectWithExtensions("permessage-deflate; client_max_window_bits"); | 568 CreateAndConnectWithExtensions("permessage-deflate; client_max_window_bits"); |
620 EXPECT_FALSE(stream_); | 569 EXPECT_FALSE(stream_); |
621 EXPECT_TRUE(has_failed()); | 570 EXPECT_TRUE(has_failed()); |
622 EXPECT_EQ( | 571 EXPECT_EQ( |
623 "Error during WebSocket handshake: Error in permessage-deflate: " | 572 "Error during WebSocket handshake: Error in permessage-deflate: " |
624 "client_max_window_bits must have value", | 573 "client_max_window_bits must have value", |
625 failure_message()); | 574 failure_message()); |
626 } | 575 } |
627 | 576 |
628 // *_max_window_bits must be an integer | 577 // Other cases for permessage-deflate parameters are tested in |
629 TEST_F(WebSocketStreamCreateExtensionTest, MaxWindowBitsValueInteger) { | 578 // websocket_deflate_parameters_test.cc. |
630 CreateAndConnectWithExtensions( | |
631 "permessage-deflate; server_max_window_bits=banana"); | |
632 EXPECT_FALSE(stream_); | |
633 EXPECT_TRUE(has_failed()); | |
634 EXPECT_EQ( | |
635 "Error during WebSocket handshake: Error in permessage-deflate: " | |
636 "Received invalid server_max_window_bits parameter", | |
637 failure_message()); | |
638 } | |
639 | |
640 // *_max_window_bits must be >= 8 | |
641 TEST_F(WebSocketStreamCreateExtensionTest, MaxWindowBitsValueTooSmall) { | |
642 CreateAndConnectWithExtensions( | |
643 "permessage-deflate; server_max_window_bits=7"); | |
644 EXPECT_FALSE(stream_); | |
645 EXPECT_TRUE(has_failed()); | |
646 EXPECT_EQ( | |
647 "Error during WebSocket handshake: Error in permessage-deflate: " | |
648 "Received invalid server_max_window_bits parameter", | |
649 failure_message()); | |
650 } | |
651 | |
652 // *_max_window_bits must be <= 15 | |
653 TEST_F(WebSocketStreamCreateExtensionTest, MaxWindowBitsValueTooBig) { | |
654 CreateAndConnectWithExtensions( | |
655 "permessage-deflate; client_max_window_bits=16"); | |
656 EXPECT_FALSE(stream_); | |
657 EXPECT_TRUE(has_failed()); | |
658 EXPECT_EQ( | |
659 "Error during WebSocket handshake: Error in permessage-deflate: " | |
660 "Received invalid client_max_window_bits parameter", | |
661 failure_message()); | |
662 } | |
663 | |
664 // *_max_window_bits must not start with 0 | |
665 TEST_F(WebSocketStreamCreateExtensionTest, MaxWindowBitsValueStartsWithZero) { | |
666 CreateAndConnectWithExtensions( | |
667 "permessage-deflate; client_max_window_bits=08"); | |
668 EXPECT_FALSE(stream_); | |
669 EXPECT_TRUE(has_failed()); | |
670 EXPECT_EQ( | |
671 "Error during WebSocket handshake: Error in permessage-deflate: " | |
672 "Received invalid client_max_window_bits parameter", | |
673 failure_message()); | |
674 } | |
675 | |
676 // *_max_window_bits must not start with + | |
677 TEST_F(WebSocketStreamCreateExtensionTest, MaxWindowBitsValueStartsWithPlus) { | |
678 CreateAndConnectWithExtensions( | |
679 "permessage-deflate; server_max_window_bits=+9"); | |
680 EXPECT_FALSE(stream_); | |
681 EXPECT_TRUE(has_failed()); | |
682 EXPECT_EQ( | |
683 "Error during WebSocket handshake: Error in permessage-deflate: " | |
684 "Received invalid server_max_window_bits parameter", | |
685 failure_message()); | |
686 } | |
687 | 579 |
688 // TODO(ricea): Check that WebSocketDeflateStream is initialised with the | 580 // TODO(ricea): Check that WebSocketDeflateStream is initialised with the |
689 // arguments from the server. This is difficult because the data written to the | 581 // arguments from the server. This is difficult because the data written to the |
690 // socket is randomly masked. | 582 // socket is randomly masked. |
691 | 583 |
692 // Additional Sec-WebSocket-Accept headers should be rejected. | 584 // Additional Sec-WebSocket-Accept headers should be rejected. |
693 TEST_F(WebSocketStreamCreateTest, DoubleAccept) { | 585 TEST_F(WebSocketStreamCreateTest, DoubleAccept) { |
694 CreateAndConnectStandard( | 586 CreateAndConnectStandard( |
695 "ws://localhost/", "localhost", "/", NoSubProtocols(), LocalhostOrigin(), | 587 "ws://localhost/", "localhost", "/", NoSubProtocols(), LocalhostOrigin(), |
696 "", "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"); | 588 "", "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"); |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), | 1188 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), |
1297 LocalhostOrigin(), socket_data.Pass()); | 1189 LocalhostOrigin(), socket_data.Pass()); |
1298 WaitUntilConnectDone(); | 1190 WaitUntilConnectDone(); |
1299 EXPECT_TRUE(has_failed()); | 1191 EXPECT_TRUE(has_failed()); |
1300 EXPECT_EQ("Establishing a tunnel via proxy server failed.", | 1192 EXPECT_EQ("Establishing a tunnel via proxy server failed.", |
1301 failure_message()); | 1193 failure_message()); |
1302 } | 1194 } |
1303 | 1195 |
1304 } // namespace | 1196 } // namespace |
1305 } // namespace net | 1197 } // namespace net |
OLD | NEW |