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

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

Issue 3040016: Net: Convert username and password to string16. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/ftp/ftp_transaction.h » ('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) 2010 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 "base/string_util.h"
10 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
11 #include "net/base/mock_host_resolver.h" 12 #include "net/base/mock_host_resolver.h"
12 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
13 #include "net/base/sys_addrinfo.h" 14 #include "net/base/sys_addrinfo.h"
14 #include "net/base/test_completion_callback.h" 15 #include "net/base/test_completion_callback.h"
15 #include "net/ftp/ftp_network_session.h" 16 #include "net/ftp/ftp_network_session.h"
16 #include "net/ftp/ftp_request_info.h" 17 #include "net/ftp/ftp_request_info.h"
17 #include "net/socket/socket_test_util.h" 18 #include "net/socket/socket_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 20 #include "testing/platform_test.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 case PRE_PWD: 75 case PRE_PWD:
75 return Verify("PWD\r\n", data, PRE_TYPE, 76 return Verify("PWD\r\n", data, PRE_TYPE,
76 "257 \"/\" is your current location\r\n"); 77 "257 \"/\" is your current location\r\n");
77 case PRE_TYPE: 78 case PRE_TYPE:
78 return Verify(std::string("TYPE ") + data_type_ + "\r\n", data, 79 return Verify(std::string("TYPE ") + data_type_ + "\r\n", data,
79 PRE_EPSV, "200 TYPE set successfully\r\n"); 80 PRE_EPSV, "200 TYPE set successfully\r\n");
80 case PRE_EPSV: 81 case PRE_EPSV:
81 return Verify("EPSV\r\n", data, PRE_SIZE, 82 return Verify("EPSV\r\n", data, PRE_SIZE,
82 "227 Entering Extended Passive Mode (|||31744|)\r\n"); 83 "227 Entering Extended Passive Mode (|||31744|)\r\n");
83 case PRE_NOPASV: 84 case PRE_NOPASV:
84 // Use unallocated 599 FTP error code to make sure it falls into the gen eric 85 // Use unallocated 599 FTP error code to make sure it falls into the
85 // ERR_FTP_FAILED bucket. 86 // generic ERR_FTP_FAILED bucket.
86 return Verify("PASV\r\n", data, PRE_QUIT, 87 return Verify("PASV\r\n", data, PRE_QUIT,
87 "599 fail\r\n"); 88 "599 fail\r\n");
88 case PRE_QUIT: 89 case PRE_QUIT:
89 return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n"); 90 return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n");
90 default: 91 default:
91 NOTREACHED() << "State not handled " << state(); 92 NOTREACHED() << "State not handled " << state();
92 return MockWriteResult(true, ERR_UNEXPECTED); 93 return MockWriteResult(true, ERR_UNEXPECTED);
93 } 94 }
94 } 95 }
95 96
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 MockRead("220 host TestFTPd\r\n"), 1039 MockRead("220 host TestFTPd\r\n"),
1039 MockRead("221 Goodbye!\r\n"), 1040 MockRead("221 Goodbye!\r\n"),
1040 MockRead(false, OK), 1041 MockRead(false, OK),
1041 }; 1042 };
1042 MockWrite ctrl_writes[] = { 1043 MockWrite ctrl_writes[] = {
1043 MockWrite("QUIT\r\n"), 1044 MockWrite("QUIT\r\n"),
1044 }; 1045 };
1045 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), 1046 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
1046 ctrl_writes, arraysize(ctrl_writes)); 1047 ctrl_writes, arraysize(ctrl_writes));
1047 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 1048 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
1048 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red", 1049 ASSERT_EQ(ERR_IO_PENDING,
1049 L"innocent", 1050 transaction_.RestartWithAuth(ASCIIToUTF16("foo\nownz0red"),
1050 &callback_)); 1051 ASCIIToUTF16("innocent"),
1052 &callback_));
1051 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 1053 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult());
1052 } 1054 }
1053 1055
1054 TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { 1056 TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) {
1055 FtpSocketDataProvider ctrl_socket1; 1057 FtpSocketDataProvider ctrl_socket1;
1056 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, 1058 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD,
1057 FtpSocketDataProvider::PRE_QUIT, 1059 FtpSocketDataProvider::PRE_QUIT,
1058 "530 Login authentication failed\r\n"); 1060 "530 Login authentication failed\r\n");
1059 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); 1061 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1);
1060 1062
1061 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); 1063 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file");
1062 1064
1063 ASSERT_EQ(ERR_IO_PENDING, 1065 ASSERT_EQ(ERR_IO_PENDING,
1064 transaction_.Start(&request_info, &callback_, BoundNetLog())); 1066 transaction_.Start(&request_info, &callback_, BoundNetLog()));
1065 ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult()); 1067 ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult());
1066 1068
1067 MockRead ctrl_reads[] = { 1069 MockRead ctrl_reads[] = {
1068 MockRead("220 host TestFTPd\r\n"), 1070 MockRead("220 host TestFTPd\r\n"),
1069 MockRead("331 User okay, send password\r\n"), 1071 MockRead("331 User okay, send password\r\n"),
1070 MockRead("221 Goodbye!\r\n"), 1072 MockRead("221 Goodbye!\r\n"),
1071 MockRead(false, OK), 1073 MockRead(false, OK),
1072 }; 1074 };
1073 MockWrite ctrl_writes[] = { 1075 MockWrite ctrl_writes[] = {
1074 MockWrite("USER innocent\r\n"), 1076 MockWrite("USER innocent\r\n"),
1075 MockWrite("QUIT\r\n"), 1077 MockWrite("QUIT\r\n"),
1076 }; 1078 };
1077 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), 1079 StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads),
1078 ctrl_writes, arraysize(ctrl_writes)); 1080 ctrl_writes, arraysize(ctrl_writes));
1079 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); 1081 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2);
1080 ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", 1082 ASSERT_EQ(ERR_IO_PENDING,
1081 L"foo\nownz0red", 1083 transaction_.RestartWithAuth(ASCIIToUTF16("innocent"),
1082 &callback_)); 1084 ASCIIToUTF16("foo\nownz0red"),
1085 &callback_));
1083 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); 1086 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult());
1084 } 1087 }
1085 1088
1086 TEST_F(FtpNetworkTransactionTest, Escaping) { 1089 TEST_F(FtpNetworkTransactionTest, Escaping) {
1087 FtpSocketDataProviderEscaping ctrl_socket; 1090 FtpSocketDataProviderEscaping ctrl_socket;
1088 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", 1091 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81",
1089 OK); 1092 OK);
1090 } 1093 }
1091 1094
1092 // Test for http://crbug.com/23794. 1095 // Test for http://crbug.com/23794.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 FtpSocketDataProviderFileDownload ctrl_socket; 1340 FtpSocketDataProviderFileDownload ctrl_socket;
1338 TransactionFailHelper(&ctrl_socket, 1341 TransactionFailHelper(&ctrl_socket,
1339 "ftp://host/file", 1342 "ftp://host/file",
1340 FtpSocketDataProvider::PRE_PWD, 1343 FtpSocketDataProvider::PRE_PWD,
1341 FtpSocketDataProvider::PRE_TYPE, 1344 FtpSocketDataProvider::PRE_TYPE,
1342 "257 \"\"\r\n", 1345 "257 \"\"\r\n",
1343 OK); 1346 OK);
1344 } 1347 }
1345 1348
1346 } // namespace net 1349 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_network_transaction.cc ('k') | net/ftp/ftp_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698