diff options
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_request_ftp_job.cc | 9 | ||||
-rw-r--r-- | net/url_request/url_request_new_ftp_job.cc | 24 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 96 |
3 files changed, 5 insertions, 124 deletions
diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index bc7f085..eca845a 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -138,8 +138,7 @@ void URLRequestFtpJob::SendRequest() { username = WideToUTF8(server_auth_->username); password = WideToUTF8(server_auth_->password); request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), - server_auth_->username, - server_auth_->password); + server_auth_.get()); } else { if (request_->url().has_username()) { username = request_->url().username(); @@ -184,15 +183,13 @@ void URLRequestFtpJob::OnIOComplete(const AsyncResult& result) { GURL origin = request_->url().GetOrigin(); if (server_auth_ != NULL && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) { - request_->context()->ftp_auth_cache()->Remove(origin, - server_auth_->username, - server_auth_->password); + request_->context()->ftp_auth_cache()->Remove(origin); } else { server_auth_ = new net::AuthData(); } server_auth_->state = net::AUTH_STATE_NEED_AUTH; - net::FtpAuthCache::Entry* cached_auth = + scoped_refptr<net::AuthData> cached_auth = request_->context()->ftp_auth_cache()->Lookup(origin); if (cached_auth) { diff --git a/net/url_request/url_request_new_ftp_job.cc b/net/url_request/url_request_new_ftp_job.cc index 172e5f4..40b23c4 100644 --- a/net/url_request/url_request_new_ftp_job.cc +++ b/net/url_request/url_request_new_ftp_job.cc @@ -136,9 +136,6 @@ void URLRequestNewFtpJob::SetAuth(const std::wstring& username, server_auth_->username = username; server_auth_->password = password; - request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), - username, password); - RestartTransactionWithAuth(); } @@ -365,26 +362,9 @@ void URLRequestNewFtpJob::OnStartCompleted(int result) { if (result == net::OK) { NotifyHeadersComplete(); } else if (transaction_->GetResponseInfo()->needs_auth) { - GURL origin = request_->url().GetOrigin(); - if (server_auth_ && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) { - request_->context()->ftp_auth_cache()->Remove(origin, - server_auth_->username, - server_auth_->password); - } else if (!server_auth_) { - server_auth_ = new net::AuthData(); - } + server_auth_ = new net::AuthData(); server_auth_->state = net::AUTH_STATE_NEED_AUTH; - - net::FtpAuthCache::Entry* cached_auth = - request_->context()->ftp_auth_cache()->Lookup(origin); - - if (cached_auth) { - // Retry using cached auth data. - SetAuth(cached_auth->username, cached_auth->password); - } else { - // Prompt for a username/password. - NotifyHeadersComplete(); - } + NotifyHeadersComplete(); } else { NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); } diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 0926c30..d82e085 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -2123,99 +2123,3 @@ TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); } } - -TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { - ASSERT_TRUE(NULL != server_.get()); - FilePath app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path = app_path.AppendASCII("LICENSE"); - - scoped_ptr<TestDelegate> d(new TestDelegate); - { - // Pass correct login identity in the URL. - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "chrome"), - d.get()); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_FALSE(r.is_pending()); - EXPECT_EQ(1, d->response_started_count()); - EXPECT_FALSE(d->received_data_before_response()); - EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); - } - - d.reset(new TestDelegate); - { - // This request should use cached identity from previous request. - TestURLRequest r(server_->TestServerPage("/LICENSE"), d.get()); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_FALSE(r.is_pending()); - EXPECT_EQ(1, d->response_started_count()); - EXPECT_FALSE(d->received_data_before_response()); - EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); - } -} - -TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { - ASSERT_TRUE(NULL != server_.get()); - FilePath app_path; - PathService::Get(base::DIR_SOURCE_ROOT, &app_path); - app_path = app_path.AppendASCII("LICENSE"); - - scoped_ptr<TestDelegate> d(new TestDelegate); - // Set correct login credentials. The delegate will be asked for them when - // the initial login with wrong credentials will fail. - d->set_username(L"chrome"); - d->set_password(L"chrome"); - { - TestURLRequest r(server_->TestServerPage("/LICENSE", - "chrome", "wrong_password"), - d.get()); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_FALSE(r.is_pending()); - EXPECT_EQ(1, d->response_started_count()); - EXPECT_FALSE(d->received_data_before_response()); - EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); - } - - // Use a new delegate without explicit credentials. The cached ones should be - // used. - d.reset(new TestDelegate); - { - // Don't pass wrong credentials in the URL, they would override valid cached - // ones. - TestURLRequest r(server_->TestServerPage("/LICENSE"), d.get()); - r.Start(); - EXPECT_TRUE(r.is_pending()); - - MessageLoop::current()->Run(); - - int64 file_size = 0; - file_util::GetFileSize(app_path, &file_size); - - EXPECT_FALSE(r.is_pending()); - EXPECT_EQ(1, d->response_started_count()); - EXPECT_FALSE(d->received_data_before_response()); - EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); - } -} |