diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 06:15:44 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 06:15:44 +0000 |
commit | 13c8a0903376ff406151679d8673a6452d721290 (patch) | |
tree | dbb5b8e9503f8d0ee447863089f3e6f23692910f /net/ftp | |
parent | 6b55570f03236557b8b966b08dfbdda1ea91aadc (diff) | |
download | chromium_src-13c8a0903376ff406151679d8673a6452d721290.zip chromium_src-13c8a0903376ff406151679d8673a6452d721290.tar.gz chromium_src-13c8a0903376ff406151679d8673a6452d721290.tar.bz2 |
Net: Convert username and password to string16.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3040016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r-- | net/ftp/ftp_auth_cache.cc | 10 | ||||
-rw-r--r-- | net/ftp/ftp_auth_cache.h | 20 | ||||
-rw-r--r-- | net/ftp/ftp_auth_cache_unittest.cc | 64 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.cc | 14 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.h | 13 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction_unittest.cc | 21 | ||||
-rw-r--r-- | net/ftp/ftp_transaction.h | 11 |
7 files changed, 86 insertions, 67 deletions
diff --git a/net/ftp/ftp_auth_cache.cc b/net/ftp/ftp_auth_cache.cc index d3bff90..caa2b8a 100644 --- a/net/ftp/ftp_auth_cache.cc +++ b/net/ftp/ftp_auth_cache.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,8 +20,8 @@ FtpAuthCache::Entry* FtpAuthCache::Lookup(const GURL& origin) { return NULL; } -void FtpAuthCache::Add(const GURL& origin, const std::wstring& username, - const std::wstring& password) { +void FtpAuthCache::Add(const GURL& origin, const string16& username, + const string16& password) { DCHECK(origin.SchemeIs("ftp")); DCHECK_EQ(origin.GetOrigin(), origin); @@ -38,8 +38,8 @@ void FtpAuthCache::Add(const GURL& origin, const std::wstring& username, } } -void FtpAuthCache::Remove(const GURL& origin, const std::wstring& username, - const std::wstring& password) { +void FtpAuthCache::Remove(const GURL& origin, const string16& username, + const string16& password) { for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { if (it->origin == origin && it->username == username && it->password == password) { diff --git a/net/ftp/ftp_auth_cache.h b/net/ftp/ftp_auth_cache.h index d541b8e..36156da 100644 --- a/net/ftp/ftp_auth_cache.h +++ b/net/ftp/ftp_auth_cache.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,8 +7,8 @@ #pragma once #include <list> -#include <string> +#include "base/string16.h" #include "googleurl/src/gurl.h" namespace net { @@ -27,16 +27,16 @@ class FtpAuthCache { static const size_t kMaxEntries; struct Entry { - Entry(const GURL& origin, const std::wstring& username, - const std::wstring& password) + Entry(const GURL& origin, const string16& username, + const string16& password) : origin(origin), username(username), password(password) { } const GURL origin; - std::wstring username; - std::wstring password; + string16 username; + string16 password; }; FtpAuthCache() {} @@ -48,13 +48,13 @@ class FtpAuthCache { // Add an entry for |origin| to the cache (consisting of |username| and // |password|). If there is already an entry for |origin|, it will be // overwritten. - void Add(const GURL& origin, const std::wstring& username, - const std::wstring& password); + void Add(const GURL& origin, const string16& username, + const string16& password); // Remove the entry for |origin| from the cache, if one exists and matches // |username| and |password|. - void Remove(const GURL& origin, const std::wstring& username, - const std::wstring& password); + void Remove(const GURL& origin, const string16& username, + const string16& password); private: typedef std::list<Entry> EntryList; diff --git a/net/ftp/ftp_auth_cache_unittest.cc b/net/ftp/ftp_auth_cache_unittest.cc index b23781e..005de89 100644 --- a/net/ftp/ftp_auth_cache_unittest.cc +++ b/net/ftp/ftp_auth_cache_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,22 @@ using net::FtpAuthCache; +namespace { + +const string16 kBogus(ASCIIToUTF16("bogus")); +const string16 kOthername(ASCIIToUTF16("othername")); +const string16 kOtherword(ASCIIToUTF16("otherword")); +const string16 kPassword(ASCIIToUTF16("password")); +const string16 kPassword1(ASCIIToUTF16("password1")); +const string16 kPassword2(ASCIIToUTF16("password2")); +const string16 kPassword3(ASCIIToUTF16("password3")); +const string16 kUsername(ASCIIToUTF16("username")); +const string16 kUsername1(ASCIIToUTF16("username1")); +const string16 kUsername2(ASCIIToUTF16("username2")); +const string16 kUsername3(ASCIIToUTF16("username3")); + +} // namespace + TEST(FtpAuthCacheTest, LookupAddRemove) { FtpAuthCache cache; @@ -20,38 +36,38 @@ TEST(FtpAuthCacheTest, LookupAddRemove) { EXPECT_TRUE(cache.Lookup(origin1) == NULL); // Add entry for origin1. - cache.Add(origin1, L"username1", L"password1"); + cache.Add(origin1, kUsername1, kPassword1); FtpAuthCache::Entry* entry1 = cache.Lookup(origin1); ASSERT_TRUE(entry1); EXPECT_EQ(origin1, entry1->origin); - EXPECT_EQ(L"username1", entry1->username); - EXPECT_EQ(L"password1", entry1->password); + EXPECT_EQ(kUsername1, entry1->username); + EXPECT_EQ(kPassword1, entry1->password); // Add an entry for origin2. - cache.Add(origin2, L"username2", L"password2"); + cache.Add(origin2, kUsername2, kPassword2); FtpAuthCache::Entry* entry2 = cache.Lookup(origin2); ASSERT_TRUE(entry2); EXPECT_EQ(origin2, entry2->origin); - EXPECT_EQ(L"username2", entry2->username); - EXPECT_EQ(L"password2", entry2->password); + EXPECT_EQ(kUsername2, entry2->username); + EXPECT_EQ(kPassword2, entry2->password); // The original entry1 should still be there. EXPECT_EQ(entry1, cache.Lookup(origin1)); // Overwrite the entry for origin1. - cache.Add(origin1, L"username3", L"password3"); + cache.Add(origin1, kUsername3, kPassword3); FtpAuthCache::Entry* entry3 = cache.Lookup(origin1); ASSERT_TRUE(entry3); EXPECT_EQ(origin1, entry3->origin); - EXPECT_EQ(L"username3", entry3->username); - EXPECT_EQ(L"password3", entry3->password); + EXPECT_EQ(kUsername3, entry3->username); + EXPECT_EQ(kPassword3, entry3->password); // Remove entry of origin1. - cache.Remove(origin1, L"username3", L"password3"); + cache.Remove(origin1, kUsername3, kPassword3); EXPECT_TRUE(cache.Lookup(origin1) == NULL); // Remove non-existent entry. - cache.Remove(origin1, L"username3", L"password3"); + cache.Remove(origin1, kUsername3, kPassword3); EXPECT_TRUE(cache.Lookup(origin1) == NULL); } @@ -63,8 +79,8 @@ TEST(FtpAuthCacheTest, LookupWithPort) { GURL origin1("ftp://foo:80"); GURL origin2("ftp://foo:21"); - cache.Add(origin1, L"username", L"password"); - cache.Add(origin2, L"username", L"password"); + cache.Add(origin1, kUsername, kPassword); + cache.Add(origin2, kUsername, kPassword); EXPECT_NE(cache.Lookup(origin1), cache.Lookup(origin2)); } @@ -77,7 +93,7 @@ TEST(FtpAuthCacheTest, NormalizedKey) { FtpAuthCache cache; // Add. - cache.Add(GURL("ftp://HoSt:21"), L"username", L"password"); + cache.Add(GURL("ftp://HoSt:21"), kUsername, kPassword); // Lookup. FtpAuthCache::Entry* entry1 = cache.Lookup(GURL("ftp://HoSt:21")); @@ -86,30 +102,30 @@ TEST(FtpAuthCacheTest, NormalizedKey) { EXPECT_EQ(entry1, cache.Lookup(GURL("ftp://host"))); // Overwrite. - cache.Add(GURL("ftp://host"), L"othername", L"otherword"); + cache.Add(GURL("ftp://host"), kOthername, kOtherword); FtpAuthCache::Entry* entry2 = cache.Lookup(GURL("ftp://HoSt:21")); ASSERT_TRUE(entry2); EXPECT_EQ(GURL("ftp://host"), entry2->origin); - EXPECT_EQ(L"othername", entry2->username); - EXPECT_EQ(L"otherword", entry2->password); + EXPECT_EQ(kOthername, entry2->username); + EXPECT_EQ(kOtherword, entry2->password); // Remove - cache.Remove(GURL("ftp://HOsT"), L"othername", L"otherword"); + cache.Remove(GURL("ftp://HOsT"), kOthername, kOtherword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); } TEST(FtpAuthCacheTest, OnlyRemoveMatching) { FtpAuthCache cache; - cache.Add(GURL("ftp://host"), L"username", L"password"); + cache.Add(GURL("ftp://host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); // Auth data doesn't match, shouldn't remove. - cache.Remove(GURL("ftp://host"), L"bogus", L"bogus"); + cache.Remove(GURL("ftp://host"), kBogus, kBogus); EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); // Auth data matches, should remove. - cache.Remove(GURL("ftp://host"), L"username", L"password"); + cache.Remove(GURL("ftp://host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); } @@ -117,7 +133,7 @@ TEST(FtpAuthCacheTest, EvictOldEntries) { FtpAuthCache cache; for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) - cache.Add(GURL("ftp://host" + IntToString(i)), L"username", L"password"); + cache.Add(GURL("ftp://host" + IntToString(i)), kUsername, kPassword); // No entries should be evicted before reaching the limit. for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { @@ -125,7 +141,7 @@ TEST(FtpAuthCacheTest, EvictOldEntries) { } // Adding one entry should cause eviction of the first entry. - cache.Add(GURL("ftp://last_host"), L"username", L"password"); + cache.Add(GURL("ftp://last_host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host0")) == NULL); // Remaining entries should not get evicted. diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc index 471e8c9..85cac4b 100644 --- a/net/ftp/ftp_network_transaction.cc +++ b/net/ftp/ftp_network_transaction.cc @@ -212,8 +212,8 @@ int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, if (request_->url.has_username()) { GetIdentityFromURL(request_->url, &username_, &password_); } else { - username_ = L"anonymous"; - password_ = L"chrome@example.com"; + username_ = ASCIIToUTF16("anonymous"); + password_ = ASCIIToUTF16("chrome@example.com"); } DetectTypecode(); @@ -234,8 +234,8 @@ int FtpNetworkTransaction::Stop(int error) { return OK; } -int FtpNetworkTransaction::RestartWithAuth(const std::wstring& username, - const std::wstring& password, +int FtpNetworkTransaction::RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback) { ResetStateForRestart(); @@ -653,7 +653,7 @@ int FtpNetworkTransaction::DoCtrlReadComplete(int result) { // Some servers (for example Pure-FTPd) apparently close the control // connection when anonymous login is not permitted. For more details // see http://crbug.com/25023. - if (command_sent_ == COMMAND_USER && username_ == L"anonymous") + if (command_sent_ == COMMAND_USER && username_ == ASCIIToUTF16("anonymous")) response_.needs_auth = true; return Stop(ERR_EMPTY_RESPONSE); } @@ -700,7 +700,7 @@ int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { // USER Command. int FtpNetworkTransaction::DoCtrlWriteUSER() { - std::string command = "USER " + WideToUTF8(username_); + std::string command = "USER " + UTF16ToUTF8(username_); if (!IsValidFTPCommandString(command)) return Stop(ERR_MALFORMED_IDENTITY); @@ -732,7 +732,7 @@ int FtpNetworkTransaction::ProcessResponseUSER( // PASS command. int FtpNetworkTransaction::DoCtrlWritePASS() { - std::string command = "PASS " + WideToUTF8(password_); + std::string command = "PASS " + UTF16ToUTF8(password_); if (!IsValidFTPCommandString(command)) return Stop(ERR_MALFORMED_IDENTITY); diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h index 6b2a1f8..3732157 100644 --- a/net/ftp/ftp_network_transaction.h +++ b/net/ftp/ftp_network_transaction.h @@ -6,13 +6,14 @@ #define NET_FTP_FTP_NETWORK_TRANSACTION_H_ #pragma once -#include <string> #include <queue> +#include <string> #include <utility> #include <vector> #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "net/base/address_list.h" #include "net/base/host_resolver.h" #include "net/base/net_log.h" @@ -37,8 +38,8 @@ class FtpNetworkTransaction : public FtpTransaction { CompletionCallback* callback, const BoundNetLog& net_log); virtual int Stop(int error); - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback); virtual int RestartIgnoringLastError(CompletionCallback* callback); virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); @@ -201,10 +202,8 @@ class FtpNetworkTransaction : public FtpTransaction { // EPSV fail, we fall back to PASV for the duration of connection. bool use_epsv_; - // We get username and password as wstrings in RestartWithAuth, so they are - // also kept as wstrings here. - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; // Current directory on the remote server, as returned by last PWD command, // with any trailing slash removed. diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index c5aed0d..5745ae7 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "build/build_config.h" #include "base/ref_counted.h" +#include "base/string_util.h" #include "net/base/io_buffer.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_util.h" @@ -81,8 +82,8 @@ class FtpSocketDataProvider : public DynamicSocketDataProvider { return Verify("EPSV\r\n", data, PRE_SIZE, "227 Entering Extended Passive Mode (|||31744|)\r\n"); case PRE_NOPASV: - // Use unallocated 599 FTP error code to make sure it falls into the generic - // ERR_FTP_FAILED bucket. + // Use unallocated 599 FTP error code to make sure it falls into the + // generic ERR_FTP_FAILED bucket. return Verify("PASV\r\n", data, PRE_QUIT, "599 fail\r\n"); case PRE_QUIT: @@ -1045,9 +1046,10 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), ctrl_writes, arraysize(ctrl_writes)); mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); - ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red", - L"innocent", - &callback_)); + ASSERT_EQ(ERR_IO_PENDING, + transaction_.RestartWithAuth(ASCIIToUTF16("foo\nownz0red"), + ASCIIToUTF16("innocent"), + &callback_)); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } @@ -1077,9 +1079,10 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), ctrl_writes, arraysize(ctrl_writes)); mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); - ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", - L"foo\nownz0red", - &callback_)); + ASSERT_EQ(ERR_IO_PENDING, + transaction_.RestartWithAuth(ASCIIToUTF16("innocent"), + ASCIIToUTF16("foo\nownz0red"), + &callback_)); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } diff --git a/net/ftp/ftp_transaction.h b/net/ftp/ftp_transaction.h index b4d1f76..b1f1add 100644 --- a/net/ftp/ftp_transaction.h +++ b/net/ftp/ftp_transaction.h @@ -1,11 +1,12 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifndef NET_FTP_FTP_TRANSACTION_H_ #define NET_FTP_FTP_TRANSACTION_H_ #pragma once +#include "base/string16.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/load_states.h" @@ -42,8 +43,8 @@ class FtpTransaction { const BoundNetLog& net_log) = 0; // Restarts the FTP transaction with authentication credentials. - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback) = 0; // Once response info is available for the transaction, response data may be |