| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 PRE_USER, | 37 PRE_USER, |
| 38 PRE_PASSWD, | 38 PRE_PASSWD, |
| 39 PRE_SYST, | 39 PRE_SYST, |
| 40 PRE_PWD, | 40 PRE_PWD, |
| 41 PRE_TYPE, | 41 PRE_TYPE, |
| 42 PRE_SIZE, | 42 PRE_SIZE, |
| 43 PRE_EPSV, | 43 PRE_EPSV, |
| 44 PRE_PASV, | 44 PRE_PASV, |
| 45 PRE_LIST, | 45 PRE_LIST, |
| 46 PRE_RETR, | 46 PRE_RETR, |
| 47 PRE_RETR_EPSV, |
| 48 PRE_RETR_PASV, |
| 49 PRE_CWD_EPSV, |
| 50 PRE_CWD_PASV, |
| 47 PRE_CWD, | 51 PRE_CWD, |
| 48 PRE_QUIT, | 52 PRE_QUIT, |
| 49 PRE_NOPASV, | 53 PRE_NOPASV, |
| 50 QUIT | 54 QUIT |
| 51 }; | 55 }; |
| 52 | 56 |
| 53 FtpSocketDataProvider() | 57 FtpSocketDataProvider() |
| 54 : failure_injection_state_(NONE), | 58 : failure_injection_state_(NONE), |
| 55 multiline_welcome_(false), | 59 multiline_welcome_(false), |
| 56 data_type_('I') { | 60 data_type_('I') { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 75 return Verify("SYST\r\n", data, PRE_PWD, "215 UNIX\r\n"); | 79 return Verify("SYST\r\n", data, PRE_PWD, "215 UNIX\r\n"); |
| 76 case PRE_PWD: | 80 case PRE_PWD: |
| 77 return Verify("PWD\r\n", data, PRE_TYPE, | 81 return Verify("PWD\r\n", data, PRE_TYPE, |
| 78 "257 \"/\" is your current location\r\n"); | 82 "257 \"/\" is your current location\r\n"); |
| 79 case PRE_TYPE: | 83 case PRE_TYPE: |
| 80 return Verify(std::string("TYPE ") + data_type_ + "\r\n", data, | 84 return Verify(std::string("TYPE ") + data_type_ + "\r\n", data, |
| 81 PRE_EPSV, "200 TYPE set successfully\r\n"); | 85 PRE_EPSV, "200 TYPE set successfully\r\n"); |
| 82 case PRE_EPSV: | 86 case PRE_EPSV: |
| 83 return Verify("EPSV\r\n", data, PRE_SIZE, | 87 return Verify("EPSV\r\n", data, PRE_SIZE, |
| 84 "227 Entering Extended Passive Mode (|||31744|)\r\n"); | 88 "227 Entering Extended Passive Mode (|||31744|)\r\n"); |
| 89 case PRE_CWD_EPSV: |
| 90 return Verify("EPSV\r\n", data, PRE_CWD, |
| 91 "227 Entering Extended Passive Mode (|||31744|)\r\n"); |
| 92 case PRE_RETR_EPSV: |
| 93 return Verify("EPSV\r\n", data, PRE_RETR, |
| 94 "227 Entering Extended Passive Mode (|||31744|)\r\n"); |
| 95 case PRE_CWD_PASV: |
| 96 return Verify("PASV\r\n", data, PRE_CWD, |
| 97 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 98 case PRE_RETR_PASV: |
| 99 return Verify("PASV\r\n", data, PRE_RETR, |
| 100 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 85 case PRE_NOPASV: | 101 case PRE_NOPASV: |
| 86 // Use unallocated 599 FTP error code to make sure it falls into the | 102 // Use unallocated 599 FTP error code to make sure it falls into the |
| 87 // generic ERR_FTP_FAILED bucket. | 103 // generic ERR_FTP_FAILED bucket. |
| 88 return Verify("PASV\r\n", data, PRE_QUIT, | 104 return Verify("PASV\r\n", data, PRE_QUIT, |
| 89 "599 fail\r\n"); | 105 "599 fail\r\n"); |
| 90 case PRE_QUIT: | 106 case PRE_QUIT: |
| 91 return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n"); | 107 return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n"); |
| 92 default: | 108 default: |
| 93 NOTREACHED() << "State not handled " << state(); | 109 NOTREACHED() << "State not handled " << state(); |
| 94 return MockWriteResult(ASYNC, ERR_UNEXPECTED); | 110 return MockWriteResult(ASYNC, ERR_UNEXPECTED); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 class FtpSocketDataProviderDirectoryListing : public FtpSocketDataProvider { | 195 class FtpSocketDataProviderDirectoryListing : public FtpSocketDataProvider { |
| 180 public: | 196 public: |
| 181 FtpSocketDataProviderDirectoryListing() { | 197 FtpSocketDataProviderDirectoryListing() { |
| 182 } | 198 } |
| 183 | 199 |
| 184 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 200 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 185 if (InjectFault()) | 201 if (InjectFault()) |
| 186 return MockWriteResult(ASYNC, data.length()); | 202 return MockWriteResult(ASYNC, data.length()); |
| 187 switch (state()) { | 203 switch (state()) { |
| 188 case PRE_SIZE: | 204 case PRE_SIZE: |
| 189 return Verify("SIZE /\r\n", data, PRE_CWD, | 205 return Verify("SIZE /\r\n", data, PRE_CWD_EPSV, |
| 190 "550 I can only retrieve regular files\r\n"); | 206 "550 I can only retrieve regular files\r\n"); |
| 191 case PRE_CWD: | 207 case PRE_CWD: |
| 192 return Verify("CWD /\r\n", data, PRE_LIST, "200 OK\r\n"); | 208 return Verify("CWD /\r\n", data, PRE_LIST, "200 OK\r\n"); |
| 193 case PRE_LIST: | 209 case PRE_LIST: |
| 194 return Verify("LIST\r\n", data, PRE_QUIT, "200 OK\r\n"); | 210 return Verify("LIST\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 195 default: | 211 default: |
| 196 return FtpSocketDataProvider::OnWrite(data); | 212 return FtpSocketDataProvider::OnWrite(data); |
| 197 } | 213 } |
| 198 } | 214 } |
| 199 | 215 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 210 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 226 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 211 if (InjectFault()) | 227 if (InjectFault()) |
| 212 return MockWriteResult(ASYNC, data.length()); | 228 return MockWriteResult(ASYNC, data.length()); |
| 213 switch (state()) { | 229 switch (state()) { |
| 214 case PRE_EPSV: | 230 case PRE_EPSV: |
| 215 return Verify("EPSV\r\n", data, PRE_PASV, | 231 return Verify("EPSV\r\n", data, PRE_PASV, |
| 216 "500 no EPSV for you\r\n"); | 232 "500 no EPSV for you\r\n"); |
| 217 case PRE_PASV: | 233 case PRE_PASV: |
| 218 return Verify("PASV\r\n", data, PRE_SIZE, | 234 return Verify("PASV\r\n", data, PRE_SIZE, |
| 219 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 235 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 236 case PRE_SIZE: |
| 237 return Verify("SIZE /\r\n", data, PRE_CWD_PASV, |
| 238 "550 I can only retrieve regular files\r\n"); |
| 220 default: | 239 default: |
| 221 return FtpSocketDataProviderDirectoryListing::OnWrite(data); | 240 return FtpSocketDataProviderDirectoryListing::OnWrite(data); |
| 222 } | 241 } |
| 223 } | 242 } |
| 224 | 243 |
| 225 private: | 244 private: |
| 226 DISALLOW_COPY_AND_ASSIGN( | 245 DISALLOW_COPY_AND_ASSIGN( |
| 227 FtpSocketDataProviderDirectoryListingWithPasvFallback); | 246 FtpSocketDataProviderDirectoryListingWithPasvFallback); |
| 228 }; | 247 }; |
| 229 | 248 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return Verify("SYST\r\n", data, PRE_PWD, "215 VMS\r\n"); | 280 return Verify("SYST\r\n", data, PRE_PWD, "215 VMS\r\n"); |
| 262 case PRE_PWD: | 281 case PRE_PWD: |
| 263 return Verify("PWD\r\n", data, PRE_TYPE, | 282 return Verify("PWD\r\n", data, PRE_TYPE, |
| 264 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); | 283 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); |
| 265 case PRE_EPSV: | 284 case PRE_EPSV: |
| 266 return Verify("EPSV\r\n", data, PRE_PASV, "500 Invalid command\r\n"); | 285 return Verify("EPSV\r\n", data, PRE_PASV, "500 Invalid command\r\n"); |
| 267 case PRE_PASV: | 286 case PRE_PASV: |
| 268 return Verify("PASV\r\n", data, PRE_SIZE, | 287 return Verify("PASV\r\n", data, PRE_SIZE, |
| 269 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 288 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 270 case PRE_SIZE: | 289 case PRE_SIZE: |
| 271 return Verify("SIZE ANONYMOUS_ROOT:[000000]dir\r\n", data, PRE_CWD, | 290 return Verify("SIZE ANONYMOUS_ROOT:[000000]dir\r\n", data, PRE_CWD_PASV, |
| 272 "550 I can only retrieve regular files\r\n"); | 291 "550 I can only retrieve regular files\r\n"); |
| 273 case PRE_CWD: | 292 case PRE_CWD: |
| 274 return Verify("CWD ANONYMOUS_ROOT:[dir]\r\n", data, PRE_LIST, | 293 return Verify("CWD ANONYMOUS_ROOT:[dir]\r\n", data, PRE_LIST, |
| 275 "200 OK\r\n"); | 294 "200 OK\r\n"); |
| 276 case PRE_LIST: | 295 case PRE_LIST: |
| 277 return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); | 296 return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 278 default: | 297 default: |
| 279 return FtpSocketDataProvider::OnWrite(data); | 298 return FtpSocketDataProvider::OnWrite(data); |
| 280 } | 299 } |
| 281 } | 300 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 299 case PRE_PWD: | 318 case PRE_PWD: |
| 300 return Verify("PWD\r\n", data, PRE_TYPE, | 319 return Verify("PWD\r\n", data, PRE_TYPE, |
| 301 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); | 320 "257 \"ANONYMOUS_ROOT:[000000]\"\r\n"); |
| 302 case PRE_EPSV: | 321 case PRE_EPSV: |
| 303 return Verify("EPSV\r\n", data, PRE_PASV, | 322 return Verify("EPSV\r\n", data, PRE_PASV, |
| 304 "500 EPSV command unknown\r\n"); | 323 "500 EPSV command unknown\r\n"); |
| 305 case PRE_PASV: | 324 case PRE_PASV: |
| 306 return Verify("PASV\r\n", data, PRE_SIZE, | 325 return Verify("PASV\r\n", data, PRE_SIZE, |
| 307 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 326 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 308 case PRE_SIZE: | 327 case PRE_SIZE: |
| 309 return Verify("SIZE ANONYMOUS_ROOT\r\n", data, PRE_CWD, | 328 return Verify("SIZE ANONYMOUS_ROOT\r\n", data, PRE_CWD_PASV, |
| 310 "550 I can only retrieve regular files\r\n"); | 329 "550 I can only retrieve regular files\r\n"); |
| 311 case PRE_CWD: | 330 case PRE_CWD: |
| 312 return Verify("CWD ANONYMOUS_ROOT:[000000]\r\n", data, PRE_LIST, | 331 return Verify("CWD ANONYMOUS_ROOT:[000000]\r\n", data, PRE_LIST, |
| 313 "200 OK\r\n"); | 332 "200 OK\r\n"); |
| 314 case PRE_LIST: | 333 case PRE_LIST: |
| 315 return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); | 334 return Verify("LIST *.*;0\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 316 default: | 335 default: |
| 317 return FtpSocketDataProvider::OnWrite(data); | 336 return FtpSocketDataProvider::OnWrite(data); |
| 318 } | 337 } |
| 319 } | 338 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 372 } |
| 354 | 373 |
| 355 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 374 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 356 if (InjectFault()) | 375 if (InjectFault()) |
| 357 return MockWriteResult(ASYNC, data.length()); | 376 return MockWriteResult(ASYNC, data.length()); |
| 358 switch (state()) { | 377 switch (state()) { |
| 359 case PRE_SIZE: | 378 case PRE_SIZE: |
| 360 return Verify("SIZE /file\r\n", data, PRE_CWD, | 379 return Verify("SIZE /file\r\n", data, PRE_CWD, |
| 361 "213 18\r\n"); | 380 "213 18\r\n"); |
| 362 case PRE_CWD: | 381 case PRE_CWD: |
| 363 return Verify("CWD /file\r\n", data, PRE_RETR, | 382 return Verify("CWD /file\r\n", data, PRE_RETR_EPSV, |
| 364 "550 Not a directory\r\n"); | 383 "550 Not a directory\r\n"); |
| 365 case PRE_RETR: | 384 case PRE_RETR: |
| 366 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); | 385 return Verify("RETR /file\r\n", data, PRE_QUIT, "200 OK\r\n"); |
| 367 default: | 386 default: |
| 368 return FtpSocketDataProvider::OnWrite(data); | 387 return FtpSocketDataProvider::OnWrite(data); |
| 369 } | 388 } |
| 370 } | 389 } |
| 371 | 390 |
| 372 private: | 391 private: |
| 373 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownload); | 392 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownload); |
| 374 }; | 393 }; |
| 375 | 394 |
| 376 class FtpSocketDataProviderFileNotFound : public FtpSocketDataProvider { | 395 class FtpSocketDataProviderFileNotFound : public FtpSocketDataProvider { |
| 377 public: | 396 public: |
| 378 FtpSocketDataProviderFileNotFound() { | 397 FtpSocketDataProviderFileNotFound() { |
| 379 } | 398 } |
| 380 | 399 |
| 381 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 400 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 382 if (InjectFault()) | 401 if (InjectFault()) |
| 383 return MockWriteResult(ASYNC, data.length()); | 402 return MockWriteResult(ASYNC, data.length()); |
| 384 switch (state()) { | 403 switch (state()) { |
| 385 case PRE_SIZE: | 404 case PRE_SIZE: |
| 386 return Verify("SIZE /file\r\n", data, PRE_CWD, | 405 return Verify("SIZE /file\r\n", data, PRE_CWD_EPSV, |
| 387 "550 File Not Found\r\n"); | 406 "550 File Not Found\r\n"); |
| 388 case PRE_CWD: | 407 case PRE_CWD: |
| 389 return Verify("CWD /file\r\n", data, PRE_RETR, | 408 return Verify("CWD /file\r\n", data, PRE_RETR_EPSV, |
| 390 "550 File Not Found\r\n"); | 409 "550 File Not Found\r\n"); |
| 391 case PRE_RETR: | 410 case PRE_RETR: |
| 392 return Verify("RETR /file\r\n", data, PRE_QUIT, | 411 return Verify("RETR /file\r\n", data, PRE_QUIT, |
| 393 "550 File Not Found\r\n"); | 412 "550 File Not Found\r\n"); |
| 394 default: | 413 default: |
| 395 return FtpSocketDataProvider::OnWrite(data); | 414 return FtpSocketDataProvider::OnWrite(data); |
| 396 } | 415 } |
| 397 } | 416 } |
| 398 | 417 |
| 399 private: | 418 private: |
| 400 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileNotFound); | 419 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileNotFound); |
| 401 }; | 420 }; |
| 402 | 421 |
| 403 class FtpSocketDataProviderFileDownloadWithPasvFallback | 422 class FtpSocketDataProviderFileDownloadWithPasvFallback |
| 404 : public FtpSocketDataProviderFileDownload { | 423 : public FtpSocketDataProviderFileDownload { |
| 405 public: | 424 public: |
| 406 FtpSocketDataProviderFileDownloadWithPasvFallback() { | 425 FtpSocketDataProviderFileDownloadWithPasvFallback() { |
| 407 } | 426 } |
| 408 | 427 |
| 409 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 428 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 410 if (InjectFault()) | 429 if (InjectFault()) |
| 411 return MockWriteResult(ASYNC, data.length()); | 430 return MockWriteResult(ASYNC, data.length()); |
| 412 switch (state()) { | 431 switch (state()) { |
| 413 case PRE_EPSV: | 432 case PRE_EPSV: |
| 414 return Verify("EPSV\r\n", data, PRE_PASV, | 433 return Verify("EPSV\r\n", data, PRE_PASV, |
| 415 "500 No can do\r\n"); | 434 "500 No can do\r\n"); |
| 416 case PRE_PASV: | 435 case PRE_PASV: |
| 417 return Verify("PASV\r\n", data, PRE_SIZE, | 436 return Verify("PASV\r\n", data, PRE_SIZE, |
| 418 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 437 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 438 case PRE_CWD: |
| 439 return Verify("CWD /file\r\n", data, PRE_RETR_PASV, |
| 440 "550 Not a directory\r\n"); |
| 419 default: | 441 default: |
| 420 return FtpSocketDataProviderFileDownload::OnWrite(data); | 442 return FtpSocketDataProviderFileDownload::OnWrite(data); |
| 421 } | 443 } |
| 422 } | 444 } |
| 423 | 445 |
| 424 private: | 446 private: |
| 425 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadWithPasvFallback); | 447 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadWithPasvFallback); |
| 426 }; | 448 }; |
| 427 | 449 |
| 428 class FtpSocketDataProviderFileDownloadZeroSize | 450 class FtpSocketDataProviderFileDownloadZeroSize |
| 429 : public FtpSocketDataProviderFileDownload { | 451 : public FtpSocketDataProviderFileDownload { |
| 430 public: | 452 public: |
| 431 FtpSocketDataProviderFileDownloadZeroSize() { | 453 FtpSocketDataProviderFileDownloadZeroSize() { |
| 432 } | 454 } |
| 433 | 455 |
| 434 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 456 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 435 if (InjectFault()) | 457 if (InjectFault()) |
| 436 return MockWriteResult(ASYNC, data.length()); | 458 return MockWriteResult(ASYNC, data.length()); |
| 437 switch (state()) { | 459 switch (state()) { |
| 438 case PRE_SIZE: | 460 case PRE_SIZE: |
| 439 return Verify("SIZE /file\r\n", data, PRE_CWD, | 461 return Verify("SIZE /file\r\n", data, PRE_CWD, |
| 440 "213 0\r\n"); | 462 "213 0\r\n"); |
| 441 case PRE_CWD: | 463 case PRE_CWD: |
| 442 return Verify("CWD /file\r\n", data, PRE_RETR, | 464 return Verify("CWD /file\r\n", data, PRE_RETR_EPSV, |
| 443 "550 not a directory\r\n"); | 465 "550 not a directory\r\n"); |
| 444 default: | 466 default: |
| 445 return FtpSocketDataProviderFileDownload::OnWrite(data); | 467 return FtpSocketDataProviderFileDownload::OnWrite(data); |
| 446 } | 468 } |
| 447 } | 469 } |
| 448 | 470 |
| 449 private: | 471 private: |
| 450 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadZeroSize); | 472 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadZeroSize); |
| 451 }; | 473 }; |
| 452 | 474 |
| 453 class FtpSocketDataProviderFileDownloadCWD451 | 475 class FtpSocketDataProviderFileDownloadCWD451 |
| 454 : public FtpSocketDataProviderFileDownload { | 476 : public FtpSocketDataProviderFileDownload { |
| 455 public: | 477 public: |
| 456 FtpSocketDataProviderFileDownloadCWD451() { | 478 FtpSocketDataProviderFileDownloadCWD451() { |
| 457 } | 479 } |
| 458 | 480 |
| 459 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 481 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 460 if (InjectFault()) | 482 if (InjectFault()) |
| 461 return MockWriteResult(ASYNC, data.length()); | 483 return MockWriteResult(ASYNC, data.length()); |
| 462 switch (state()) { | 484 switch (state()) { |
| 463 case PRE_CWD: | 485 case PRE_CWD: |
| 464 return Verify("CWD /file\r\n", data, PRE_RETR, | 486 return Verify("CWD /file\r\n", data, PRE_RETR_EPSV, |
| 465 "451 not a directory\r\n"); | 487 "451 not a directory\r\n"); |
| 466 default: | 488 default: |
| 467 return FtpSocketDataProviderFileDownload::OnWrite(data); | 489 return FtpSocketDataProviderFileDownload::OnWrite(data); |
| 468 } | 490 } |
| 469 } | 491 } |
| 470 | 492 |
| 471 private: | 493 private: |
| 472 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadCWD451); | 494 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderFileDownloadCWD451); |
| 473 }; | 495 }; |
| 474 | 496 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 489 case PRE_EPSV: | 511 case PRE_EPSV: |
| 490 return Verify("EPSV\r\n", data, PRE_PASV, | 512 return Verify("EPSV\r\n", data, PRE_PASV, |
| 491 "500 EPSV command unknown\r\n"); | 513 "500 EPSV command unknown\r\n"); |
| 492 case PRE_PASV: | 514 case PRE_PASV: |
| 493 return Verify("PASV\r\n", data, PRE_SIZE, | 515 return Verify("PASV\r\n", data, PRE_SIZE, |
| 494 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); | 516 "227 Entering Passive Mode 127,0,0,1,123,456\r\n"); |
| 495 case PRE_SIZE: | 517 case PRE_SIZE: |
| 496 return Verify("SIZE ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_CWD, | 518 return Verify("SIZE ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_CWD, |
| 497 "213 18\r\n"); | 519 "213 18\r\n"); |
| 498 case PRE_CWD: | 520 case PRE_CWD: |
| 499 return Verify("CWD ANONYMOUS_ROOT:[file]\r\n", data, PRE_RETR, | 521 return Verify("CWD ANONYMOUS_ROOT:[file]\r\n", data, PRE_RETR_PASV, |
| 500 "550 Not a directory\r\n"); | 522 "550 Not a directory\r\n"); |
| 501 case PRE_RETR: | 523 case PRE_RETR: |
| 502 return Verify("RETR ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_QUIT, | 524 return Verify("RETR ANONYMOUS_ROOT:[000000]file\r\n", data, PRE_QUIT, |
| 503 "200 OK\r\n"); | 525 "200 OK\r\n"); |
| 504 default: | 526 default: |
| 505 return FtpSocketDataProvider::OnWrite(data); | 527 return FtpSocketDataProvider::OnWrite(data); |
| 506 } | 528 } |
| 507 } | 529 } |
| 508 | 530 |
| 509 private: | 531 private: |
| 510 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSFileDownload); | 532 DISALLOW_COPY_AND_ASSIGN(FtpSocketDataProviderVMSFileDownload); |
| 511 }; | 533 }; |
| 512 | 534 |
| 513 class FtpSocketDataProviderEscaping : public FtpSocketDataProviderFileDownload { | 535 class FtpSocketDataProviderEscaping : public FtpSocketDataProviderFileDownload { |
| 514 public: | 536 public: |
| 515 FtpSocketDataProviderEscaping() { | 537 FtpSocketDataProviderEscaping() { |
| 516 } | 538 } |
| 517 | 539 |
| 518 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | 540 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { |
| 519 if (InjectFault()) | 541 if (InjectFault()) |
| 520 return MockWriteResult(ASYNC, data.length()); | 542 return MockWriteResult(ASYNC, data.length()); |
| 521 switch (state()) { | 543 switch (state()) { |
| 522 case PRE_SIZE: | 544 case PRE_SIZE: |
| 523 return Verify("SIZE / !\"#$%y\200\201\r\n", data, PRE_CWD, | 545 return Verify("SIZE / !\"#$%y\200\201\r\n", data, PRE_CWD, |
| 524 "213 18\r\n"); | 546 "213 18\r\n"); |
| 525 case PRE_CWD: | 547 case PRE_CWD: |
| 526 return Verify("CWD / !\"#$%y\200\201\r\n", data, PRE_RETR, | 548 return Verify("CWD / !\"#$%y\200\201\r\n", data, PRE_RETR_EPSV, |
| 527 "550 Not a directory\r\n"); | 549 "550 Not a directory\r\n"); |
| 528 case PRE_RETR: | 550 case PRE_RETR: |
| 529 return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, | 551 return Verify("RETR / !\"#$%y\200\201\r\n", data, PRE_QUIT, |
| 530 "200 OK\r\n"); | 552 "200 OK\r\n"); |
| 531 default: | 553 default: |
| 532 return FtpSocketDataProviderFileDownload::OnWrite(data); | 554 return FtpSocketDataProviderFileDownload::OnWrite(data); |
| 533 } | 555 } |
| 534 } | 556 } |
| 535 | 557 |
| 536 private: | 558 private: |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 781 |
| 760 protected: | 782 protected: |
| 761 FtpRequestInfo GetRequestInfo(const std::string& url) { | 783 FtpRequestInfo GetRequestInfo(const std::string& url) { |
| 762 FtpRequestInfo info; | 784 FtpRequestInfo info; |
| 763 info.url = GURL(url); | 785 info.url = GURL(url); |
| 764 return info; | 786 return info; |
| 765 } | 787 } |
| 766 | 788 |
| 767 void ExecuteTransaction(FtpSocketDataProvider* ctrl_socket, | 789 void ExecuteTransaction(FtpSocketDataProvider* ctrl_socket, |
| 768 const char* request, | 790 const char* request, |
| 791 int data_socket, |
| 769 int expected_result) { | 792 int expected_result) { |
| 793 mock_socket_factory_.AddSocketDataProvider(ctrl_socket); |
| 794 |
| 770 std::string mock_data("mock-data"); | 795 std::string mock_data("mock-data"); |
| 771 MockRead data_reads[] = { | 796 MockRead data_reads[] = { |
| 772 // Usually FTP servers close the data connection after the entire data has | 797 // Usually FTP servers close the data connection after the entire data has |
| 773 // been received. | 798 // been received. |
| 774 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 799 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 775 MockRead(mock_data.c_str()), | 800 MockRead(mock_data.c_str()), |
| 776 }; | 801 }; |
| 777 StaticSocketDataProvider data_socket(data_reads, arraysize(data_reads), | 802 |
| 778 NULL, 0); | 803 scoped_array<StaticSocketDataProvider*> data_sockets( |
| 779 mock_socket_factory_.AddSocketDataProvider(ctrl_socket); | 804 new StaticSocketDataProvider*[data_socket + 1]); |
| 780 mock_socket_factory_.AddSocketDataProvider(&data_socket); | 805 for (int i = 0; i < data_socket + 1; i++) { |
| 806 // We only read from one data socket, other ones are dummy. |
| 807 if (i == data_socket) { |
| 808 data_sockets[i] = new StaticSocketDataProvider( |
| 809 data_reads, arraysize(data_reads), NULL, 0); |
| 810 } else { |
| 811 data_sockets[i] = new StaticSocketDataProvider; |
| 812 } |
| 813 mock_socket_factory_.AddSocketDataProvider(data_sockets[i]); |
| 814 } |
| 815 |
| 781 FtpRequestInfo request_info = GetRequestInfo(request); | 816 FtpRequestInfo request_info = GetRequestInfo(request); |
| 782 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 817 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
| 783 ASSERT_EQ(ERR_IO_PENDING, | 818 ASSERT_EQ(ERR_IO_PENDING, |
| 784 transaction_.Start(&request_info, callback_.callback(), | 819 transaction_.Start(&request_info, callback_.callback(), |
| 785 BoundNetLog())); | 820 BoundNetLog())); |
| 786 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 821 EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
| 787 ASSERT_EQ(expected_result, callback_.WaitForResult()); | 822 ASSERT_EQ(expected_result, callback_.WaitForResult()); |
| 788 if (expected_result == OK) { | 823 if (expected_result == OK) { |
| 789 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); | 824 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); |
| 790 memset(io_buffer->data(), 0, kBufferSize); | 825 memset(io_buffer->data(), 0, kBufferSize); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 808 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); | 843 EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); |
| 809 } | 844 } |
| 810 | 845 |
| 811 void TransactionFailHelper(FtpSocketDataProvider* ctrl_socket, | 846 void TransactionFailHelper(FtpSocketDataProvider* ctrl_socket, |
| 812 const char* request, | 847 const char* request, |
| 813 FtpSocketDataProvider::State state, | 848 FtpSocketDataProvider::State state, |
| 814 FtpSocketDataProvider::State next_state, | 849 FtpSocketDataProvider::State next_state, |
| 815 const char* response, | 850 const char* response, |
| 816 int expected_result) { | 851 int expected_result) { |
| 817 ctrl_socket->InjectFailure(state, next_state, response); | 852 ctrl_socket->InjectFailure(state, next_state, response); |
| 818 ExecuteTransaction(ctrl_socket, request, expected_result); | 853 ExecuteTransaction(ctrl_socket, request, 1, expected_result); |
| 819 } | 854 } |
| 820 | 855 |
| 821 scoped_ptr<MockHostResolver> host_resolver_; | 856 scoped_ptr<MockHostResolver> host_resolver_; |
| 822 scoped_refptr<FtpNetworkSession> session_; | 857 scoped_refptr<FtpNetworkSession> session_; |
| 823 MockClientSocketFactory mock_socket_factory_; | 858 MockClientSocketFactory mock_socket_factory_; |
| 824 FtpNetworkTransaction transaction_; | 859 FtpNetworkTransaction transaction_; |
| 825 TestCompletionCallback callback_; | 860 TestCompletionCallback callback_; |
| 826 }; | 861 }; |
| 827 | 862 |
| 828 TEST_F(FtpNetworkTransactionTest, FailedLookup) { | 863 TEST_F(FtpNetworkTransactionTest, FailedLookup) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 841 TEST_F(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) { | 876 TEST_F(FtpNetworkTransactionTest, StripBracketsFromIPv6Literals) { |
| 842 host_resolver_->rules()->AddSimulatedFailure("[::1]"); | 877 host_resolver_->rules()->AddSimulatedFailure("[::1]"); |
| 843 | 878 |
| 844 // We start a transaction that is expected to fail with ERR_INVALID_RESPONSE. | 879 // We start a transaction that is expected to fail with ERR_INVALID_RESPONSE. |
| 845 // The important part of this test is to make sure that we don't fail with | 880 // The important part of this test is to make sure that we don't fail with |
| 846 // ERR_NAME_NOT_RESOLVED, since that would mean the decorated hostname | 881 // ERR_NAME_NOT_RESOLVED, since that would mean the decorated hostname |
| 847 // was used. | 882 // was used. |
| 848 FtpSocketDataProviderEvilSize ctrl_socket( | 883 FtpSocketDataProviderEvilSize ctrl_socket( |
| 849 "213 99999999999999999999999999999999\r\n", | 884 "213 99999999999999999999999999999999\r\n", |
| 850 FtpSocketDataProvider::PRE_QUIT); | 885 FtpSocketDataProvider::PRE_QUIT); |
| 851 ExecuteTransaction(&ctrl_socket, "ftp://[::1]/file", ERR_INVALID_RESPONSE); | 886 ExecuteTransaction(&ctrl_socket, "ftp://[::1]/file", 1, ERR_INVALID_RESPONSE); |
| 852 } | 887 } |
| 853 | 888 |
| 854 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { | 889 TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { |
| 855 FtpSocketDataProviderDirectoryListing ctrl_socket; | 890 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 856 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 891 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 857 | 892 |
| 858 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); | 893 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); |
| 859 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); | 894 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); |
| 860 EXPECT_EQ("192.0.2.33", | 895 EXPECT_EQ("192.0.2.33", |
| 861 transaction_.GetResponseInfo()->socket_address.host()); | 896 transaction_.GetResponseInfo()->socket_address.host()); |
| 862 EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); | 897 EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); |
| 863 } | 898 } |
| 864 | 899 |
| 865 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionWithPasvFallback) { | 900 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionWithPasvFallback) { |
| 866 FtpSocketDataProviderDirectoryListingWithPasvFallback ctrl_socket; | 901 FtpSocketDataProviderDirectoryListingWithPasvFallback ctrl_socket; |
| 867 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 902 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 868 | 903 |
| 869 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); | 904 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); |
| 870 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); | 905 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); |
| 871 } | 906 } |
| 872 | 907 |
| 873 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionWithTypecode) { | 908 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionWithTypecode) { |
| 874 FtpSocketDataProviderDirectoryListing ctrl_socket; | 909 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 875 ExecuteTransaction(&ctrl_socket, "ftp://host;type=d", OK); | 910 ExecuteTransaction(&ctrl_socket, "ftp://host;type=d", 1, OK); |
| 876 | 911 |
| 877 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); | 912 EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); |
| 878 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); | 913 EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); |
| 879 } | 914 } |
| 880 | 915 |
| 881 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { | 916 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcome) { |
| 882 FtpSocketDataProviderDirectoryListing ctrl_socket; | 917 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 883 ctrl_socket.set_multiline_welcome(true); | 918 ctrl_socket.set_multiline_welcome(true); |
| 884 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 919 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 885 } | 920 } |
| 886 | 921 |
| 887 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads2) { | 922 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads2) { |
| 888 FtpSocketDataProviderDirectoryListing ctrl_socket; | 923 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 889 ctrl_socket.set_short_read_limit(2); | 924 ctrl_socket.set_short_read_limit(2); |
| 890 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 925 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 891 } | 926 } |
| 892 | 927 |
| 893 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads5) { | 928 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionShortReads5) { |
| 894 FtpSocketDataProviderDirectoryListing ctrl_socket; | 929 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 895 ctrl_socket.set_short_read_limit(5); | 930 ctrl_socket.set_short_read_limit(5); |
| 896 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 931 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 897 } | 932 } |
| 898 | 933 |
| 899 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcomeShort) { | 934 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionMultilineWelcomeShort) { |
| 900 FtpSocketDataProviderDirectoryListing ctrl_socket; | 935 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 901 // The client will not consume all three 230 lines. That's good, we want to | 936 // The client will not consume all three 230 lines. That's good, we want to |
| 902 // test that scenario. | 937 // test that scenario. |
| 903 ctrl_socket.allow_unconsumed_reads(true); | 938 ctrl_socket.allow_unconsumed_reads(true); |
| 904 ctrl_socket.set_multiline_welcome(true); | 939 ctrl_socket.set_multiline_welcome(true); |
| 905 ctrl_socket.set_short_read_limit(5); | 940 ctrl_socket.set_short_read_limit(5); |
| 906 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 941 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 907 } | 942 } |
| 908 | 943 |
| 909 // Regression test for http://crbug.com/60555. | 944 // Regression test for http://crbug.com/60555. |
| 910 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionZeroSize) { | 945 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionZeroSize) { |
| 911 FtpSocketDataProviderDirectoryListingZeroSize ctrl_socket; | 946 FtpSocketDataProviderDirectoryListingZeroSize ctrl_socket; |
| 912 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 947 ExecuteTransaction(&ctrl_socket, "ftp://host", 0, OK); |
| 913 } | 948 } |
| 914 | 949 |
| 915 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMS) { | 950 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMS) { |
| 916 FtpSocketDataProviderVMSDirectoryListing ctrl_socket; | 951 FtpSocketDataProviderVMSDirectoryListing ctrl_socket; |
| 917 ExecuteTransaction(&ctrl_socket, "ftp://host/dir", OK); | 952 ExecuteTransaction(&ctrl_socket, "ftp://host/dir", 1, OK); |
| 918 } | 953 } |
| 919 | 954 |
| 920 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMSRootDirectory) { | 955 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionVMSRootDirectory) { |
| 921 FtpSocketDataProviderVMSDirectoryListingRootDirectory ctrl_socket; | 956 FtpSocketDataProviderVMSDirectoryListingRootDirectory ctrl_socket; |
| 922 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 957 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 923 } | 958 } |
| 924 | 959 |
| 925 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionTransferStarting) { | 960 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionTransferStarting) { |
| 926 FtpSocketDataProviderDirectoryListingTransferStarting ctrl_socket; | 961 FtpSocketDataProviderDirectoryListingTransferStarting ctrl_socket; |
| 927 ExecuteTransaction(&ctrl_socket, "ftp://host", OK); | 962 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, OK); |
| 928 } | 963 } |
| 929 | 964 |
| 930 TEST_F(FtpNetworkTransactionTest, DownloadTransaction) { | 965 TEST_F(FtpNetworkTransactionTest, DownloadTransaction) { |
| 931 FtpSocketDataProviderFileDownload ctrl_socket; | 966 FtpSocketDataProviderFileDownload ctrl_socket; |
| 932 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 967 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 933 | 968 |
| 934 // We pass an artificial value of 18 as a response to the SIZE command. | 969 // We pass an artificial value of 18 as a response to the SIZE command. |
| 935 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 970 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
| 936 EXPECT_EQ("192.0.2.33", | 971 EXPECT_EQ("192.0.2.33", |
| 937 transaction_.GetResponseInfo()->socket_address.host()); | 972 transaction_.GetResponseInfo()->socket_address.host()); |
| 938 EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); | 973 EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); |
| 939 } | 974 } |
| 940 | 975 |
| 941 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithPasvFallback) { | 976 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithPasvFallback) { |
| 942 FtpSocketDataProviderFileDownloadWithPasvFallback ctrl_socket; | 977 FtpSocketDataProviderFileDownloadWithPasvFallback ctrl_socket; |
| 943 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 978 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 944 | 979 |
| 945 // We pass an artificial value of 18 as a response to the SIZE command. | 980 // We pass an artificial value of 18 as a response to the SIZE command. |
| 946 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 981 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
| 947 } | 982 } |
| 948 | 983 |
| 949 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeA) { | 984 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeA) { |
| 950 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; | 985 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; |
| 951 ctrl_socket.set_data_type('A'); | 986 ctrl_socket.set_data_type('A'); |
| 952 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=a", OK); | 987 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=a", 0, OK); |
| 953 | 988 |
| 954 // We pass an artificial value of 18 as a response to the SIZE command. | 989 // We pass an artificial value of 18 as a response to the SIZE command. |
| 955 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 990 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
| 956 } | 991 } |
| 957 | 992 |
| 958 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeI) { | 993 TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithTypecodeI) { |
| 959 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; | 994 FtpSocketDataProviderFileDownloadWithFileTypecode ctrl_socket; |
| 960 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=i", OK); | 995 ExecuteTransaction(&ctrl_socket, "ftp://host/file;type=i", 0, OK); |
| 961 | 996 |
| 962 // We pass an artificial value of 18 as a response to the SIZE command. | 997 // We pass an artificial value of 18 as a response to the SIZE command. |
| 963 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); | 998 EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); |
| 964 } | 999 } |
| 965 | 1000 |
| 966 TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) { | 1001 TEST_F(FtpNetworkTransactionTest, DownloadTransactionMultilineWelcome) { |
| 967 FtpSocketDataProviderFileDownload ctrl_socket; | 1002 FtpSocketDataProviderFileDownload ctrl_socket; |
| 968 ctrl_socket.set_multiline_welcome(true); | 1003 ctrl_socket.set_multiline_welcome(true); |
| 969 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1004 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 970 } | 1005 } |
| 971 | 1006 |
| 972 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads2) { | 1007 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads2) { |
| 973 FtpSocketDataProviderFileDownload ctrl_socket; | 1008 FtpSocketDataProviderFileDownload ctrl_socket; |
| 974 ctrl_socket.set_short_read_limit(2); | 1009 ctrl_socket.set_short_read_limit(2); |
| 975 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1010 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 976 } | 1011 } |
| 977 | 1012 |
| 978 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads5) { | 1013 TEST_F(FtpNetworkTransactionTest, DownloadTransactionShortReads5) { |
| 979 FtpSocketDataProviderFileDownload ctrl_socket; | 1014 FtpSocketDataProviderFileDownload ctrl_socket; |
| 980 ctrl_socket.set_short_read_limit(5); | 1015 ctrl_socket.set_short_read_limit(5); |
| 981 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1016 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 982 } | 1017 } |
| 983 | 1018 |
| 984 TEST_F(FtpNetworkTransactionTest, DownloadTransactionZeroSize) { | 1019 TEST_F(FtpNetworkTransactionTest, DownloadTransactionZeroSize) { |
| 985 FtpSocketDataProviderFileDownloadZeroSize ctrl_socket; | 1020 FtpSocketDataProviderFileDownloadZeroSize ctrl_socket; |
| 986 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1021 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 987 } | 1022 } |
| 988 | 1023 |
| 989 TEST_F(FtpNetworkTransactionTest, DownloadTransactionCWD451) { | 1024 TEST_F(FtpNetworkTransactionTest, DownloadTransactionCWD451) { |
| 990 FtpSocketDataProviderFileDownloadCWD451 ctrl_socket; | 1025 FtpSocketDataProviderFileDownloadCWD451 ctrl_socket; |
| 991 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1026 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 992 } | 1027 } |
| 993 | 1028 |
| 994 TEST_F(FtpNetworkTransactionTest, DownloadTransactionVMS) { | 1029 TEST_F(FtpNetworkTransactionTest, DownloadTransactionVMS) { |
| 995 FtpSocketDataProviderVMSFileDownload ctrl_socket; | 1030 FtpSocketDataProviderVMSFileDownload ctrl_socket; |
| 996 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1031 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 997 } | 1032 } |
| 998 | 1033 |
| 999 TEST_F(FtpNetworkTransactionTest, DownloadTransactionTransferStarting) { | 1034 TEST_F(FtpNetworkTransactionTest, DownloadTransactionTransferStarting) { |
| 1000 FtpSocketDataProviderFileDownloadTransferStarting ctrl_socket; | 1035 FtpSocketDataProviderFileDownloadTransferStarting ctrl_socket; |
| 1001 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1036 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 1002 } | 1037 } |
| 1003 | 1038 |
| 1004 TEST_F(FtpNetworkTransactionTest, DownloadTransactionInvalidResponse) { | 1039 TEST_F(FtpNetworkTransactionTest, DownloadTransactionInvalidResponse) { |
| 1005 FtpSocketDataProviderFileDownloadInvalidResponse ctrl_socket; | 1040 FtpSocketDataProviderFileDownloadInvalidResponse ctrl_socket; |
| 1006 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1041 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1007 } | 1042 } |
| 1008 | 1043 |
| 1009 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvReallyBadFormat) { | 1044 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvReallyBadFormat) { |
| 1010 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,\r\n", | 1045 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,\r\n", |
| 1011 FtpSocketDataProvider::PRE_QUIT); | 1046 FtpSocketDataProvider::PRE_QUIT); |
| 1012 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1047 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1013 } | 1048 } |
| 1014 | 1049 |
| 1015 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort1) { | 1050 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort1) { |
| 1016 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,0,22)\r\n", | 1051 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,0,22)\r\n", |
| 1017 FtpSocketDataProvider::PRE_QUIT); | 1052 FtpSocketDataProvider::PRE_QUIT); |
| 1018 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1053 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1019 } | 1054 } |
| 1020 | 1055 |
| 1021 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort2) { | 1056 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort2) { |
| 1022 // Still unsafe. 1 * 256 + 2 = 258, which is < 1024. | 1057 // Still unsafe. 1 * 256 + 2 = 258, which is < 1024. |
| 1023 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,1,2)\r\n", | 1058 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,1,2)\r\n", |
| 1024 FtpSocketDataProvider::PRE_QUIT); | 1059 FtpSocketDataProvider::PRE_QUIT); |
| 1025 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1060 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1026 } | 1061 } |
| 1027 | 1062 |
| 1028 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort3) { | 1063 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort3) { |
| 1029 // Still unsafe. 3 * 256 + 4 = 772, which is < 1024. | 1064 // Still unsafe. 3 * 256 + 4 = 772, which is < 1024. |
| 1030 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,3,4)\r\n", | 1065 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,3,4)\r\n", |
| 1031 FtpSocketDataProvider::PRE_QUIT); | 1066 FtpSocketDataProvider::PRE_QUIT); |
| 1032 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1067 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1033 } | 1068 } |
| 1034 | 1069 |
| 1035 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort4) { | 1070 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafePort4) { |
| 1036 // Unsafe. 8 * 256 + 1 = 2049, which is used by nfs. | 1071 // Unsafe. 8 * 256 + 1 = 2049, which is used by nfs. |
| 1037 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,8,1)\r\n", | 1072 FtpSocketDataProviderEvilPasv ctrl_socket("227 Portscan (127,0,0,1,8,1)\r\n", |
| 1038 FtpSocketDataProvider::PRE_QUIT); | 1073 FtpSocketDataProvider::PRE_QUIT); |
| 1039 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1074 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1040 } | 1075 } |
| 1041 | 1076 |
| 1042 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { | 1077 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { |
| 1043 FtpSocketDataProviderEvilPasv ctrl_socket( | 1078 FtpSocketDataProviderEvilPasv ctrl_socket( |
| 1044 "227 Portscan (10,1,2,3,123,456)\r\n", FtpSocketDataProvider::PRE_SIZE); | 1079 "227 Portscan (10,1,2,3,123,456)\r\n", FtpSocketDataProvider::PRE_SIZE); |
| 1045 std::string mock_data("mock-data"); | 1080 std::string mock_data("mock-data"); |
| 1046 MockRead data_reads[] = { | 1081 MockRead data_reads[] = { |
| 1047 MockRead(mock_data.c_str()), | 1082 MockRead(mock_data.c_str()), |
| 1048 }; | 1083 }; |
| 1049 StaticSocketDataProvider data_socket1(data_reads, arraysize(data_reads), | 1084 StaticSocketDataProvider data_socket1; |
| 1085 StaticSocketDataProvider data_socket2(data_reads, arraysize(data_reads), |
| 1050 NULL, 0); | 1086 NULL, 0); |
| 1051 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); | 1087 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket); |
| 1052 mock_socket_factory_.AddSocketDataProvider(&data_socket1); | 1088 mock_socket_factory_.AddSocketDataProvider(&data_socket1); |
| 1089 mock_socket_factory_.AddSocketDataProvider(&data_socket2); |
| 1053 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); | 1090 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); |
| 1054 | 1091 |
| 1055 // Start the transaction. | 1092 // Start the transaction. |
| 1056 ASSERT_EQ(ERR_IO_PENDING, | 1093 ASSERT_EQ(ERR_IO_PENDING, |
| 1057 transaction_.Start(&request_info, callback_.callback(), | 1094 transaction_.Start(&request_info, callback_.callback(), |
| 1058 BoundNetLog())); | 1095 BoundNetLog())); |
| 1059 ASSERT_EQ(OK, callback_.WaitForResult()); | 1096 ASSERT_EQ(OK, callback_.WaitForResult()); |
| 1060 | 1097 |
| 1061 // The transaction fires the callback when we can start reading data. That | 1098 // The transaction fires the callback when we can start reading data. That |
| 1062 // means that the data socket should be open. | 1099 // means that the data socket should be open. |
| 1063 MockTCPClientSocket* data_socket = | 1100 MockTCPClientSocket* data_socket = |
| 1064 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); | 1101 static_cast<MockTCPClientSocket*>(transaction_.data_socket_.get()); |
| 1065 ASSERT_TRUE(data_socket); | 1102 ASSERT_TRUE(data_socket); |
| 1066 ASSERT_TRUE(data_socket->IsConnected()); | 1103 ASSERT_TRUE(data_socket->IsConnected()); |
| 1067 | 1104 |
| 1068 // Even if the PASV response specified some other address, we connect | 1105 // Even if the PASV response specified some other address, we connect |
| 1069 // to the address we used for control connection (which could be 127.0.0.1 | 1106 // to the address we used for control connection (which could be 127.0.0.1 |
| 1070 // or ::1 depending on whether we use IPv6). | 1107 // or ::1 depending on whether we use IPv6). |
| 1071 for (AddressList::const_iterator it = data_socket->addresses().begin(); | 1108 for (AddressList::const_iterator it = data_socket->addresses().begin(); |
| 1072 it != data_socket->addresses().end(); ++it) { | 1109 it != data_socket->addresses().end(); ++it) { |
| 1073 EXPECT_NE("10.1.2.3", it->ToStringWithoutPort()); | 1110 EXPECT_NE("10.1.2.3", it->ToStringWithoutPort()); |
| 1074 } | 1111 } |
| 1075 } | 1112 } |
| 1076 | 1113 |
| 1077 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat1) { | 1114 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat1) { |
| 1078 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||22)\r\n", | 1115 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||22)\r\n", |
| 1079 FtpSocketDataProvider::PRE_QUIT); | 1116 FtpSocketDataProvider::PRE_QUIT); |
| 1080 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1117 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1081 } | 1118 } |
| 1082 | 1119 |
| 1083 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat2) { | 1120 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat2) { |
| 1084 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (||\r\n", | 1121 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (||\r\n", |
| 1085 FtpSocketDataProvider::PRE_QUIT); | 1122 FtpSocketDataProvider::PRE_QUIT); |
| 1086 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1123 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1087 } | 1124 } |
| 1088 | 1125 |
| 1089 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat3) { | 1126 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat3) { |
| 1090 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan\r\n", | 1127 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan\r\n", |
| 1091 FtpSocketDataProvider::PRE_QUIT); | 1128 FtpSocketDataProvider::PRE_QUIT); |
| 1092 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1129 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1093 } | 1130 } |
| 1094 | 1131 |
| 1095 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat4) { | 1132 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat4) { |
| 1096 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (||||)\r\n", | 1133 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (||||)\r\n", |
| 1097 FtpSocketDataProvider::PRE_QUIT); | 1134 FtpSocketDataProvider::PRE_QUIT); |
| 1098 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1135 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1099 } | 1136 } |
| 1100 | 1137 |
| 1101 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat5) { | 1138 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvReallyBadFormat5) { |
| 1102 const char response[] = "227 Portscan (\0\0\031773\0)\r\n"; | 1139 const char response[] = "227 Portscan (\0\0\031773\0)\r\n"; |
| 1103 FtpSocketDataProviderEvilEpsv ctrl_socket(response, sizeof(response)-1, | 1140 FtpSocketDataProviderEvilEpsv ctrl_socket(response, sizeof(response)-1, |
| 1104 FtpSocketDataProvider::PRE_QUIT); | 1141 FtpSocketDataProvider::PRE_QUIT); |
| 1105 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1142 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1106 } | 1143 } |
| 1107 | 1144 |
| 1108 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort1) { | 1145 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort1) { |
| 1109 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||22|)\r\n", | 1146 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||22|)\r\n", |
| 1110 FtpSocketDataProvider::PRE_QUIT); | 1147 FtpSocketDataProvider::PRE_QUIT); |
| 1111 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1148 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1112 } | 1149 } |
| 1113 | 1150 |
| 1114 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort2) { | 1151 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort2) { |
| 1115 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||258|)\r\n", | 1152 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||258|)\r\n", |
| 1116 FtpSocketDataProvider::PRE_QUIT); | 1153 FtpSocketDataProvider::PRE_QUIT); |
| 1117 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1154 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1118 } | 1155 } |
| 1119 | 1156 |
| 1120 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort3) { | 1157 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort3) { |
| 1121 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||772|)\r\n", | 1158 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||772|)\r\n", |
| 1122 FtpSocketDataProvider::PRE_QUIT); | 1159 FtpSocketDataProvider::PRE_QUIT); |
| 1123 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1160 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1124 } | 1161 } |
| 1125 | 1162 |
| 1126 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort4) { | 1163 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvUnsafePort4) { |
| 1127 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||2049|)\r\n", | 1164 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|||2049|)\r\n", |
| 1128 FtpSocketDataProvider::PRE_QUIT); | 1165 FtpSocketDataProvider::PRE_QUIT); |
| 1129 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1166 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1130 } | 1167 } |
| 1131 | 1168 |
| 1132 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvWeirdSep) { | 1169 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvWeirdSep) { |
| 1133 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan ($$$31744$)\r\n", | 1170 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan ($$$31744$)\r\n", |
| 1134 FtpSocketDataProvider::PRE_SIZE); | 1171 FtpSocketDataProvider::PRE_SIZE); |
| 1135 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1172 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 1136 } | 1173 } |
| 1137 | 1174 |
| 1138 TEST_F(FtpNetworkTransactionTest, | 1175 TEST_F(FtpNetworkTransactionTest, |
| 1139 DownloadTransactionEvilEpsvWeirdSepUnsafePort) { | 1176 DownloadTransactionEvilEpsvWeirdSepUnsafePort) { |
| 1140 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan ($$$317$)\r\n", | 1177 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan ($$$317$)\r\n", |
| 1141 FtpSocketDataProvider::PRE_QUIT); | 1178 FtpSocketDataProvider::PRE_QUIT); |
| 1142 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_UNSAFE_PORT); | 1179 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_UNSAFE_PORT); |
| 1143 } | 1180 } |
| 1144 | 1181 |
| 1145 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvIllegalHost) { | 1182 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilEpsvIllegalHost) { |
| 1146 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|2|::1|31744|)\r\n", | 1183 FtpSocketDataProviderEvilEpsv ctrl_socket("227 Portscan (|2|::1|31744|)\r\n", |
| 1147 FtpSocketDataProvider::PRE_QUIT); | 1184 FtpSocketDataProvider::PRE_QUIT); |
| 1148 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1185 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1149 } | 1186 } |
| 1150 | 1187 |
| 1151 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadUsername) { | 1188 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadUsername) { |
| 1152 FtpSocketDataProviderEvilLogin ctrl_socket("hello%0Aworld", "test"); | 1189 FtpSocketDataProviderEvilLogin ctrl_socket("hello%0Aworld", "test"); |
| 1153 ExecuteTransaction(&ctrl_socket, "ftp://hello%0Aworld:test@host/file", OK); | 1190 ExecuteTransaction(&ctrl_socket, "ftp://hello%0Aworld:test@host/file", 1, OK); |
| 1154 } | 1191 } |
| 1155 | 1192 |
| 1156 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadPassword) { | 1193 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilLoginBadPassword) { |
| 1157 FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello%0Dworld"); | 1194 FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello%0Dworld"); |
| 1158 ExecuteTransaction(&ctrl_socket, "ftp://test:hello%0Dworld@host/file", OK); | 1195 ExecuteTransaction(&ctrl_socket, "ftp://test:hello%0Dworld@host/file", 1, OK); |
| 1159 } | 1196 } |
| 1160 | 1197 |
| 1161 TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInLogin) { | 1198 TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInLogin) { |
| 1162 FtpSocketDataProviderEvilLogin ctrl_socket("hello world", "test"); | 1199 FtpSocketDataProviderEvilLogin ctrl_socket("hello world", "test"); |
| 1163 ExecuteTransaction(&ctrl_socket, "ftp://hello%20world:test@host/file", OK); | 1200 ExecuteTransaction(&ctrl_socket, "ftp://hello%20world:test@host/file", 1, OK); |
| 1164 } | 1201 } |
| 1165 | 1202 |
| 1166 TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInPassword) { | 1203 TEST_F(FtpNetworkTransactionTest, DownloadTransactionSpaceInPassword) { |
| 1167 FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello world"); | 1204 FtpSocketDataProviderEvilLogin ctrl_socket("test", "hello world"); |
| 1168 ExecuteTransaction(&ctrl_socket, "ftp://test:hello%20world@host/file", OK); | 1205 ExecuteTransaction(&ctrl_socket, "ftp://test:hello%20world@host/file", 1, OK); |
| 1169 } | 1206 } |
| 1170 | 1207 |
| 1171 TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { | 1208 TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { |
| 1172 FtpSocketDataProvider ctrl_socket1; | 1209 FtpSocketDataProvider ctrl_socket1; |
| 1173 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, | 1210 ctrl_socket1.InjectFailure(FtpSocketDataProvider::PRE_PASSWD, |
| 1174 FtpSocketDataProvider::PRE_QUIT, | 1211 FtpSocketDataProvider::PRE_QUIT, |
| 1175 "530 Login authentication failed\r\n"); | 1212 "530 Login authentication failed\r\n"); |
| 1176 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); | 1213 mock_socket_factory_.AddSocketDataProvider(&ctrl_socket1); |
| 1177 | 1214 |
| 1178 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); | 1215 FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 transaction_.RestartWithAuth( | 1270 transaction_.RestartWithAuth( |
| 1234 AuthCredentials(ASCIIToUTF16("innocent"), | 1271 AuthCredentials(ASCIIToUTF16("innocent"), |
| 1235 ASCIIToUTF16("foo\nownz0red")), | 1272 ASCIIToUTF16("foo\nownz0red")), |
| 1236 callback_.callback())); | 1273 callback_.callback())); |
| 1237 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); | 1274 EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); |
| 1238 } | 1275 } |
| 1239 | 1276 |
| 1240 TEST_F(FtpNetworkTransactionTest, Escaping) { | 1277 TEST_F(FtpNetworkTransactionTest, Escaping) { |
| 1241 FtpSocketDataProviderEscaping ctrl_socket; | 1278 FtpSocketDataProviderEscaping ctrl_socket; |
| 1242 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", | 1279 ExecuteTransaction(&ctrl_socket, "ftp://host/%20%21%22%23%24%25%79%80%81", |
| 1243 OK); | 1280 1, OK); |
| 1244 } | 1281 } |
| 1245 | 1282 |
| 1246 // Test for http://crbug.com/23794. | 1283 // Test for http://crbug.com/23794. |
| 1247 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilSize) { | 1284 TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilSize) { |
| 1248 // Try to overflow int64 in the response. | 1285 // Try to overflow int64 in the response. |
| 1249 FtpSocketDataProviderEvilSize ctrl_socket( | 1286 FtpSocketDataProviderEvilSize ctrl_socket( |
| 1250 "213 99999999999999999999999999999999\r\n", | 1287 "213 99999999999999999999999999999999\r\n", |
| 1251 FtpSocketDataProvider::PRE_QUIT); | 1288 FtpSocketDataProvider::PRE_QUIT); |
| 1252 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE); | 1289 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, ERR_INVALID_RESPONSE); |
| 1253 } | 1290 } |
| 1254 | 1291 |
| 1255 // Test for http://crbug.com/36360. | 1292 // Test for http://crbug.com/36360. |
| 1256 TEST_F(FtpNetworkTransactionTest, DownloadTransactionBigSize) { | 1293 TEST_F(FtpNetworkTransactionTest, DownloadTransactionBigSize) { |
| 1257 // Pass a valid, but large file size. The transaction should not fail. | 1294 // Pass a valid, but large file size. The transaction should not fail. |
| 1258 FtpSocketDataProviderEvilSize ctrl_socket( | 1295 FtpSocketDataProviderEvilSize ctrl_socket( |
| 1259 "213 3204427776\r\n", | 1296 "213 3204427776\r\n", |
| 1260 FtpSocketDataProvider::PRE_CWD); | 1297 FtpSocketDataProvider::PRE_CWD); |
| 1261 ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK); | 1298 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 1, OK); |
| 1262 EXPECT_EQ(3204427776LL, | 1299 EXPECT_EQ(3204427776LL, |
| 1263 transaction_.GetResponseInfo()->expected_content_size); | 1300 transaction_.GetResponseInfo()->expected_content_size); |
| 1264 } | 1301 } |
| 1265 | 1302 |
| 1266 // Regression test for http://crbug.com/25023. | 1303 // Regression test for http://crbug.com/25023. |
| 1267 TEST_F(FtpNetworkTransactionTest, CloseConnection) { | 1304 TEST_F(FtpNetworkTransactionTest, CloseConnection) { |
| 1268 FtpSocketDataProviderCloseConnection ctrl_socket; | 1305 FtpSocketDataProviderCloseConnection ctrl_socket; |
| 1269 ExecuteTransaction(&ctrl_socket, "ftp://host", ERR_EMPTY_RESPONSE); | 1306 ExecuteTransaction(&ctrl_socket, "ftp://host", 1, ERR_EMPTY_RESPONSE); |
| 1270 } | 1307 } |
| 1271 | 1308 |
| 1272 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { | 1309 TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) { |
| 1273 FtpSocketDataProviderDirectoryListing ctrl_socket; | 1310 FtpSocketDataProviderDirectoryListing ctrl_socket; |
| 1274 // Use unallocated 599 FTP error code to make sure it falls into the generic | 1311 // Use unallocated 599 FTP error code to make sure it falls into the generic |
| 1275 // ERR_FTP_FAILED bucket. | 1312 // ERR_FTP_FAILED bucket. |
| 1276 TransactionFailHelper(&ctrl_socket, | 1313 TransactionFailHelper(&ctrl_socket, |
| 1277 "ftp://host", | 1314 "ftp://host", |
| 1278 FtpSocketDataProvider::PRE_USER, | 1315 FtpSocketDataProvider::PRE_USER, |
| 1279 FtpSocketDataProvider::PRE_QUIT, | 1316 FtpSocketDataProvider::PRE_QUIT, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 TransactionFailHelper(&ctrl_socket, | 1488 TransactionFailHelper(&ctrl_socket, |
| 1452 "ftp://host/file", | 1489 "ftp://host/file", |
| 1453 FtpSocketDataProvider::PRE_RETR, | 1490 FtpSocketDataProvider::PRE_RETR, |
| 1454 FtpSocketDataProvider::PRE_QUIT, | 1491 FtpSocketDataProvider::PRE_QUIT, |
| 1455 "599 fail\r\n", | 1492 "599 fail\r\n", |
| 1456 ERR_FTP_FAILED); | 1493 ERR_FTP_FAILED); |
| 1457 } | 1494 } |
| 1458 | 1495 |
| 1459 TEST_F(FtpNetworkTransactionTest, FileNotFound) { | 1496 TEST_F(FtpNetworkTransactionTest, FileNotFound) { |
| 1460 FtpSocketDataProviderFileNotFound ctrl_socket; | 1497 FtpSocketDataProviderFileNotFound ctrl_socket; |
| 1461 ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_FTP_FAILED); | 1498 ExecuteTransaction(&ctrl_socket, "ftp://host/file", 2, ERR_FTP_FAILED); |
| 1462 } | 1499 } |
| 1463 | 1500 |
| 1464 // Test for http://crbug.com/38845. | 1501 // Test for http://crbug.com/38845. |
| 1465 TEST_F(FtpNetworkTransactionTest, ZeroLengthDirInPWD) { | 1502 TEST_F(FtpNetworkTransactionTest, ZeroLengthDirInPWD) { |
| 1466 FtpSocketDataProviderFileDownload ctrl_socket; | 1503 FtpSocketDataProviderFileDownload ctrl_socket; |
| 1467 TransactionFailHelper(&ctrl_socket, | 1504 TransactionFailHelper(&ctrl_socket, |
| 1468 "ftp://host/file", | 1505 "ftp://host/file", |
| 1469 FtpSocketDataProvider::PRE_PWD, | 1506 FtpSocketDataProvider::PRE_PWD, |
| 1470 FtpSocketDataProvider::PRE_TYPE, | 1507 FtpSocketDataProvider::PRE_TYPE, |
| 1471 "257 \"\"\r\n", | 1508 "257 \"\"\r\n", |
| 1472 OK); | 1509 OK); |
| 1473 } | 1510 } |
| 1474 | 1511 |
| 1475 } // namespace net | 1512 } // namespace net |
| OLD | NEW |