diff options
author | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 14:13:34 +0000 |
---|---|---|
committer | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 14:13:34 +0000 |
commit | 96e272bcde178a2abe0b8008149c467630148f18 (patch) | |
tree | 1f4f8683341507dae46b023f43ef347f2a2b6394 /net/ftp/ftp_network_transaction_unittest.cc | |
parent | 04e3f3559dac2a7a5178e8f0d935d69970e2a33c (diff) | |
download | chromium_src-96e272bcde178a2abe0b8008149c467630148f18.zip chromium_src-96e272bcde178a2abe0b8008149c467630148f18.tar.gz chromium_src-96e272bcde178a2abe0b8008149c467630148f18.tar.bz2 |
Pass nulls through test sockets.
Fixing 35050, one of the tests I wrote for EPSV required NULS go through the
testing framework. That created issue 42432 which covers permitting NULs through
our socket tests. I added an interface to SimulateRead which passes in an explicit
length, and moved as much of that into ftp_network_transaction_unittest as possible.
BUG=42432
TEST=see the modified Epsv test in ftp_network_transaction_unittest.cc
Review URL: http://codereview.chromium.org/1949003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_network_transaction_unittest.cc')
-rw-r--r-- | net/ftp/ftp_network_transaction_unittest.cc | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 6e814aa..6b359a5 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -150,16 +150,26 @@ class FtpSocketDataProvider : public DynamicSocketDataProvider { MockWriteResult Verify(const std::string& expected, const std::string& data, State next_state, - const char* next_read) { + const char* next_read, + const size_t next_read_length) { EXPECT_EQ(expected, data); if (expected == data) { state_ = next_state; - SimulateRead(next_read); + SimulateRead(next_read, next_read_length); return MockWriteResult(true, data.length()); } return MockWriteResult(true, ERR_UNEXPECTED); } + MockWriteResult Verify(const std::string& expected, + const std::string& data, + State next_state, + const char* next_read) { + return Verify(expected, data, next_state, + next_read, std::strlen(next_read)); + } + + private: State state_; State failure_injection_state_; @@ -552,18 +562,26 @@ class FtpSocketDataProviderFileDownloadRetrFail class FtpSocketDataProviderEvilEpsv : public FtpSocketDataProviderFileDownload { public: - explicit FtpSocketDataProviderEvilEpsv(const char* epsv_response, - State expected_state) + FtpSocketDataProviderEvilEpsv(const char* epsv_response, + State expected_state) : epsv_response_(epsv_response), - expected_state_(expected_state) { - } + epsv_response_length_(std::strlen(epsv_response)), + expected_state_(expected_state) {} + + FtpSocketDataProviderEvilEpsv(const char* epsv_response, + size_t epsv_response_length, + State expected_state) + : epsv_response_(epsv_response), + epsv_response_length_(epsv_response_length), + expected_state_(expected_state) {} virtual MockWriteResult OnWrite(const std::string& data) { if (InjectFault()) return MockWriteResult(true, data.length()); switch (state()) { case PRE_EPSV: - return Verify("EPSV\r\n", data, expected_state_, epsv_response_); + return Verify("EPSV\r\n", data, expected_state_, + epsv_response_, epsv_response_length_); default: return FtpSocketDataProviderFileDownload::OnWrite(data); } @@ -571,6 +589,7 @@ class FtpSocketDataProviderEvilEpsv : public FtpSocketDataProviderFileDownload { private: const char* epsv_response_; + const size_t epsv_response_length_; const State expected_state_; DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEvilEpsv); @@ -1007,9 +1026,10 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat4) { } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat5) { - FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (\0\0\031773\0)\r\n", + const char response[] = "227 Portscan (\0\0\031773\0)\r\n"; + FtpSocketDataProviderEvilEpsv ctrl_socket(response, sizeof(response)-1, FtpSocketDataProvider::PRE_QUIT); - ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNEXPECTED); + ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort1) { |