| 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 "chrome/browser/chromeos/login/parallel_authenticator.h" | 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class ParallelAuthenticatorTest : public testing::Test { | 46 class ParallelAuthenticatorTest : public testing::Test { |
| 47 public: | 47 public: |
| 48 ParallelAuthenticatorTest() | 48 ParallelAuthenticatorTest() |
| 49 : username_("me@nowhere.org"), | 49 : username_("me@nowhere.org"), |
| 50 password_("fakepass"), | 50 password_("fakepass"), |
| 51 hash_ascii_(ParallelAuthenticator::HashPassword( | 51 hash_ascii_(ParallelAuthenticator::HashPassword( |
| 52 password_, | 52 password_, |
| 53 SystemSaltGetter::ConvertRawSaltToHexString( | 53 SystemSaltGetter::ConvertRawSaltToHexString( |
| 54 FakeCryptohomeClient::GetStubSystemSalt()))), | 54 FakeCryptohomeClient::GetStubSystemSalt()))), |
| 55 user_manager_enabler_(new MockUserManager), | 55 user_manager_enabler_(new MockUserManager), |
| 56 mock_caller_(NULL), | 56 mock_caller_(NULL) { |
| 57 fake_dbus_thread_manager_(new FakeDBusThreadManager) { | |
| 58 } | 57 } |
| 59 | 58 |
| 60 virtual ~ParallelAuthenticatorTest() { | 59 virtual ~ParallelAuthenticatorTest() { |
| 61 DCHECK(!mock_caller_); | 60 DCHECK(!mock_caller_); |
| 62 } | 61 } |
| 63 | 62 |
| 64 virtual void SetUp() { | 63 virtual void SetUp() { |
| 65 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); | 64 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); |
| 66 | 65 |
| 67 mock_caller_ = new cryptohome::MockAsyncMethodCaller; | 66 mock_caller_ = new cryptohome::MockAsyncMethodCaller; |
| 68 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); | 67 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); |
| 69 | 68 |
| 70 // Ownership of fake_dbus_thread_manager_ is taken. | 69 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 71 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager_); | 70 fake_cryptohome_client_ = new FakeCryptohomeClient; |
| 71 fake_dbus_thread_manager->SetCryptohomeClient( |
| 72 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); |
| 73 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); |
| 74 |
| 72 SystemSaltGetter::Initialize(); | 75 SystemSaltGetter::Initialize(); |
| 73 | 76 |
| 74 auth_ = new ParallelAuthenticator(&consumer_); | 77 auth_ = new ParallelAuthenticator(&consumer_); |
| 75 state_.reset(new TestAttemptState(UserContext(username_, | 78 state_.reset(new TestAttemptState(UserContext(username_, |
| 76 password_, | 79 password_, |
| 77 std::string()), | 80 std::string()), |
| 78 "", | 81 "", |
| 79 "", | 82 "", |
| 80 User::USER_TYPE_REGULAR, | 83 User::USER_TYPE_REGULAR, |
| 81 false)); | 84 false)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | 196 ScopedDeviceSettingsTestHelper device_settings_test_helper_; |
| 194 ScopedTestCrosSettings test_cros_settings_; | 197 ScopedTestCrosSettings test_cros_settings_; |
| 195 | 198 |
| 196 ScopedUserManagerEnabler user_manager_enabler_; | 199 ScopedUserManagerEnabler user_manager_enabler_; |
| 197 | 200 |
| 198 cryptohome::MockAsyncMethodCaller* mock_caller_; | 201 cryptohome::MockAsyncMethodCaller* mock_caller_; |
| 199 | 202 |
| 200 MockConsumer consumer_; | 203 MockConsumer consumer_; |
| 201 scoped_refptr<ParallelAuthenticator> auth_; | 204 scoped_refptr<ParallelAuthenticator> auth_; |
| 202 scoped_ptr<TestAttemptState> state_; | 205 scoped_ptr<TestAttemptState> state_; |
| 203 FakeDBusThreadManager* fake_dbus_thread_manager_; | 206 FakeCryptohomeClient* fake_cryptohome_client_; |
| 204 }; | 207 }; |
| 205 | 208 |
| 206 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { | 209 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { |
| 207 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, | 210 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, |
| 208 password_, | 211 password_, |
| 209 std::string(), | 212 std::string(), |
| 210 username_hash_, | 213 username_hash_, |
| 211 true /* using oauth */))) | 214 true /* using oauth */))) |
| 212 .Times(1) | 215 .Times(1) |
| 213 .RetiresOnSaturation(); | 216 .RetiresOnSaturation(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 285 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
| 283 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, | 286 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, |
| 284 SetAndResolveState(auth_.get(), state_.release())); | 287 SetAndResolveState(auth_.get(), state_.release())); |
| 285 } | 288 } |
| 286 | 289 |
| 287 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { | 290 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { |
| 288 FailOnLoginSuccess(); // Set failing on success as the default... | 291 FailOnLoginSuccess(); // Set failing on success as the default... |
| 289 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); | 292 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); |
| 290 ExpectLoginFailure(failure); | 293 ExpectLoginFailure(failure); |
| 291 | 294 |
| 292 FakeCryptohomeClient* fake_cryptohome_client = | 295 fake_cryptohome_client_->set_unmount_result(true); |
| 293 fake_dbus_thread_manager_->fake_cryptohome_client(); | |
| 294 fake_cryptohome_client->set_unmount_result(true); | |
| 295 | 296 |
| 296 CrosSettingsProvider* device_settings_provider; | 297 CrosSettingsProvider* device_settings_provider; |
| 297 StubCrosSettingsProvider stub_settings_provider; | 298 StubCrosSettingsProvider stub_settings_provider; |
| 298 // Set up state as though a cryptohome mount attempt has occurred | 299 // Set up state as though a cryptohome mount attempt has occurred |
| 299 // and succeeded but we are in safe mode and the current user is not owner. | 300 // and succeeded but we are in safe mode and the current user is not owner. |
| 300 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 301 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
| 301 SetOwnerState(false, false); | 302 SetOwnerState(false, false); |
| 302 // Remove the real DeviceSettingsProvider and replace it with a stub. | 303 // Remove the real DeviceSettingsProvider and replace it with a stub. |
| 303 device_settings_provider = | 304 device_settings_provider = |
| 304 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); | 305 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 .Times(1) | 605 .Times(1) |
| 605 .RetiresOnSaturation(); | 606 .RetiresOnSaturation(); |
| 606 | 607 |
| 607 auth_->AuthenticateToUnlock(UserContext(username_, | 608 auth_->AuthenticateToUnlock(UserContext(username_, |
| 608 std::string(), | 609 std::string(), |
| 609 std::string())); | 610 std::string())); |
| 610 base::MessageLoop::current()->Run(); | 611 base::MessageLoop::current()->Run(); |
| 611 } | 612 } |
| 612 | 613 |
| 613 } // namespace chromeos | 614 } // namespace chromeos |
| OLD | NEW |