Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: chrome/browser/chromeos/login/parallel_authenticator_unittest.cc

Issue 23684033: Fix device policy recovery on CrOS login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 10 #include "base/file_util.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h" 16 #include "chrome/browser/chromeos/login/mock_login_status_consumer.h"
16 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 17 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
17 #include "chrome/browser/chromeos/login/mock_user_manager.h" 18 #include "chrome/browser/chromeos/login/mock_user_manager.h"
18 #include "chrome/browser/chromeos/login/test_attempt_state.h" 19 #include "chrome/browser/chromeos/login/test_attempt_state.h"
19 #include "chrome/browser/chromeos/login/user.h" 20 #include "chrome/browser/chromeos/login/user.h"
20 #include "chrome/browser/chromeos/login/user_manager.h" 21 #include "chrome/browser/chromeos/login/user_manager.h"
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 22 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 23 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
23 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
24 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "chromeos/chromeos_switches.h"
25 #include "chromeos/cryptohome/mock_async_method_caller.h" 27 #include "chromeos/cryptohome/mock_async_method_caller.h"
26 #include "chromeos/cryptohome/mock_cryptohome_library.h" 28 #include "chromeos/cryptohome/mock_cryptohome_library.h"
27 #include "chromeos/dbus/fake_cryptohome_client.h" 29 #include "chromeos/dbus/fake_cryptohome_client.h"
28 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" 30 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "google_apis/gaia/mock_url_fetcher_factory.h" 32 #include "google_apis/gaia/mock_url_fetcher_factory.h"
31 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
32 #include "net/url_request/url_request_status.h" 34 #include "net/url_request/url_request_status.h"
33 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 13 matching lines...) Expand all
48 : OnlineAttempt(state, resolver) { 50 : OnlineAttempt(state, resolver) {
49 } 51 }
50 }; 52 };
51 53
52 class ParallelAuthenticatorTest : public testing::Test { 54 class ParallelAuthenticatorTest : public testing::Test {
53 public: 55 public:
54 ParallelAuthenticatorTest() 56 ParallelAuthenticatorTest()
55 : username_("me@nowhere.org"), 57 : username_("me@nowhere.org"),
56 password_("fakepass"), 58 password_("fakepass"),
57 hash_ascii_("0a010000000000a0" + std::string(16, '0')), 59 hash_ascii_("0a010000000000a0" + std::string(16, '0')),
58 user_manager_enabler_(new MockUserManager) { 60 user_manager_enabler_(new MockUserManager),
61 mock_caller_(NULL) {
59 } 62 }
60 63
61 virtual ~ParallelAuthenticatorTest() { 64 virtual ~ParallelAuthenticatorTest() {
62 DCHECK(!mock_caller_); 65 DCHECK(!mock_caller_);
63 } 66 }
64 67
65 virtual void SetUp() { 68 virtual void SetUp() {
69 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager);
70
66 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 71 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
67 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 72 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
68 73
69 mock_cryptohome_library_ .reset(new MockCryptohomeLibrary()); 74 mock_cryptohome_library_ .reset(new MockCryptohomeLibrary());
70 CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get()); 75 CryptohomeLibrary::SetForTest(mock_cryptohome_library_.get());
71 76
72 auth_ = new ParallelAuthenticator(&consumer_); 77 auth_ = new ParallelAuthenticator(&consumer_);
73 state_.reset(new TestAttemptState(UserContext(username_, 78 state_.reset(new TestAttemptState(UserContext(username_,
74 password_, 79 password_,
75 std::string()), 80 std::string()),
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 SetOwnerState(false, false); 325 SetOwnerState(false, false);
321 // Remove the real DeviceSettingsProvider and replace it with a stub. 326 // Remove the real DeviceSettingsProvider and replace it with a stub.
322 device_settings_provider = 327 device_settings_provider =
323 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); 328 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo);
324 EXPECT_TRUE(device_settings_provider != NULL); 329 EXPECT_TRUE(device_settings_provider != NULL);
325 EXPECT_TRUE( 330 EXPECT_TRUE(
326 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); 331 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider));
327 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); 332 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider);
328 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); 333 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true);
329 334
335 // Initialize login state for this test to verify the login state is changed
336 // to SAFE_MODE.
337 LoginState::Initialize();
338
330 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 339 EXPECT_EQ(ParallelAuthenticator::CONTINUE,
331 SetAndResolveState(auth_.get(), state_.release())); 340 SetAndResolveState(auth_.get(), state_.release()));
332 // Let the owner verification run. 341 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
342
343 // Simulate certificates load event. The exact certificates loaded are not
344 // actually used by the DeviceSettingsService, so it is OK to pass an empty
345 // list.
346 DeviceSettingsService::Get()->OnCertificatesLoaded(net::CertificateList(),
347 true);
348 // Flush all the pending operations. The operations should induce an owner
349 // verification.
333 device_settings_test_helper_.Flush(); 350 device_settings_test_helper_.Flush();
334 // and test that the mount has succeeded. 351 // and test that the mount has succeeded.
335 state_.reset(new TestAttemptState(UserContext(username_, 352 state_.reset(new TestAttemptState(UserContext(username_,
336 password_, 353 password_,
337 std::string()), 354 std::string()),
338 hash_ascii_, 355 hash_ascii_,
339 "", 356 "",
340 "", 357 "",
341 User::USER_TYPE_REGULAR, 358 User::USER_TYPE_REGULAR,
342 false)); 359 false));
343 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 360 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
344 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 361 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
345 SetAndResolveState(auth_.get(), state_.release())); 362 SetAndResolveState(auth_.get(), state_.release()));
346 363
364 // Unset global objects used by this test.
365 LoginState::Shutdown();
347 EXPECT_TRUE( 366 EXPECT_TRUE(
348 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 367 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
349 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 368 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
350 DBusThreadManager::Get()->Shutdown(); 369 DBusThreadManager::Get()->Shutdown();
351 } 370 }
352 371
353 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { 372 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) {
354 FailOnLoginSuccess(); 373 FailOnLoginSuccess();
355 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 374 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME));
356 375
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 .WillOnce(Return(std::string())) 652 .WillOnce(Return(std::string()))
634 .RetiresOnSaturation(); 653 .RetiresOnSaturation();
635 654
636 auth_->AuthenticateToUnlock(UserContext(username_, 655 auth_->AuthenticateToUnlock(UserContext(username_,
637 std::string(), 656 std::string(),
638 std::string())); 657 std::string()));
639 base::MessageLoop::current()->Run(); 658 base::MessageLoop::current()->Run();
640 } 659 }
641 660
642 } // namespace chromeos 661 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/parallel_authenticator.cc ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698