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

Unified Diff: net/ftp/ftp_network_transaction_unittest.cc

Issue 149211: Correctly handle multiple control response lines in new FTP transaction (Closed)
Patch Set: fixes Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/socket/socket_test_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_network_transaction_unittest.cc
diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc
index 51cf77b9e407ce2c0be79ab018434bb0f2401144..c81fc0f9cea9f78dc84994f8fde3f30b1f2cb486 100644
--- a/net/ftp/ftp_network_transaction_unittest.cc
+++ b/net/ftp/ftp_network_transaction_unittest.cc
@@ -44,7 +44,9 @@ class FtpMockControlSocket : public DynamicMockSocket {
QUIT
};
- FtpMockControlSocket() : failure_injection_state_(NONE) {
+ FtpMockControlSocket()
+ : failure_injection_state_(NONE),
+ multiline_welcome_(false) {
Init();
}
@@ -56,8 +58,12 @@ class FtpMockControlSocket : public DynamicMockSocket {
return Verify("USER anonymous\r\n", data, PRE_PASSWD,
"331 Password needed\r\n");
case PRE_PASSWD:
- return Verify("PASS chrome@example.com\r\n", data, PRE_SYST,
- "230 Welcome\r\n");
+ {
+ const char* response_one = "230 Welcome\r\n";
+ const char* response_multi = "230 One\r\n230 Two\r\n230 Three\r\n";
+ return Verify("PASS chrome@example.com\r\n", data, PRE_SYST,
+ multiline_welcome_ ? response_multi : response_one);
+ }
case PRE_SYST:
return Verify("SYST\r\n", data, PRE_PWD, "215 UNIX\r\n");
case PRE_PWD:
@@ -95,6 +101,10 @@ class FtpMockControlSocket : public DynamicMockSocket {
Init();
}
+ void set_multiline_welcome(bool multiline) {
+ multiline_welcome_ = multiline;
+ }
+
protected:
void Init() {
state_ = PRE_USER;
@@ -130,6 +140,9 @@ class FtpMockControlSocket : public DynamicMockSocket {
State failure_injection_next_state_;
const char* fault_response_;
+ // If true, we will send multiple 230 lines as response after PASS.
+ bool multiline_welcome_;
+
DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocket);
};
@@ -293,6 +306,12 @@ TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) {
ExecuteTransaction(&ctrl_socket, "ftp://host", OK);
}
+TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) {
+ FtpMockControlSocketDirectoryListing ctrl_socket;
+ ctrl_socket.set_multiline_welcome(true);
+ ExecuteTransaction(&ctrl_socket, "ftp://host", OK);
+}
+
TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads2) {
FtpMockControlSocketDirectoryListing ctrl_socket;
ctrl_socket.set_short_read_limit(2);
@@ -305,11 +324,27 @@ TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads5) {
ExecuteTransaction(&ctrl_socket, "ftp://host", OK);
}
+TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcomeShort) {
+ FtpMockControlSocketDirectoryListing ctrl_socket;
+ // The client will not consume all three 230 lines. That's good, we want to
+ // test that scenario.
+ ctrl_socket.allow_unconsumed_reads(true);
+ ctrl_socket.set_multiline_welcome(true);
+ ctrl_socket.set_short_read_limit(5);
+ ExecuteTransaction(&ctrl_socket, "ftp://host", OK);
+}
+
TEST_F(FtpNetworkTransactionTest, DownloadTransaction) {
FtpMockControlSocketFileDownload ctrl_socket;
ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK);
}
+TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) {
+ FtpMockControlSocketFileDownload ctrl_socket;
+ ctrl_socket.set_multiline_welcome(true);
+ ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK);
+}
+
TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads2) {
FtpMockControlSocketFileDownload ctrl_socket;
ctrl_socket.set_short_read_limit(2);
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/socket/socket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698