| Index: chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
|
| diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
|
| index 26f91675fa6e1233e4f1e18924ba609530aba617..39138f1301398ccce03f769258609496a9cbaeff 100644
|
| --- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
|
| +++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc
|
| @@ -18,10 +18,15 @@
|
| #include "chrome/browser/chromeos/cros/cros_library.h"
|
| #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
|
| #include "chrome/browser/chromeos/cros/mock_library_loader.h"
|
| +#include "chrome/browser/chromeos/cros_settings.h"
|
| #include "chrome/browser/chromeos/cryptohome/mock_async_method_caller.h"
|
| +#include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h"
|
| +#include "chrome/browser/chromeos/dbus/mock_cryptohome_client.h"
|
| #include "chrome/browser/chromeos/login/mock_login_status_consumer.h"
|
| #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
|
| +#include "chrome/browser/chromeos/login/mock_user_manager.h"
|
| #include "chrome/browser/chromeos/login/test_attempt_state.h"
|
| +#include "chrome/browser/chromeos/stub_cros_settings_provider.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/net/gaia/mock_url_fetcher_factory.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| @@ -43,7 +48,7 @@ using ::testing::AnyNumber;
|
| using ::testing::DoAll;
|
| using ::testing::Invoke;
|
| using ::testing::Return;
|
| -using ::testing::SetArgumentPointee;
|
| +using ::testing::SetArgPointee;
|
| using ::testing::_;
|
|
|
| namespace chromeos {
|
| @@ -85,6 +90,7 @@ class ParallelAuthenticatorTest : public testing::Test {
|
| ParallelAuthenticatorTest()
|
| : message_loop_(MessageLoop::TYPE_UI),
|
| ui_thread_(BrowserThread::UI, &message_loop_),
|
| + file_thread_(BrowserThread::FILE, &message_loop_),
|
| io_thread_(BrowserThread::IO),
|
| username_("me@nowhere.org"),
|
| password_("fakepass") {
|
| @@ -115,6 +121,11 @@ class ParallelAuthenticatorTest : public testing::Test {
|
| test_api->SetCryptohomeLibrary(mock_library_, true);
|
| io_thread_.Start();
|
|
|
| + mock_user_manager_ = new MockUserManager();
|
| + UserManager::Set(mock_user_manager_);
|
| + EXPECT_CALL(*mock_user_manager_, LoadKeyStore())
|
| + .Times(AnyNumber());
|
| +
|
| auth_ = new ParallelAuthenticator(&consumer_);
|
| auth_->set_using_oauth(false);
|
| state_.reset(new TestAttemptState(username_,
|
| @@ -218,12 +229,17 @@ class ParallelAuthenticatorTest : public testing::Test {
|
| auth->set_attempt_state(state);
|
| }
|
|
|
| + void SetOwnerState(bool owner_check_finished, bool check_result) {
|
| + auth_->SetOwnerState(owner_check_finished, check_result);
|
| + }
|
| +
|
| void FakeOnlineAttempt() {
|
| auth_->set_online_attempt(new TestOnlineAttempt(state_.get(), auth_.get()));
|
| }
|
|
|
| MessageLoop message_loop_;
|
| content::TestBrowserThread ui_thread_;
|
| + content::TestBrowserThread file_thread_;
|
| content::TestBrowserThread io_thread_;
|
|
|
| std::string username_;
|
| @@ -236,6 +252,7 @@ class ParallelAuthenticatorTest : public testing::Test {
|
| // Mocks, destroyed by CrosLibrary class.
|
| MockCryptohomeLibrary* mock_library_;
|
| MockLibraryLoader* loader_;
|
| + MockUserManager* mock_user_manager_;
|
|
|
| cryptohome::MockAsyncMethodCaller* mock_caller_;
|
|
|
| @@ -310,6 +327,98 @@ TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) {
|
| EXPECT_TRUE(checker->Run());
|
| }
|
|
|
| +TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) {
|
| + // Set up state as though a cryptohome mount attempt has occurred
|
| + // and succeeded but we are in safe mode and the current user is not owner.
|
| + // This is a high level test to verify the proper transitioning in this mode
|
| + // only. It is not testing that we properly verify that the user is an owner
|
| + // or that we really are in "safe-mode".
|
| + state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
|
| + SetOwnerState(true, false);
|
| +
|
| + scoped_refptr<ResolveChecker> checker(
|
| + new ResolveChecker(state_.release(),
|
| + auth_.get(),
|
| + ParallelAuthenticator::OWNER_REQUIRED));
|
| + EXPECT_TRUE(checker->Run());
|
| +}
|
| +
|
| +TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
|
| + // Set up state as though a cryptohome mount attempt has occurred
|
| + // and succeeded but we are in safe mode and the current user is not owner.
|
| + // This test will check that the "safe-mode" policy is not set and will let
|
| + // the mount finish successfully.
|
| + state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
|
| + SetOwnerState(false, false);
|
| +
|
| + scoped_refptr<ResolveChecker> checker(
|
| + new ResolveChecker(state_.release(),
|
| + auth_.get(),
|
| + ParallelAuthenticator::CONTINUE));
|
| + EXPECT_TRUE(checker->Run());
|
| + // Let the owner verification run on the FILE thread...
|
| + message_loop_.RunAllPending();
|
| + // and test that the mount has succeeded.
|
| + state_.reset(new TestAttemptState(username_,
|
| + password_,
|
| + hash_ascii_,
|
| + "",
|
| + "",
|
| + false));
|
| + state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
|
| + checker = new ResolveChecker(state_.release(),
|
| + auth_.get(),
|
| + ParallelAuthenticator::OFFLINE_LOGIN);
|
| + EXPECT_TRUE(checker->Run());
|
| +}
|
| +
|
| +TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
|
| + scoped_ptr<MockDBusThreadManager> mock_dbus_thread_manager(
|
| + new MockDBusThreadManager);
|
| + DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager.get());
|
| + EXPECT_CALL(*mock_dbus_thread_manager->mock_cryptohome_client(), Unmount(_))
|
| + .WillOnce(DoAll(SetArgPointee<0>(true), Return(true)));
|
| +
|
| + CrosSettingsProvider* device_settings_provider;
|
| + StubCrosSettingsProvider stub_settings_provider;
|
| + // Set up state as though a cryptohome mount attempt has occurred
|
| + // and succeeded but we are in safe mode and the current user is not owner.
|
| + state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
|
| + SetOwnerState(false, false);
|
| + // Remove the real DeviceSettingsProvider and replace it with a stub.
|
| + device_settings_provider =
|
| + CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo);
|
| + EXPECT_TRUE(device_settings_provider != NULL);
|
| + EXPECT_TRUE(
|
| + CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
|
| + CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
|
| + CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
|
| +
|
| + scoped_refptr<ResolveChecker> checker(
|
| + new ResolveChecker(state_.release(),
|
| + auth_.get(),
|
| + ParallelAuthenticator::CONTINUE));
|
| + EXPECT_TRUE(checker->Run());
|
| + // Let the owner verification run on the FILE thread...
|
| + message_loop_.RunAllPending();
|
| + // and test that the mount has succeeded.
|
| + state_.reset(new TestAttemptState(username_,
|
| + password_,
|
| + hash_ascii_,
|
| + "",
|
| + "",
|
| + false));
|
| + state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
|
| + checker = new ResolveChecker(state_.release(),
|
| + auth_.get(),
|
| + ParallelAuthenticator::OWNER_REQUIRED);
|
| + EXPECT_TRUE(checker->Run());
|
| +
|
| + EXPECT_TRUE(
|
| + CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
|
| + CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
|
| +}
|
| +
|
| TEST_F(ParallelAuthenticatorTest, DriveFailedMount) {
|
| FailOnLoginSuccess();
|
| ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME));
|
|
|