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

Side by Side Diff: net/server/http_server_unittest.cc

Issue 2640363004: HttpServer WebSocket: don't crash on data before server handshake (Closed)
Patch Set: Apply review feedback. Created 3 years, 11 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
« no previous file with comments | « no previous file | net/server/web_socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/server/http_server.h" 5 #include "net/server/http_server.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 client.Send( 461 client.Send(
462 "GET /test HTTP/1.1\r\n" 462 "GET /test HTTP/1.1\r\n"
463 "Upgrade: WebSocket\r\n" 463 "Upgrade: WebSocket\r\n"
464 "Connection: SomethingElse, Upgrade\r\n" 464 "Connection: SomethingElse, Upgrade\r\n"
465 "Sec-WebSocket-Version: 8\r\n" 465 "Sec-WebSocket-Version: 8\r\n"
466 "Sec-WebSocket-Key: key\r\n" 466 "Sec-WebSocket-Key: key\r\n"
467 "\r\n"); 467 "\r\n");
468 ASSERT_TRUE(RunUntilRequestsReceived(1)); 468 ASSERT_TRUE(RunUntilRequestsReceived(1));
469 } 469 }
470 470
471 TEST_F(WebSocketTest, RequestWebSocketTrailingJunk) {
472 TestHttpClient client;
473 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
474 client.Send(
475 "GET /test HTTP/1.1\r\n"
476 "Upgrade: WebSocket\r\n"
477 "Connection: SomethingElse, Upgrade\r\n"
478 "Sec-WebSocket-Version: 8\r\n"
479 "Sec-WebSocket-Key: key\r\n"
480 "\r\nHello? Anyone");
481 ASSERT_TRUE(RunUntilConnectionIdClosed(1));
482 client.ExpectUsedThenDisconnectedWithNoData();
483 }
484
471 TEST_F(HttpServerTest, RequestWithTooLargeBody) { 485 TEST_F(HttpServerTest, RequestWithTooLargeBody) {
472 class TestURLFetcherDelegate : public URLFetcherDelegate { 486 class TestURLFetcherDelegate : public URLFetcherDelegate {
473 public: 487 public:
474 TestURLFetcherDelegate(const base::Closure& quit_loop_func) 488 TestURLFetcherDelegate(const base::Closure& quit_loop_func)
475 : quit_loop_func_(quit_loop_func) {} 489 : quit_loop_func_(quit_loop_func) {}
476 ~TestURLFetcherDelegate() override {} 490 ~TestURLFetcherDelegate() override {}
477 491
478 void OnURLFetchComplete(const URLFetcher* source) override { 492 void OnURLFetchComplete(const URLFetcher* source) override {
479 EXPECT_EQ(HTTP_INTERNAL_SERVER_ERROR, source->GetResponseCode()); 493 EXPECT_EQ(HTTP_INTERNAL_SERVER_ERROR, source->GetResponseCode());
480 quit_loop_func_.Run(); 494 quit_loop_func_.Run();
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); 753 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
740 client.Send("GET / HTTP/1.1\r\n\r\n"); 754 client.Send("GET / HTTP/1.1\r\n\r\n");
741 ASSERT_FALSE(RunUntilRequestsReceived(1)); 755 ASSERT_FALSE(RunUntilRequestsReceived(1));
742 ASSERT_EQ(1ul, connection_ids_.size()); 756 ASSERT_EQ(1ul, connection_ids_.size());
743 ASSERT_EQ(0ul, requests_.size()); 757 ASSERT_EQ(0ul, requests_.size());
744 } 758 }
745 759
746 } // namespace 760 } // namespace
747 761
748 } // namespace net 762 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/server/web_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698