diff options
author | oritm@chromium.org <oritm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 23:54:07 +0000 |
---|---|---|
committer | oritm@chromium.org <oritm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-28 23:54:07 +0000 |
commit | 450b0af61eea4166dc4b680f96fba739ce1f600e (patch) | |
tree | 67d6eeaae85e03212e4d17a2d4ef66cf0715a8b7 | |
parent | c4ec7a133b4488f8f5145860e9247d328fc794f1 (diff) | |
download | chromium_src-450b0af61eea4166dc4b680f96fba739ce1f600e.zip chromium_src-450b0af61eea4166dc4b680f96fba739ce1f600e.tar.gz chromium_src-450b0af61eea4166dc4b680f96fba739ce1f600e.tar.bz2 |
Merge 48456 - Remove signin and persist from gaia_authenticator. This fixes an issue where Chromium OS did not persist sync cookies.
TEST=included unit tests
BUG=http://crosbug.com/2786
Review URL: http://codereview.chromium.org/2124020
TBR=chron@chromium.org
Review URL: http://codereview.chromium.org/2353003
git-svn-id: svn://svn.chromium.org/chrome/branches/418/src@48545 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/engine/auth_watcher.cc | 48 | ||||
-rw-r--r-- | chrome/browser/sync/engine/auth_watcher.h | 8 | ||||
-rw-r--r-- | chrome/browser/sync/engine/auth_watcher_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/sync/engine/authenticator.cc | 7 | ||||
-rw-r--r-- | chrome/browser/sync/engine/authenticator.h | 9 | ||||
-rw-r--r-- | chrome/browser/sync/engine/net/server_connection_manager.h | 3 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncapi.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/util/user_settings.cc | 45 | ||||
-rw-r--r-- | chrome/browser/sync/util/user_settings.h | 5 | ||||
-rw-r--r-- | chrome/browser/sync/util/user_settings_unittest.cc | 85 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_authenticator.cc | 58 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_authenticator.h | 49 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_authenticator_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/common/net/gaia/signin.h | 18 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy_backend.cc | 4 |
15 files changed, 145 insertions, 213 deletions
diff --git a/chrome/browser/sync/engine/auth_watcher.cc b/chrome/browser/sync/engine/auth_watcher.cc index 53c21cf..e75b6de 100644 --- a/chrome/browser/sync/engine/auth_watcher.cc +++ b/chrome/browser/sync/engine/auth_watcher.cc @@ -78,18 +78,14 @@ void AuthWatcher::PersistCredentials() { ClearAuthenticationData(); user_settings_->StoreEmailForSignin(results.email, results.primary_email); - user_settings_->RememberSigninType(results.email, results.signin); - user_settings_->RememberSigninType(results.primary_email, results.signin); results.email = results.primary_email; gaia_->SetUsernamePassword(results.primary_email, results.password); if (!user_settings_->VerifyAgainstStoredHash(results.email, results.password)) user_settings_->StoreHashedPassword(results.email, results.password); - if (gaia::PERSIST_TO_DISK == results.credentials_saved) { - user_settings_->SetAuthTokenForService(results.email, - SYNC_SERVICE_NAME, - gaia_->auth_token()); - } + user_settings_->SetAuthTokenForService(results.email, + SYNC_SERVICE_NAME, + gaia_->auth_token()); } // TODO(chron): Full integration test suite needed. http://crbug.com/35429 @@ -130,7 +126,7 @@ void AuthWatcher::DoAuthenticateWithLsid(const std::string& lsid) { AuthWatcherEvent event = { AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START }; NotifyListeners(&event); - if (gaia_->AuthenticateWithLsid(lsid, true)) { + if (gaia_->AuthenticateWithLsid(lsid)) { PersistCredentials(); DoAuthenticateWithToken(gaia_->email(), gaia_->auth_token()); } else { @@ -159,9 +155,10 @@ void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email, LOG(INFO) << "Auth returned email " << email << " for gaia email " << gaia_email; } + AuthWatcherEvent event = {AuthWatcherEvent::ILLEGAL_VALUE , 0}; gaia_->SetUsername(email); - gaia_->SetAuthToken(auth_token, gaia::SAVE_IN_MEMORY_ONLY); + gaia_->SetAuthToken(auth_token); const bool was_authenticated = NOT_AUTHENTICATED != status_; switch (result) { case Authenticator::SUCCESS: @@ -235,15 +232,11 @@ void AuthWatcher::ProcessGaiaAuthFailure() { if (LOCALLY_AUTHENTICATED == status_) { return; // nothing todo } else if (AuthenticateLocally(results.email, results.password)) { - // We save the "Remember me" checkbox by putting a non-null auth - // token into the last_user table. So if we're offline and the - // user checks the box, insert a bogus auth token. - if (gaia::PERSIST_TO_DISK == results.credentials_saved) { - const string auth_token("bogus"); - user_settings_->SetAuthTokenForService(results.email, - SYNC_SERVICE_NAME, - auth_token); - } + // TODO(chron): Do we really want a bogus token? + const string auth_token("bogus"); + user_settings_->SetAuthTokenForService(results.email, + SYNC_SERVICE_NAME, + auth_token); const bool unavailable = gaia::ConnectionUnavailable == results.auth_error || gaia::Unknown == results.auth_error || @@ -263,11 +256,6 @@ void AuthWatcher::DoAuthenticate(const AuthRequest& request) { current_attempt_trigger_ = request.trigger; - gaia::SaveCredentials save = request.persist_creds_to_disk ? - gaia::PERSIST_TO_DISK : gaia::SAVE_IN_MEMORY_ONLY; - gaia::SignIn const signin = user_settings_-> - RecallSigninType(request.email, gaia::GMAIL_SIGNIN); - // We let the caller be lazy and try using the last captcha token seen by // the gaia authenticator if they haven't provided a token but have sent // a challenge response. Of course, if the captcha token is specified, @@ -280,11 +268,10 @@ void AuthWatcher::DoAuthenticate(const AuthRequest& request) { bool authenticated = false; if (!captcha_token.empty()) { authenticated = gaia_->Authenticate(request.email, request.password, - save, captcha_token, - request.captcha_value, signin); + captcha_token, + request.captcha_value); } else { - authenticated = gaia_->Authenticate(request.email, request.password, - save, signin); + authenticated = gaia_->Authenticate(request.email, request.password); } if (authenticated) { PersistCredentials(); @@ -334,8 +321,6 @@ void AuthWatcher::DoHandleServerConnectionEvent( AuthRequest request = { authresults.email, authresults.password, authresults.auth_token, std::string(), std::string(), - gaia::PERSIST_TO_DISK == - authresults.credentials_saved, AuthWatcherEvent::EXPIRED_CREDENTIALS }; DoAuthenticate(request); } @@ -352,13 +337,12 @@ AuthWatcher::~AuthWatcher() { } void AuthWatcher::Authenticate(const string& email, const string& password, - const string& captcha_token, const string& captcha_value, - bool persist_creds_to_disk) { + const string& captcha_token, const string& captcha_value) { LOG(INFO) << "AuthWatcher::Authenticate called"; string empty; AuthRequest request = { FormatAsEmailAddress(email), password, empty, - captcha_token, captcha_value, persist_creds_to_disk, + captcha_token, captcha_value, AuthWatcherEvent::USER_INITIATED }; message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &AuthWatcher::DoAuthenticate, request)); diff --git a/chrome/browser/sync/engine/auth_watcher.h b/chrome/browser/sync/engine/auth_watcher.h index 7ae3f98..5649136 100644 --- a/chrome/browser/sync/engine/auth_watcher.h +++ b/chrome/browser/sync/engine/auth_watcher.h @@ -111,12 +111,11 @@ class AuthWatcher : public base::RefCountedThreadSafe<AuthWatcher> { // convenience in the common case so the token doesn't have to be plumbed // everywhere. void Authenticate(const std::string& email, const std::string& password, - const std::string& captcha_token, const std::string& captcha_value, - bool persist_creds_to_disk); + const std::string& captcha_token, const std::string& captcha_value); void Authenticate(const std::string& email, const std::string& password, bool persist_creds_to_disk) { - Authenticate(email, password, "", "", persist_creds_to_disk); + Authenticate(email, password, "", ""); } // Use this to update only the token of the current email address. @@ -150,8 +149,7 @@ class AuthWatcher : public base::RefCountedThreadSafe<AuthWatcher> { void HandleServerConnectionEvent(const ServerConnectionEvent& event); void SaveUserSettings(const std::string& username, - const std::string& auth_token, - const bool save_credentials); + const std::string& auth_token); MessageLoop* message_loop() { return auth_backend_thread_.message_loop(); } diff --git a/chrome/browser/sync/engine/auth_watcher_unittest.cc b/chrome/browser/sync/engine/auth_watcher_unittest.cc index 6a0e3dc..9a33e59 100644 --- a/chrome/browser/sync/engine/auth_watcher_unittest.cc +++ b/chrome/browser/sync/engine/auth_watcher_unittest.cc @@ -71,11 +71,6 @@ class GaiaAuthMockForAuthWatcher : public gaia::GaiaAuthenticator { return true; } - bool LookupEmail(AuthResults* results) { - results->signin = gaia::GMAIL_SIGNIN; - return true; - } - void RenewAuthToken(const std::string& auth_token) { renewed_token_ = auth_token; } @@ -194,8 +189,8 @@ TEST_F(AuthWatcherTest, Construction) { TEST_F(AuthWatcherTest, AuthenticateGaiaAuthFailure) { auth_watcher()->Authenticate(kTestEmail, kWrongPassword, std::string(), // captcha_token - std::string(), // captcha_value - false); // persist_creds_to_disk + std::string()); // captcha_value + EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); EXPECT_EQ(AuthWatcherEvent::GAIA_AUTH_FAILED, ConsumeNextEvent()); } @@ -203,14 +198,14 @@ TEST_F(AuthWatcherTest, AuthenticateGaiaAuthFailure) { TEST_F(AuthWatcherTest, AuthenticateBadAuthToken) { gaia_auth()->SendBadAuthTokenForNextRequest(); auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), - std::string(), false); + std::string()); EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); EXPECT_EQ(AuthWatcherEvent::SERVICE_AUTH_FAILED, ConsumeNextEvent()); } TEST_F(AuthWatcherTest, AuthenticateSuccess) { auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), - std::string(), false); + std::string()); EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); @@ -233,7 +228,7 @@ TEST_F(AuthWatcherTest, AuthenticateWithTokenSuccess) { // Just check that the thread task was properly issued. TEST_F(AuthWatcherTest, RenewAuthToken) { auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), - std::string(), false); + std::string()); EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); diff --git a/chrome/browser/sync/engine/authenticator.cc b/chrome/browser/sync/engine/authenticator.cc index f8b3ce1..479be99 100644 --- a/chrome/browser/sync/engine/authenticator.cc +++ b/chrome/browser/sync/engine/authenticator.cc @@ -30,16 +30,13 @@ Authenticator::AuthenticationResult Authenticator::Authenticate() { } Authenticator::AuthenticationResult Authenticator::Authenticate( - string username, string password, bool save_credentials) { + string username, string password) { // TODO(sync): need to figure out if this routine is used anywhere other // than the test code. gaia::GaiaAuthenticator auth_service("ChromiumBrowser", "chromiumsync", "https://www.google.com:443/accounts/ClientLogin"); auth_service.set_message_loop(MessageLoop::current()); - const gaia::SignIn signin_type = - settings_->RecallSigninType(username, gaia::GMAIL_SIGNIN); - if (!auth_service.Authenticate(username, password, gaia::SAVE_IN_MEMORY_ONLY, - signin_type)) { + if (!auth_service.Authenticate(username, password)) { return UNSPECIFIC_ERROR_RETURN; } CHECK(!auth_service.auth_token().empty()); diff --git a/chrome/browser/sync/engine/authenticator.h b/chrome/browser/sync/engine/authenticator.h index 95e4698..710fad3 100644 --- a/chrome/browser/sync/engine/authenticator.h +++ b/chrome/browser/sync/engine/authenticator.h @@ -69,14 +69,11 @@ class Authenticator { // any. AuthenticationResult Authenticate(); - // If save_credentials is set we save the long-lived auth token to local disk. - // In all cases we save the username and password in memory (if given) so we + // We save the username and password in memory (if given) so we // can refresh the long-lived auth token if it expires. // Also we save a 10-bit hash of the password to allow offline login. - // TODO(sync): Make it work as described. - // TODO(sync): Arguments for desired domain. - AuthenticationResult Authenticate(std::string username, std::string password, - bool save_credentials); + AuthenticationResult Authenticate(std::string username, std::string password); + // A version of the auth token to authenticate cookie portion of // authentication. It uses the new proto buffer based call instead of the HTTP // GET based one we currently use. diff --git a/chrome/browser/sync/engine/net/server_connection_manager.h b/chrome/browser/sync/engine/net/server_connection_manager.h index 078e7f8..188b4ba 100644 --- a/chrome/browser/sync/engine/net/server_connection_manager.h +++ b/chrome/browser/sync/engine/net/server_connection_manager.h @@ -18,7 +18,6 @@ #include "chrome/browser/sync/util/sync_types.h" #include "chrome/common/deprecated/event_sys.h" #include "chrome/common/net/http_return.h" -#include "chrome/common/net/gaia/signin.h" namespace syncable { class WriteTransaction; @@ -254,8 +253,6 @@ class ServerConnectionManager { const std::string client_id() const { return client_id_; } - void SetDomainFromSignIn(gaia::SignIn signin_type, const std::string& signin); - // This changes the server info used by the connection manager. This allows // a single client instance to talk to different backing servers. This is // typically called during / after authentication so that the server url diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc index ecb0fa3..e052bc6 100644 --- a/chrome/browser/sync/engine/syncapi.cc +++ b/chrome/browser/sync/engine/syncapi.cc @@ -1333,7 +1333,7 @@ void SyncManager::SyncInternal::Authenticate(const std::string& username, RaiseAuthNeededEvent(); } auth_watcher()->Authenticate(username, password, std::string(), - captcha, true); + captcha); } void SyncManager::SyncInternal::AuthenticateWithLsid(const string& lsid) { diff --git a/chrome/browser/sync/util/user_settings.cc b/chrome/browser/sync/util/user_settings.cc index 043d532..f8ac69b 100644 --- a/chrome/browser/sync/util/user_settings.cc +++ b/chrome/browser/sync/util/user_settings.cc @@ -69,7 +69,7 @@ static const char PASSWORD_HASH[] = "password_hash2"; static const char SALT[] = "salt2"; static const int kSaltSize = 20; -static const int kCurrentDBVersion = 11; +static const int kCurrentDBVersion = 12; UserSettings::ScopedDBHandle::ScopedDBHandle(UserSettings* settings) : mutex_lock_(settings->dbhandle_mutex_), handle_(&settings->dbhandle_) { @@ -138,6 +138,10 @@ void UserSettings::MigrateOldVersionsAsNeeded(sqlite3* const handle, ExecOrDie(handle, "DROP TABLE shares"); ExecOrDie(handle, "UPDATE db_version SET version = 11"); // FALL THROUGH + case 11: + ExecOrDie(handle, "DROP TABLE signin_types"); + ExecOrDie(handle, "UPDATE db_version SET version = 12"); + // FALL THROUGH case kCurrentDBVersion: // Nothing to migrate. return; @@ -154,15 +158,6 @@ static void MakeCookiesTable(sqlite3* const dbhandle) { " PRIMARY KEY(email, service_name) ON CONFLICT REPLACE)"); } -static void MakeSigninTypesTable(sqlite3* const dbhandle) { - // With every successful gaia authentication, remember if it was - // a hosted domain or not. - ExecOrDie(dbhandle, - "CREATE TABLE signin_types" - " (signin, signin_type, " - " PRIMARY KEY(signin, signin_type) ON CONFLICT REPLACE)"); -} - static void MakeClientIDTable(sqlite3* const dbhandle) { // Stores a single client ID value that can be used as the client id, if // there's not another such ID provided on the install. @@ -247,7 +242,6 @@ bool UserSettings::Init(const FilePath& settings_path) { MakeSigninsTable(dbhandle.get()); MakeCookiesTable(dbhandle.get()); - MakeSigninTypesTable(dbhandle.get()); MakeClientIDTable(dbhandle.get()); } transaction.Commit(); @@ -429,35 +423,6 @@ void UserSettings::SwitchUser(const string& username) { } } -void UserSettings::RememberSigninType(const string& signin, - gaia::SignIn signin_type) { - ScopedDBHandle dbhandle(this); - SQLStatement statement; - statement.prepare(dbhandle.get(), - "INSERT INTO signin_types(signin, signin_type)" - " values ( ?, ? )"); - statement.bind_string(0, signin); - statement.bind_int(1, static_cast<int>(signin_type)); - if (SQLITE_DONE != statement.step()) { - LOG(FATAL) << sqlite3_errmsg(dbhandle.get()); - } -} - -gaia::SignIn UserSettings::RecallSigninType(const string& signin, - gaia::SignIn default_type) { - ScopedDBHandle dbhandle(this); - SQLStatement statement; - statement.prepare(dbhandle.get(), - "SELECT signin_type from signin_types WHERE signin = ?"); - statement.bind_string(0, signin); - int query_result = statement.step(); - if (SQLITE_ROW == query_result) { - int signin_type = statement.column_int(0); - return static_cast<gaia::SignIn>(signin_type); - } - return default_type; -} - string UserSettings::GetClientId() { ScopedDBHandle dbhandle(this); SQLStatement statement; diff --git a/chrome/browser/sync/util/user_settings.h b/chrome/browser/sync/util/user_settings.h index e379cc0..7bfa571 100644 --- a/chrome/browser/sync/util/user_settings.h +++ b/chrome/browser/sync/util/user_settings.h @@ -13,7 +13,6 @@ #include "base/lock.h" #include "build/build_config.h" #include "chrome/browser/sync/util/sync_types.h" -#include "chrome/common/net/gaia/signin.h" extern "C" struct sqlite3; @@ -59,10 +58,6 @@ class UserSettings { std::string* username, std::string* service_token); - void RememberSigninType(const std::string& signin, gaia::SignIn signin_type); - gaia::SignIn RecallSigninType(const std::string& signin, - gaia::SignIn default_type); - void RemoveAllGuestSettings(); void StoreEmailForSignin(const std::string& signin, diff --git a/chrome/browser/sync/util/user_settings_unittest.cc b/chrome/browser/sync/util/user_settings_unittest.cc index 9f2202f..f17b514 100644 --- a/chrome/browser/sync/util/user_settings_unittest.cc +++ b/chrome/browser/sync/util/user_settings_unittest.cc @@ -23,6 +23,8 @@ using std::numeric_limits; static const FilePath::CharType kV10UserSettingsDB[] = FILE_PATH_LITERAL("Version10Settings.sqlite3"); +static const FilePath::CharType kV11UserSettingsDB[] = + FILE_PATH_LITERAL("Version11Settings.sqlite3"); static const FilePath::CharType kOldStyleSyncDataDB[] = FILE_PATH_LITERAL("OldStyleSyncData.sqlite3"); @@ -36,7 +38,8 @@ class UserSettingsTest : public testing::Test { sqlite3* primer_handle = NULL; v10_user_setting_db_path_ = destination_directory.Append(FilePath(kV10UserSettingsDB)); - ASSERT_EQ(SQLITE_OK, OpenSqliteDb(v10_user_setting_db_path_, &primer_handle)); + ASSERT_EQ(SQLITE_OK, OpenSqliteDb(v10_user_setting_db_path_, + &primer_handle)); old_style_sync_data_path_ = destination_directory.Append(FilePath(kOldStyleSyncDataDB)); @@ -49,7 +52,9 @@ class UserSettingsTest : public testing::Test { ExecOrDie(primer_handle, "CREATE TABLE settings" " (email, key, value, " " PRIMARY KEY(email, key) ON CONFLICT REPLACE)"); - + // Add a blank signin table. + ExecOrDie(primer_handle, "CREATE TABLE signin_types" + " (signin, signin_type)"); // Create and populate version table. ExecOrDie(primer_handle, "CREATE TABLE db_version ( version )"); { @@ -80,10 +85,56 @@ class UserSettingsTest : public testing::Test { sqlite3_close(primer_handle); } + // Creates and populates the V11 database file within + // |destination_directory|. + void SetUpVersion11Database(const FilePath& destination_directory) { + sqlite3* primer_handle = NULL; + v11_user_setting_db_path_ = + destination_directory.Append(FilePath(kV11UserSettingsDB)); + ASSERT_EQ(SQLITE_OK, OpenSqliteDb(v11_user_setting_db_path_, + &primer_handle)); + + // Create settings table. + ExecOrDie(primer_handle, "CREATE TABLE settings" + " (email, key, value, " + " PRIMARY KEY(email, key) ON CONFLICT REPLACE)"); + + // Create and populate version table. + ExecOrDie(primer_handle, "CREATE TABLE db_version ( version )"); + { + SQLStatement statement; + const char query[] = "INSERT INTO db_version values ( ? )"; + statement.prepare(primer_handle, query); + statement.bind_int(0, 11); + if (SQLITE_DONE != statement.step()) { + LOG(FATAL) << query << "\n" << sqlite3_errmsg(primer_handle); + } + } + + ExecOrDie(primer_handle, "CREATE TABLE signin_types" + " (signin, signin_type)"); + + { + SQLStatement statement; + const char query[] = "INSERT INTO signin_types values ( ?, ? )"; + statement.prepare(primer_handle, query); + statement.bind_string(0, "test"); + statement.bind_string(1, "test"); + if (SQLITE_DONE != statement.step()) { + LOG(FATAL) << query << "\n" << sqlite3_errmsg(primer_handle); + } + } + + sqlite3_close(primer_handle); + } + const std::string& sync_data() const { return sync_data_; } const FilePath& v10_user_setting_db_path() const { return v10_user_setting_db_path_; } + const FilePath& v11_user_setting_db_path() const { + return v11_user_setting_db_path_; + } const FilePath& old_style_sync_data_path() const { return old_style_sync_data_path_; } @@ -91,6 +142,9 @@ class UserSettingsTest : public testing::Test { private: FilePath v10_user_setting_db_path_; FilePath old_style_sync_data_path_; + + FilePath v11_user_setting_db_path_; + std::string sync_data_; }; @@ -117,7 +171,7 @@ TEST_F(UserSettingsTest, MigrateFromV10ToV11) { version_query.prepare(handle, "SELECT version FROM db_version"); ASSERT_EQ(SQLITE_ROW, version_query.step()); const int version = version_query.column_int(0); - EXPECT_EQ(11, version); + EXPECT_GE(version, 11); } EXPECT_FALSE(file_util::PathExists(old_style_sync_data_path())); @@ -131,6 +185,31 @@ TEST_F(UserSettingsTest, MigrateFromV10ToV11) { sqlite3_close(handle); } +TEST_F(UserSettingsTest, MigrateFromV11ToV12) { + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + SetUpVersion11Database(temp_dir.path()); + { + UserSettings settings; + settings.Init(v11_user_setting_db_path()); + } + sqlite3* handle = NULL; + ASSERT_EQ(SQLITE_OK, OpenSqliteDb(v11_user_setting_db_path(), &handle)); + + { + SQLStatement version_query; + version_query.prepare(handle, "SELECT version FROM db_version"); + ASSERT_EQ(SQLITE_ROW, version_query.step()); + const int version = version_query.column_int(0); + EXPECT_GE(version, 12); + + SQLStatement table_query; + table_query.prepare(handle, "SELECT name FROM sqlite_master " + "WHERE type='table' AND name='signin_types'"); + ASSERT_NE(SQLITE_ROW, table_query.step()); + } +} + TEST_F(UserSettingsTest, APEncode) { string test; char i; diff --git a/chrome/common/net/gaia/gaia_authenticator.cc b/chrome/common/net/gaia/gaia_authenticator.cc index 38fc19b..f544e94 100644 --- a/chrome/common/net/gaia/gaia_authenticator.cc +++ b/chrome/common/net/gaia/gaia_authenticator.cc @@ -51,49 +51,40 @@ GaiaAuthenticator::~GaiaAuthenticator() { GaiaAuthenticator::AuthParams GaiaAuthenticator::MakeParams( const string& user_name, const string& password, - SaveCredentials should_save_credentials, const string& captcha_token, - const string& captcha_value, - SignIn try_first) { + const string& captcha_value) { AuthParams params; params.request_id = ++request_count_; params.email = user_name; params.password = password; - params.should_save_credentials = should_save_credentials; params.captcha_token = captcha_token; params.captcha_value = captcha_value; params.authenticator = this; - params.try_first = try_first; return params; } bool GaiaAuthenticator::Authenticate(const string& user_name, const string& password, - SaveCredentials should_save_credentials, const string& captcha_token, - const string& captcha_value, - SignIn try_first) { + const string& captcha_value) { DCHECK_EQ(MessageLoop::current(), message_loop_); AuthParams const params = - MakeParams(user_name, password, should_save_credentials, captcha_token, - captcha_value, try_first); + MakeParams(user_name, password, captcha_token, captcha_value); return AuthenticateImpl(params); } -bool GaiaAuthenticator::AuthenticateWithLsid(const string& lsid, - bool long_lived) { +bool GaiaAuthenticator::AuthenticateWithLsid(const string& lsid) { auth_results_.lsid = lsid; // We need to lookup the email associated with this LSID cookie in order to // update |auth_results_| with the correct values. if (LookupEmail(&auth_results_)) { auth_results_.email = auth_results_.primary_email; - return IssueAuthToken(&auth_results_, service_id_, long_lived); + return IssueAuthToken(&auth_results_, service_id_); } return false; } - bool GaiaAuthenticator::AuthenticateImpl(const AuthParams& params) { DCHECK_EQ(MessageLoop::current(), message_loop_); AuthResults results; @@ -119,16 +110,9 @@ bool GaiaAuthenticator::AuthenticateImpl(const AuthParams& params) { bool GaiaAuthenticator::AuthenticateImpl(const AuthParams& params, AuthResults* results) { DCHECK_EQ(MessageLoop::current(), message_loop_); - results->credentials_saved = params.should_save_credentials; results->auth_error = ConnectionUnavailable; - // Save credentials if so requested. - if (params.should_save_credentials != DONT_SAVE_CREDENTIALS) { - results->email = params.email.data(); - results->password = params.password; - } else { // Explicitly clear previously-saved credentials. - results->email = ""; - results->password = ""; - } + results->email = params.email.data(); + results->password = params.password; // The aim of this code is to start failing requests if due to a logic error // in the program we're hammering GAIA. @@ -192,13 +176,9 @@ bool GaiaAuthenticator::PerformGaiaRequest(const AuthParams& params, return false; } else if (RC_REQUEST_OK == server_response_code) { ExtractTokensFrom(message_text, results); - const bool old_gaia = - results->auth_token.empty() && !results->lsid.empty(); - const bool long_lived_token = - params.should_save_credentials == PERSIST_TO_DISK; - if ((old_gaia || long_lived_token) && - !IssueAuthToken(results, service_id_, long_lived_token)) + if (!IssueAuthToken(results, service_id_)) { return false; + } return LookupEmail(results); } else { @@ -240,7 +220,6 @@ bool GaiaAuthenticator::LookupEmail(AuthResults* results) { if ("accountType" == i->first) { // We never authenticate an email as a hosted account. DCHECK_EQ("GOOGLE", i->second); - results->signin = GMAIL_SIGNIN; } else if ("email" == i->first) { results->primary_email = i->second; } @@ -253,8 +232,7 @@ bool GaiaAuthenticator::LookupEmail(AuthResults* results) { // We need to call this explicitly when we need to obtain a long-lived session // token. bool GaiaAuthenticator::IssueAuthToken(AuthResults* results, - const string& service_id, - bool long_lived) { + const string& service_id) { DCHECK_EQ(MessageLoop::current(), message_loop_); // Use the provided Gaia server, but change the path to what V1 expects. GURL url(gaia_url_); // Gaia server. @@ -268,9 +246,7 @@ bool GaiaAuthenticator::IssueAuthToken(AuthResults* results, post_body += "LSID="; post_body += EscapeUrlEncodedData(results->lsid); post_body += "&service=" + service_id; - if (long_lived) { - post_body += "&Session=true"; - } + post_body += "&Session=true"; unsigned long server_response_code; string message_text; @@ -383,21 +359,17 @@ void GaiaAuthenticator::RenewAuthToken(const string& auth_token) { DCHECK(!this->auth_token().empty()); auth_results_.auth_token = auth_token; } -void GaiaAuthenticator::SetAuthToken(const string& auth_token, - SaveCredentials save) { +void GaiaAuthenticator::SetAuthToken(const string& auth_token) { DCHECK_EQ(MessageLoop::current(), message_loop_); auth_results_.auth_token = auth_token; - auth_results_.credentials_saved = save; } bool GaiaAuthenticator::Authenticate(const string& user_name, - const string& password, - SaveCredentials should_save_credentials, - SignIn try_first) { + const string& password) { DCHECK_EQ(MessageLoop::current(), message_loop_); const string empty; - return Authenticate(user_name, password, should_save_credentials, empty, - empty, try_first); + return Authenticate(user_name, password, empty, + empty); } } // namepace gaia diff --git a/chrome/common/net/gaia/gaia_authenticator.h b/chrome/common/net/gaia/gaia_authenticator.h index b165cf6..d34af2d 100644 --- a/chrome/common/net/gaia/gaia_authenticator.h +++ b/chrome/common/net/gaia/gaia_authenticator.h @@ -24,8 +24,7 @@ // TODO(sanjeevr): This class has been moved here from the bookmarks sync code. // While it is a generic class that handles GAIA authentication, there are some -// artifacts of the sync code such as the SaveCredentials enum which needs to -// be cleaned up. +// artifacts of the sync code which needs to be cleaned up. #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR_H_ #define CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR_H_ @@ -33,7 +32,6 @@ #include "base/basictypes.h" #include "base/message_loop.h" -#include "chrome/common/net/gaia/signin.h" #include "chrome/common/deprecated/event_sys.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST @@ -43,16 +41,6 @@ namespace gaia { static const char kGaiaUrl[] = "https://www.google.com:443/accounts/ClientLogin"; -// Use of the following enum is odd. GaiaAuthenticator only looks at -// and DONT_SAVE_CREDENTIALS and SAVE_IN_MEMORY_ONLY (PERSIST_TO_DISK is == to -// SAVE_IN_MEMORY_ONLY for GaiaAuthenticator). - -enum SaveCredentials { - DONT_SAVE_CREDENTIALS, - SAVE_IN_MEMORY_ONLY, - PERSIST_TO_DISK // Saved in both memory and disk -}; - // Error codes from Gaia. These will be set correctly for both Gaia V1 // (/ClientAuth) and V2 (/ClientLogin) enum AuthenticationError { @@ -117,19 +105,16 @@ class GaiaAuthenticator { // token via the respective accessors. Returns a boolean indicating whether // authentication succeeded or not. bool Authenticate(const std::string& user_name, const std::string& password, - SaveCredentials should_save_credentials, const std::string& captcha_token, - const std::string& captcha_value, - SignIn try_first); + const std::string& captcha_value); - bool Authenticate(const std::string& user_name, const std::string& password, - SaveCredentials should_save_credentials, - SignIn try_first); + bool Authenticate(const std::string& user_name, const std::string& password); // Pass the LSID to authenticate with. If the authentication succeeds, you can // retrieve the authetication token via the respective accessors. Returns a // boolean indicating whether authentication succeeded or not. - bool AuthenticateWithLsid(const std::string& lsid, bool long_lived_token); + // Always returns a long lived token. + bool AuthenticateWithLsid(const std::string& lsid); // Resets all stored cookies to their default values. void ResetCredentials(); @@ -141,10 +126,9 @@ class GaiaAuthenticator { // Virtual for testing virtual void RenewAuthToken(const std::string& auth_token); - void SetAuthToken(const std::string& auth_token, SaveCredentials); + void SetAuthToken(const std::string& auth_token); struct AuthResults { - SaveCredentials credentials_saved; std::string email; std::string password; @@ -161,16 +145,8 @@ class GaiaAuthenticator { std::string auth_error_url; std::string captcha_token; std::string captcha_url; - SignIn signin; - - // TODO(skrul): When auth fails, the "signin" field of the results - // struct never gets set, which causes valgrind to complain. Give - // this field a value here so the error is suppressed. It turns - // out that the signin field has only one possible value, so the - // correct fix here would be to to remove it entirely. - AuthResults() : credentials_saved(DONT_SAVE_CREDENTIALS), - auth_error(None), - signin(GMAIL_SIGNIN) { } + + AuthResults() : auth_error(None) {} }; protected: @@ -178,21 +154,17 @@ class GaiaAuthenticator { struct AuthParams { GaiaAuthenticator* authenticator; uint32 request_id; - SaveCredentials should_save_credentials; std::string email; std::string password; std::string captcha_token; std::string captcha_value; - SignIn try_first; }; // mutex_ must be entered before calling this function. AuthParams MakeParams(const std::string& user_name, const std::string& password, - SaveCredentials should_save_credentials, const std::string& captcha_token, - const std::string& captcha_value, - SignIn try_first); + const std::string& captcha_value); // The real Authenticate implementations. bool AuthenticateImpl(const AuthParams& params); @@ -284,8 +256,7 @@ class GaiaAuthenticator { } private: - bool IssueAuthToken(AuthResults* results, const std::string& service_id, - bool long_lived_token); + bool IssueAuthToken(AuthResults* results, const std::string& service_id); // Helper method to parse response when authentication succeeds. void ExtractTokensFrom(const std::string& response, AuthResults* results); diff --git a/chrome/common/net/gaia/gaia_authenticator_unittest.cc b/chrome/common/net/gaia/gaia_authenticator_unittest.cc index 1f9813d..25a92d0 100644 --- a/chrome/common/net/gaia/gaia_authenticator_unittest.cc +++ b/chrome/common/net/gaia/gaia_authenticator_unittest.cc @@ -41,7 +41,7 @@ TEST(GaiaAuthenticatorTest, TestNewlineAtEndOfAuthTokenRemoved) { MessageLoop message_loop; mock_auth.set_message_loop(&message_loop); GaiaAuthenticator::AuthResults results; - EXPECT_TRUE(mock_auth.IssueAuthToken(&results, "sid", true)); + EXPECT_TRUE(mock_auth.IssueAuthToken(&results, "sid")); EXPECT_EQ(0, results.auth_token.compare("body")); } diff --git a/chrome/common/net/gaia/signin.h b/chrome/common/net/gaia/signin.h deleted file mode 100644 index 48f3654..0000000 --- a/chrome/common/net/gaia/signin.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2009 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 CHROME_COMMON_NET_GAIA_SIGNIN_H_ -#define CHROME_COMMON_NET_GAIA_SIGNIN_H_ - -namespace gaia { -// This enumeration is here since we used to support hosted and non-hosted -// accounts, but now only the latter is supported. -enum SignIn { - // The account foo@domain is authenticated as a consumer account. - GMAIL_SIGNIN -}; - -} // namespace gaia -#endif // CHROME_COMMON_NET_GAIA_SIGNIN_H_ - diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index eb6f3f1..e4a9ace 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -248,13 +248,13 @@ void CloudPrintProxyBackend::Core::DoInitializeWithLsid( gaia_auth_for_talk->set_message_loop(MessageLoop::current()); // TODO(sanjeevr): Handle auth failure case. We basically need to disable // cloud print and shutdown. - if (gaia_auth_for_talk->AuthenticateWithLsid(lsid, true)) { + if (gaia_auth_for_talk->AuthenticateWithLsid(lsid)) { scoped_refptr<ServiceGaiaAuthenticator> gaia_auth_for_print = new ServiceGaiaAuthenticator( user_agent, kCloudPrintGaiaServiceId, kGaiaUrl, g_service_process->io_thread()->message_loop_proxy()); gaia_auth_for_print->set_message_loop(MessageLoop::current()); - if (gaia_auth_for_print->AuthenticateWithLsid(lsid, true)) { + if (gaia_auth_for_print->AuthenticateWithLsid(lsid)) { // Let the frontend know that we have authenticated. backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, &Core::NotifyAuthenticated, gaia_auth_for_print->auth_token(), |