| 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 NoSubProtocols(), LocalhostOrigin(), "", "", | 661 NoSubProtocols(), LocalhostOrigin(), "", "", |
| 662 kRedirectResponse); | 662 kRedirectResponse); |
| 663 WaitUntilConnectDone(); | 663 WaitUntilConnectDone(); |
| 664 EXPECT_TRUE(has_failed()); | 664 EXPECT_TRUE(has_failed()); |
| 665 EXPECT_EQ("Error during WebSocket handshake: Unexpected response code: 302", | 665 EXPECT_EQ("Error during WebSocket handshake: Unexpected response code: 302", |
| 666 failure_message()); | 666 failure_message()); |
| 667 } | 667 } |
| 668 | 668 |
| 669 // Malformed responses should be rejected. HttpStreamParser will accept just | 669 // Malformed responses should be rejected. HttpStreamParser will accept just |
| 670 // about any garbage in the middle of the headers. To make it give up, the junk | 670 // about any garbage in the middle of the headers. To make it give up, the junk |
| 671 // has to be at the start of the response. Even then, it just gets treated as an | 671 // has to be at the start of the response. |
| 672 // HTTP/0.9 response. | |
| 673 TEST_F(WebSocketStreamCreateTest, MalformedResponse) { | 672 TEST_F(WebSocketStreamCreateTest, MalformedResponse) { |
| 674 static const char kMalformedResponse[] = | 673 static const char kMalformedResponse[] = |
| 675 "220 mx.google.com ESMTP\r\n" | 674 "220 mx.google.com ESMTP\r\n" |
| 676 "HTTP/1.1 101 OK\r\n" | 675 "HTTP/1.1 101 OK\r\n" |
| 677 "Upgrade: websocket\r\n" | 676 "Upgrade: websocket\r\n" |
| 678 "Connection: Upgrade\r\n" | 677 "Connection: Upgrade\r\n" |
| 679 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 678 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 680 "\r\n"; | 679 "\r\n"; |
| 681 CreateAndConnectCustomResponse("ws://localhost/", "localhost", "/", | 680 CreateAndConnectCustomResponse("ws://localhost/", "localhost", "/", |
| 682 NoSubProtocols(), LocalhostOrigin(), "", "", | 681 NoSubProtocols(), LocalhostOrigin(), "", "", |
| 683 kMalformedResponse); | 682 kMalformedResponse); |
| 684 WaitUntilConnectDone(); | 683 WaitUntilConnectDone(); |
| 685 EXPECT_TRUE(has_failed()); | 684 EXPECT_TRUE(has_failed()); |
| 686 EXPECT_EQ("Error during WebSocket handshake: Invalid status line", | 685 EXPECT_EQ("Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE", |
| 687 failure_message()); | 686 failure_message()); |
| 688 } | 687 } |
| 689 | 688 |
| 690 // Upgrade header must be present. | 689 // Upgrade header must be present. |
| 691 TEST_F(WebSocketStreamCreateTest, MissingUpgradeHeader) { | 690 TEST_F(WebSocketStreamCreateTest, MissingUpgradeHeader) { |
| 692 static const char kMissingUpgradeResponse[] = | 691 static const char kMissingUpgradeResponse[] = |
| 693 "HTTP/1.1 101 Switching Protocols\r\n" | 692 "HTTP/1.1 101 Switching Protocols\r\n" |
| 694 "Connection: Upgrade\r\n" | 693 "Connection: Upgrade\r\n" |
| 695 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 694 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 696 "\r\n"; | 695 "\r\n"; |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 LocalhostOrigin(), "", | 1233 LocalhostOrigin(), "", |
| 1235 std::move(socket_data)); | 1234 std::move(socket_data)); |
| 1236 WaitUntilConnectDone(); | 1235 WaitUntilConnectDone(); |
| 1237 EXPECT_TRUE(has_failed()); | 1236 EXPECT_TRUE(has_failed()); |
| 1238 EXPECT_EQ("Establishing a tunnel via proxy server failed.", | 1237 EXPECT_EQ("Establishing a tunnel via proxy server failed.", |
| 1239 failure_message()); | 1238 failure_message()); |
| 1240 } | 1239 } |
| 1241 | 1240 |
| 1242 } // namespace | 1241 } // namespace |
| 1243 } // namespace net | 1242 } // namespace net |
| OLD | NEW |