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

Side by Side Diff: net/ftp/ftp_network_transaction_unittest.cc

Issue 582020: Add bounds checking to StaticSocketDataProvider, to make tests more reliable (Closed)
Patch Set: Created 10 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
« no previous file with comments | « no previous file | net/http/http_network_layer_unittest.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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/ftp/ftp_network_transaction.h" 5 #include "net/ftp/ftp_network_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/ref_counted.h" 9 #include "base/ref_counted.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 567
568 void ExecuteTransaction(FtpSocketDataProvider* ctrl_socket, 568 void ExecuteTransaction(FtpSocketDataProvider* ctrl_socket,
569 const char* request, 569 const char* request,
570 int expected_result) { 570 int expected_result) {
571 std::string mock_data("mock-data"); 571 std::string mock_data("mock-data");
572 MockRead data_reads[] = { 572 MockRead data_reads[] = {
573 MockRead(mock_data.c_str()), 573 MockRead(mock_data.c_str()),
574 }; 574 };
575 // For compatibility with FileZilla, the transaction code will use two data 575 // For compatibility with FileZilla, the transaction code will use two data
576 // sockets for directory requests. For more info see http://crbug.com/25316. 576 // sockets for directory requests. For more info see http://crbug.com/25316.
577 StaticSocketDataProvider data1(data_reads, NULL); 577 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), NULL, 0);
578 StaticSocketDataProvider data2(data_reads, NULL); 578 StaticSocketDataProvider data2(data_reads, arraysize(data_reads), NULL, 0);
579 mock_socket_factory_.AddSocketDataProvider(ctrl_socket); 579 mock_socket_factory_.AddSocketDataProvider(ctrl_socket);
580 mock_socket_factory_.AddSocketDataProvider(&data1); 580 mock_socket_factory_.AddSocketDataProvider(&data1);
581 mock_socket_factory_.AddSocketDataProvider(&data2); 581 mock_socket_factory_.AddSocketDataProvider(&data2);
582 FtpRequestInfo request_info = GetRequestInfo(request); 582 FtpRequestInfo request_info = GetRequestInfo(request);
583 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); 583 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState());
584 ASSERT_EQ(ERR_IO_PENDING, 584 ASSERT_EQ(ERR_IO_PENDING,
585 transaction_.Start(&request_info, &callback_, NULL)); 585 transaction_.Start(&request_info, &callback_, NULL));
586 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); 586 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState());
587 EXPECT_EQ(expected_result, callback_.WaitForResult()); 587 EXPECT_EQ(expected_result, callback_.WaitForResult());
588 EXPECT_EQ(FtpSocketDataProvider::QUIT, ctrl_socket->state()); 588 EXPECT_EQ(FtpSocketDataProvider::QUIT, ctrl_socket->state());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 FtpSocketDataProviderVMSFileDownload ctrl_socket; 700 FtpSocketDataProviderVMSFileDownload ctrl_socket;
701 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); 701 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK);
702 } 702 }
703 703
704 TEST_F(FtpNetworkTransactionTest, DownloadTransactionAcceptedDataConnection) { 704 TEST_F(FtpNetworkTransactionTest, DownloadTransactionAcceptedDataConnection) {
705 FtpSocketDataProviderFileDownloadAcceptedDataConnection ctrl_socket; 705 FtpSocketDataProviderFileDownloadAcceptedDataConnection ctrl_socket;
706 std::string mock_data("mock-data"); 706 std::string mock_data("mock-data");
707 MockRead data_reads[] = { 707 MockRead data_reads[] = {
708 MockRead(mock_data.c_str()), 708 MockRead(mock_data.c_str()),
709 }; 709 };
710 StaticSocketDataProvider data_socket1(data_reads, NULL); 710 StaticSocketDataProvider data_socket1(data_reads, arraysize(data_reads),
711 NULL, 0);
711 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); 712 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket);
712 mock_socket_factory_.AddSocketDataProvider(&data_socket1); 713 mock_socket_factory_.AddSocketDataProvider(&data_socket1);
713 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 714 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
714 715
715 // Start the transaction. 716 // Start the transaction.
716 ASSERT_EQ(ERR_IO_PENDING, 717 ASSERT_EQ(ERR_IO_PENDING,
717 transaction_.Start(&request_info, &callback_, NULL)); 718 transaction_.Start(&request_info, &callback_, NULL));
718 EXPECT_EQ(OK, callback_.WaitForResult()); 719 EXPECT_EQ(OK, callback_.WaitForResult());
719 720
720 // The transaction fires the callback when we can start reading data. 721 // The transaction fires the callback when we can start reading data.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); 785 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT);
785 } 786 }
786 787
787 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { 788 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) {
788 FtpSocketDataProviderEvilPasv ctrl_socket( 789 FtpSocketDataProviderEvilPasv ctrl_socket(
789 "227 Portscan (10,1,2,3,4,123,456)\r\n", FtpSocketDataProvider::PRE_SIZE); 790 "227 Portscan (10,1,2,3,4,123,456)\r\n", FtpSocketDataProvider::PRE_SIZE);
790 std::string mock_data("mock-data"); 791 std::string mock_data("mock-data");
791 MockRead data_reads[] = { 792 MockRead data_reads[] = {
792 MockRead(mock_data.c_str()), 793 MockRead(mock_data.c_str()),
793 }; 794 };
794 StaticSocketDataProvider data_socket1(data_reads, NULL); 795 StaticSocketDataProvider data_socket1(data_reads, arraysize(data_reads),
796 NULL, 0);
795 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); 797 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket);
796 mock_socket_factory_.AddSocketDataProvider(&data_socket1); 798 mock_socket_factory_.AddSocketDataProvider(&data_socket1);
797 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 799 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
798 800
799 // Start the transaction. 801 // Start the transaction.
800 ASSERT_EQ(ERR_IO_PENDING, 802 ASSERT_EQ(ERR_IO_PENDING,
801 transaction_.Start(&request_info, &callback_, NULL)); 803 transaction_.Start(&request_info, &callback_, NULL));
802 EXPECT_EQ(OK, callback_.WaitForResult()); 804 EXPECT_EQ(OK, callback_.WaitForResult());
803 805
804 // The transaction fires the callback when we can start reading data. That 806 // The transaction fires the callback when we can start reading data. That
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult()); 852 EXPECT_EQ(ERR_FAILED, callback_.WaitForResult());
851 853
852 MockRead ctrl_reads[] = { 854 MockRead ctrl_reads[] = {
853 MockRead("220 host TestFTPd\r\n"), 855 MockRead("220 host TestFTPd\r\n"),
854 MockRead("221 Goodbye!\r\n"), 856 MockRead("221 Goodbye!\r\n"),
855 MockRead(false, OK), 857 MockRead(false, OK),
856 }; 858 };
857 MockWrite ctrl_writes[] = { 859 MockWrite ctrl_writes[] = {
858 MockWrite("QUIT\r\n"), 860 MockWrite("QUIT\r\n"),
859 }; 861 };
860 StaticSocketDataProvider ctrl_socket2(ctrl_reads, ctrl_writes); 862 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
863 ctrl_writes, arraysize(ctrl_writes));
861 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 864 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
862 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red", 865 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red",
863 L"innocent", 866 L"innocent",
864 &callback_)); 867 &callback_));
865 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 868 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult());
866 } 869 }
867 870
868 TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { 871 TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) {
869 FtpSocketDataProvider ctrl_socket1; 872 FtpSocketDataProvider ctrl_socket1;
870 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, 873 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD,
(...skipping 10 matching lines...) Expand all
881 MockRead ctrl_reads[] = { 884 MockRead ctrl_reads[] = {
882 MockRead("220 host TestFTPd\r\n"), 885 MockRead("220 host TestFTPd\r\n"),
883 MockRead("331 User okay, send password\r\n"), 886 MockRead("331 User okay, send password\r\n"),
884 MockRead("221 Goodbye!\r\n"), 887 MockRead("221 Goodbye!\r\n"),
885 MockRead(false, OK), 888 MockRead(false, OK),
886 }; 889 };
887 MockWrite ctrl_writes[] = { 890 MockWrite ctrl_writes[] = {
888 MockWrite("USER innocent\r\n"), 891 MockWrite("USER innocent\r\n"),
889 MockWrite("QUIT\r\n"), 892 MockWrite("QUIT\r\n"),
890 }; 893 };
891 StaticSocketDataProvider ctrl_socket2(ctrl_reads, ctrl_writes); 894 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
895 ctrl_writes, arraysize(ctrl_writes));
892 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 896 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
893 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", 897 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent",
894 L"foo\nownz0red", 898 L"foo\nownz0red",
895 &callback_)); 899 &callback_));
896 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 900 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult());
897 } 901 }
898 902
899 TEST_F(FtpNetworkTransactionTest, Escaping) { 903 TEST_F(FtpNetworkTransactionTest, Escaping) {
900 FtpSocketDataProviderEscaping ctrl_socket; 904 FtpSocketDataProviderEscaping ctrl_socket;
901 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", 905 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81",
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 FtpSocketDataProviderFileDownloadRetrFail ctrl_socket; 1126 FtpSocketDataProviderFileDownloadRetrFail ctrl_socket;
1123 TransactionFailHelper(&ctrl_socket, 1127 TransactionFailHelper(&ctrl_socket,
1124 "ftp://host/file", 1128 "ftp://host/file",
1125 FtpSocketDataProvider::PRE_RETR, 1129 FtpSocketDataProvider::PRE_RETR,
1126 FtpSocketDataProvider::PRE_PASV2, 1130 FtpSocketDataProvider::PRE_PASV2,
1127 "550 cannot open file\r\n", 1131 "550 cannot open file\r\n",
1128 ERR_FILE_NOT_FOUND); 1132 ERR_FILE_NOT_FOUND);
1129 } 1133 }
1130 1134
1131 } // namespace net 1135 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_network_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698