OLD | NEW |
1 // Copyright (c) 2010 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 "base/string_util.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 default: | 324 default: |
325 return FtpSocketDataProvider::OnWrite(data); | 325 return FtpSocketDataProvider::OnWrite(data); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 private: | 329 private: |
330 DISALLOW_COPY_AND_ASSIGN( | 330 DISALLOW_COPY_AND_ASSIGN( |
331 FtpSocketDataProviderVMSDirectoryListingRootDirectory); | 331 FtpSocketDataProviderVMSDirectoryListingRootDirectory); |
332 }; | 332 }; |
333 | 333 |
| 334 class FtpSocketDataProviderFileDownloadWithFileTypecode |
| 335 : public FtpSocketDataProvider { |
| 336 public: |
| 337 FtpSocketDataProviderFileDownloadWithFileTypecode() { |
| 338 } |
| 339 |
| 340 virtual MockWriteResult OnWrite(const std::string& data) { |
| 341 if (InjectFault()) |
| 342 return MockWriteResult(true, data.length()); |
| 343 switch (state()) { |
| 344 case PRE_SIZE: |
| 345 return Verify("SIZE /file\r\n", data, PRE_RETR, |
| 346 "213 18\r\n"); |
| 347 case PRE_RETR: |
| 348 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 349 default: |
| 350 return FtpSocketDataProvider::OnWrite(data); |
| 351 } |
| 352 } |
| 353 |
| 354 private: |
| 355 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadWithFileTypecode); |
| 356 }; |
| 357 |
334 class FtpSocketDataProviderFileDownload : public FtpSocketDataProvider { | 358 class FtpSocketDataProviderFileDownload : public FtpSocketDataProvider { |
335 public: | 359 public: |
336 FtpSocketDataProviderFileDownload() { | 360 FtpSocketDataProviderFileDownload() { |
337 } | 361 } |
338 | 362 |
339 virtual MockWriteResult OnWrite(const std::string& data) { | 363 virtual MockWriteResult OnWrite(const std::string& data) { |
340 if (InjectFault()) | 364 if (InjectFault()) |
341 return MockWriteResult(true, data.length()); | 365 return MockWriteResult(true, data.length()); |
342 switch (state()) { | 366 switch (state()) { |
343 case PRE_SIZE: | 367 case PRE_SIZE: |
344 return Verify("SIZE /file\r\n", data, PRE_RETR, | 368 return Verify("SIZE /file\r\n", data, PRE_CWD, |
345 "213 18\r\n"); | 369 "213 18\r\n"); |
| 370 case PRE_CWD: |
| 371 return Verify("CWD /file\r\n", data, PRE_RETR, |
| 372 "550 Not a directory\r\n"); |
346 case PRE_RETR: | 373 case PRE_RETR: |
347 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); | 374 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); |
348 default: | 375 default: |
349 return FtpSocketDataProvider::OnWrite(data); | 376 return FtpSocketDataProvider::OnWrite(data); |
350 } | 377 } |
351 } | 378 } |
352 | 379 |
353 private: | 380 private: |
354 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownload); | 381 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownload); |
355 }; | 382 }; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 case PRE_PWD: | 472 case PRE_PWD: |
446 return Verify("PWD\r\n", data, PRE_TYPE, | 473 return Verify("PWD\r\n", data, PRE_TYPE, |
447 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); | 474 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); |
448 case PRE_EPSV: | 475 case PRE_EPSV: |
449 return Verify("EPSV\r\n", data, PRE_PASV, | 476 return Verify("EPSV\r\n", data, PRE_PASV, |
450 "500 EPSV command unknown\r\n"); | 477 "500 EPSV command unknown\r\n"); |
451 case PRE_PASV: | 478 case PRE_PASV: |
452 return Verify("PASV\r\n", data, PRE_SIZE, | 479 return Verify("PASV\r\n", data, PRE_SIZE, |
453 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 480 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
454 case PRE_SIZE: | 481 case PRE_SIZE: |
455 return Verify("SIZE ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_RETR, | 482 return Verify("SIZE ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_CWD, |
456 "213 18\r\n"); | 483 "213 18\r\n"); |
| 484 case PRE_CWD: |
| 485 return Verify("CWD ANONYMOUS_ROOT:[file]\r\n", data, PRE_RETR, |
| 486 "550 Not a directory\r\n"); |
457 case PRE_RETR: | 487 case PRE_RETR: |
458 return Verify("RETR ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_QUIT, | 488 return Verify("RETR ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_QUIT, |
459 "200 OK\r\n"); | 489 "200 OK\r\n"); |
460 default: | 490 default: |
461 return FtpSocketDataProvider::OnWrite(data); | 491 return FtpSocketDataProvider::OnWrite(data); |
462 } | 492 } |
463 } | 493 } |
464 | 494 |
465 private: | 495 private: |
466 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSFileDownload); | 496 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSFileDownload); |
467 }; | 497 }; |
468 | 498 |
469 class FtpSocketDataProviderEscaping : public FtpSocketDataProviderFileDownload { | 499 class FtpSocketDataProviderEscaping : public FtpSocketDataProviderFileDownload { |
470 public: | 500 public: |
471 FtpSocketDataProviderEscaping() { | 501 FtpSocketDataProviderEscaping() { |
472 } | 502 } |
473 | 503 |
474 virtual MockWriteResult OnWrite(const std::string& data) { | 504 virtual MockWriteResult OnWrite(const std::string& data) { |
475 if (InjectFault()) | 505 if (InjectFault()) |
476 return MockWriteResult(true, data.length()); | 506 return MockWriteResult(true, data.length()); |
477 switch (state()) { | 507 switch (state()) { |
478 case PRE_SIZE: | 508 case PRE_SIZE: |
479 return Verify("SIZE / !\"#$%y\200\201\r\n", data, PRE_RETR, | 509 return Verify("SIZE / !\"#$%y\200\201\r\n", data, PRE_CWD, |
480 "213 18\r\n"); | 510 "213 18\r\n"); |
| 511 case PRE_CWD: |
| 512 return Verify("CWD / !\"#$%y\200\201\r\n", data, PRE_RETR, |
| 513 "550 Not a directory\r\n"); |
481 case PRE_RETR: | 514 case PRE_RETR: |
482 return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, | 515 return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, |
483 "200 OK\r\n"); | 516 "200 OK\r\n"); |
484 default: | 517 default: |
485 return FtpSocketDataProviderFileDownload::OnWrite(data); | 518 return FtpSocketDataProviderFileDownload::OnWrite(data); |
486 } | 519 } |
487 } | 520 } |
488 | 521 |
489 private: | 522 private: |
490 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEscaping); | 523 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderEscaping); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 | 917 |
885 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithPasvFallback) { | 918 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithPasvFallback) { |
886 FtpSocketDataProviderFileDownloadWithPasvFallback ctrl_socket; | 919 FtpSocketDataProviderFileDownloadWithPasvFallback ctrl_socket; |
887 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 920 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
888 | 921 |
889 // We pass an artificial value of 18 as a response to the SIZE command. | 922 // We pass an artificial value of 18 as a response to the SIZE command. |
890 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 923 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
891 } | 924 } |
892 | 925 |
893 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeA) { | 926 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeA) { |
894 FtpSocketDataProviderFileDownload ctrl_socket; | 927 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; |
895 ctrl_socket.set_data_type('A'); | 928 ctrl_socket.set_data_type('A'); |
896 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=a", OK); | 929 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=a", OK); |
897 | 930 |
898 // We pass an artificial value of 18 as a response to the SIZE command. | 931 // We pass an artificial value of 18 as a response to the SIZE command. |
899 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 932 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
900 } | 933 } |
901 | 934 |
902 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeI) { | 935 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeI) { |
903 FtpSocketDataProviderFileDownload ctrl_socket; | 936 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; |
904 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=i", OK); | 937 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=i", OK); |
905 | 938 |
906 // We pass an artificial value of 18 as a response to the SIZE command. | 939 // We pass an artificial value of 18 as a response to the SIZE command. |
907 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 940 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
908 } | 941 } |
909 | 942 |
910 TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) { | 943 TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) { |
911 FtpSocketDataProviderFileDownload ctrl_socket; | 944 FtpSocketDataProviderFileDownload ctrl_socket; |
912 ctrl_socket.set_multiline_welcome(true); | 945 ctrl_socket.set_multiline_welcome(true); |
913 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 946 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 "213 99999999999999999999999999999999\r\n", | 1217 "213 99999999999999999999999999999999\r\n", |
1185 FtpSocketDataProvider::PRE_QUIT); | 1218 FtpSocketDataProvider::PRE_QUIT); |
1186 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1219 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); |
1187 } | 1220 } |
1188 | 1221 |
1189 // Test for http://crbug.com/36360. | 1222 // Test for http://crbug.com/36360. |
1190 TEST_F(FtpNetworkTransactionTest, DownloadTransactionBigSize) { | 1223 TEST_F(FtpNetworkTransactionTest, DownloadTransactionBigSize) { |
1191 // Pass a valid, but large file size. The transaction should not fail. | 1224 // Pass a valid, but large file size. The transaction should not fail. |
1192 FtpSocketDataProviderEvilSize ctrl_socket( | 1225 FtpSocketDataProviderEvilSize ctrl_socket( |
1193 "213 3204427776\r\n", | 1226 "213 3204427776\r\n", |
1194 FtpSocketDataProvider::PRE_RETR); | 1227 FtpSocketDataProvider::PRE_CWD); |
1195 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1228 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); |
1196 EXPECT_EQ(3204427776LL, | 1229 EXPECT_EQ(3204427776LL, |
1197 transaction_.GetResponseInfo()->expected_content_size); | 1230 transaction_.GetResponseInfo()->expected_content_size); |
1198 } | 1231 } |
1199 | 1232 |
1200 // Regression test for http://crbug.com/25023. | 1233 // Regression test for http://crbug.com/25023. |
1201 TEST_F(FtpNetworkTransactionTest, CloseConnection) { | 1234 TEST_F(FtpNetworkTransactionTest, CloseConnection) { |
1202 FtpSocketDataProviderCloseConnection ctrl_socket; | 1235 FtpSocketDataProviderCloseConnection ctrl_socket; |
1203 ExecuteTransaction(&ctrl_socket, "ftp://host", ERR_EMPTY_RESPONSE); | 1236 ExecuteTransaction(&ctrl_socket, "ftp://host", ERR_EMPTY_RESPONSE); |
1204 } | 1237 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 FtpSocketDataProviderFileDownload ctrl_socket; | 1443 FtpSocketDataProviderFileDownload ctrl_socket; |
1411 TransactionFailHelper(&ctrl_socket, | 1444 TransactionFailHelper(&ctrl_socket, |
1412 "ftp://host/file", | 1445 "ftp://host/file", |
1413 FtpSocketDataProvider::PRE_PWD, | 1446 FtpSocketDataProvider::PRE_PWD, |
1414 FtpSocketDataProvider::PRE_TYPE, | 1447 FtpSocketDataProvider::PRE_TYPE, |
1415 "257 \"\"\r\n", | 1448 "257 \"\"\r\n", |
1416 OK); | 1449 OK); |
1417 } | 1450 } |
1418 | 1451 |
1419 } // namespace net | 1452 } // namespace net |
OLD | NEW |