| OLD | NEW |
| 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 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <ws2tcpip.h> | 10 #include <ws2tcpip.h> |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 if (InjectFault()) | 195 if (InjectFault()) |
| 196 return MockWriteResult(true, data.length()); | 196 return MockWriteResult(true, data.length()); |
| 197 switch (state()) { | 197 switch (state()) { |
| 198 case PRE_SIZE: | 198 case PRE_SIZE: |
| 199 return Verify("SIZE /file\r\n", data, PRE_MDTM, | 199 return Verify("SIZE /file\r\n", data, PRE_MDTM, |
| 200 "213 18\r\n"); | 200 "213 18\r\n"); |
| 201 case PRE_MDTM: | 201 case PRE_MDTM: |
| 202 return Verify("MDTM /file\r\n", data, PRE_RETR, | 202 return Verify("MDTM /file\r\n", data, PRE_RETR, |
| 203 "213 20070221112533\r\n"); | 203 "213 20070221112533\r\n"); |
| 204 case PRE_RETR: | 204 case PRE_RETR: |
| 205 // TODO(phajdan.jr): Also test with "150 Accepted Data Connection". | |
| 206 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); | 205 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 207 default: | 206 default: |
| 208 return FtpMockControlSocket::OnWrite(data); | 207 return FtpMockControlSocket::OnWrite(data); |
| 209 } | 208 } |
| 210 } | 209 } |
| 211 | 210 |
| 212 private: | 211 private: |
| 213 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownload); | 212 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownload); |
| 214 }; | 213 }; |
| 215 | 214 |
| 215 class FtpMockControlSocketEscaping : public FtpMockControlSocket { |
| 216 public: |
| 217 FtpMockControlSocketEscaping() { |
| 218 } |
| 219 |
| 220 virtual MockWriteResult OnWrite(const std::string& data) { |
| 221 if (InjectFault()) |
| 222 return MockWriteResult(true, data.length()); |
| 223 switch (state()) { |
| 224 case PRE_SIZE: |
| 225 return Verify("SIZE / !\"#$%y\200\201\r\n", data, PRE_MDTM, |
| 226 "213 18\r\n"); |
| 227 case PRE_MDTM: |
| 228 return Verify("MDTM / !\"#$%y\200\201\r\n", data, PRE_RETR, |
| 229 "213 20070221112533\r\n"); |
| 230 case PRE_RETR: |
| 231 return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, |
| 232 "200 OK\r\n"); |
| 233 default: |
| 234 return FtpMockControlSocket::OnWrite(data); |
| 235 } |
| 236 } |
| 237 |
| 238 private: |
| 239 DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketEscaping); |
| 240 }; |
| 241 |
| 216 class FtpMockControlSocketFileDownloadAcceptedDataConnection | 242 class FtpMockControlSocketFileDownloadAcceptedDataConnection |
| 217 : public FtpMockControlSocketFileDownload { | 243 : public FtpMockControlSocketFileDownload { |
| 218 public: | 244 public: |
| 219 FtpMockControlSocketFileDownloadAcceptedDataConnection() { | 245 FtpMockControlSocketFileDownloadAcceptedDataConnection() { |
| 220 } | 246 } |
| 221 | 247 |
| 222 virtual MockWriteResult OnWrite(const std::string& data) { | 248 virtual MockWriteResult OnWrite(const std::string& data) { |
| 223 if (InjectFault()) | 249 if (InjectFault()) |
| 224 return MockWriteResult(true, data.length()); | 250 return MockWriteResult(true, data.length()); |
| 225 switch (state()) { | 251 switch (state()) { |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 MockWrite("QUIT\r\n"), | 702 MockWrite("QUIT\r\n"), |
| 677 }; | 703 }; |
| 678 StaticMockSocket ctrl_socket2(ctrl_reads, ctrl_writes); | 704 StaticMockSocket ctrl_socket2(ctrl_reads, ctrl_writes); |
| 679 mock_socket_factory_.AddMockSocket(&ctrl_socket2); | 705 mock_socket_factory_.AddMockSocket(&ctrl_socket2); |
| 680 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", | 706 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", |
| 681 L"foo\nownz0red", | 707 L"foo\nownz0red", |
| 682 &callback_)); | 708 &callback_)); |
| 683 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); | 709 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); |
| 684 } | 710 } |
| 685 | 711 |
| 712 TEST_F(FtpNetworkTransactionTest, Escaping) { |
| 713 FtpMockControlSocketEscaping ctrl_socket; |
| 714 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", |
| 715 OK); |
| 716 } |
| 717 |
| 686 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { | 718 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { |
| 687 FtpMockControlSocketDirectoryListing ctrl_socket; | 719 FtpMockControlSocketDirectoryListing ctrl_socket; |
| 688 TransactionFailHelper(&ctrl_socket, | 720 TransactionFailHelper(&ctrl_socket, |
| 689 "ftp://host", | 721 "ftp://host", |
| 690 FtpMockControlSocket::PRE_USER, | 722 FtpMockControlSocket::PRE_USER, |
| 691 FtpMockControlSocket::PRE_QUIT, | 723 FtpMockControlSocket::PRE_QUIT, |
| 692 "500 no such user\r\n", | 724 "500 no such user\r\n", |
| 693 ERR_FAILED); | 725 ERR_FAILED); |
| 694 } | 726 } |
| 695 | 727 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; | 909 FtpMockControlSocketFileDownloadRetrFail ctrl_socket; |
| 878 TransactionFailHelper(&ctrl_socket, | 910 TransactionFailHelper(&ctrl_socket, |
| 879 "ftp://host/file", | 911 "ftp://host/file", |
| 880 FtpMockControlSocket::PRE_RETR, | 912 FtpMockControlSocket::PRE_RETR, |
| 881 FtpMockControlSocket::PRE_CWD, | 913 FtpMockControlSocket::PRE_CWD, |
| 882 "550 cannot open file\r\n", | 914 "550 cannot open file\r\n", |
| 883 ERR_FILE_NOT_FOUND); | 915 ERR_FILE_NOT_FOUND); |
| 884 } | 916 } |
| 885 | 917 |
| 886 } // namespace net | 918 } // namespace net |
| OLD | NEW |