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

Side by Side Diff: chrome/browser/chromeos/login/auth/cryptohome_authenticator_unittest.cc

Issue 488633003: Switch CryptohomeAuthenticator from MountAsync() to MountEx() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename TriggerResolveWithHashWithLoginTimeMarker. Created 6 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
« no previous file with comments | « no previous file | chromeos/cryptohome/cryptohome_parameters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/auth/chrome_cryptohome_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" 16 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
18 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" 18 #include "chrome/browser/chromeos/ownership/owner_settings_service.h"
19 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 21 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
23 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" 23 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
25 #include "chrome/test/base/testing_browser_process.h" 25 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "chrome/test/base/testing_profile_manager.h" 27 #include "chrome/test/base/testing_profile_manager.h"
28 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/cryptohome/cryptohome_parameters.h"
30 #include "chromeos/cryptohome/homedir_methods.h"
29 #include "chromeos/cryptohome/mock_async_method_caller.h" 31 #include "chromeos/cryptohome/mock_async_method_caller.h"
32 #include "chromeos/cryptohome/mock_homedir_methods.h"
30 #include "chromeos/cryptohome/system_salt_getter.h" 33 #include "chromeos/cryptohome/system_salt_getter.h"
34 #include "chromeos/dbus/cros_disks_client.h"
31 #include "chromeos/dbus/fake_cryptohome_client.h" 35 #include "chromeos/dbus/fake_cryptohome_client.h"
32 #include "chromeos/dbus/fake_dbus_thread_manager.h" 36 #include "chromeos/dbus/fake_dbus_thread_manager.h"
33 #include "chromeos/login/auth/key.h" 37 #include "chromeos/login/auth/key.h"
34 #include "chromeos/login/auth/mock_auth_status_consumer.h" 38 #include "chromeos/login/auth/mock_auth_status_consumer.h"
35 #include "chromeos/login/auth/mock_url_fetchers.h" 39 #include "chromeos/login/auth/mock_url_fetchers.h"
36 #include "chromeos/login/auth/test_attempt_state.h" 40 #include "chromeos/login/auth/test_attempt_state.h"
37 #include "chromeos/login/auth/user_context.h" 41 #include "chromeos/login/auth/user_context.h"
38 #include "content/public/test/test_browser_thread_bundle.h" 42 #include "content/public/test/test_browser_thread_bundle.h"
39 #include "crypto/nss_util_internal.h" 43 #include "crypto/nss_util_internal.h"
40 #include "crypto/scoped_test_nss_chromeos_user.h" 44 #include "crypto/scoped_test_nss_chromeos_user.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 115
112 } // namespace 116 } // namespace
113 117
114 class CryptohomeAuthenticatorTest : public testing::Test { 118 class CryptohomeAuthenticatorTest : public testing::Test {
115 public: 119 public:
116 CryptohomeAuthenticatorTest() 120 CryptohomeAuthenticatorTest()
117 : user_context_("me@nowhere.org"), 121 : user_context_("me@nowhere.org"),
118 user_manager_(new FakeUserManager()), 122 user_manager_(new FakeUserManager()),
119 user_manager_enabler_(user_manager_), 123 user_manager_enabler_(user_manager_),
120 mock_caller_(NULL), 124 mock_caller_(NULL),
125 mock_homedir_methods_(NULL),
121 owner_key_util_(new MockOwnerKeyUtil) { 126 owner_key_util_(new MockOwnerKeyUtil) {
122 user_context_.SetKey(Key("fakepass")); 127 user_context_.SetKey(Key("fakepass"));
123 user_context_.SetUserIDHash("me_nowhere_com_hash"); 128 user_context_.SetUserIDHash("me_nowhere_com_hash");
124 const user_manager::User* user = 129 const user_manager::User* user =
125 user_manager_->AddUser(user_context_.GetUserID()); 130 user_manager_->AddUser(user_context_.GetUserID());
126 profile_.set_profile_name(user_context_.GetUserID()); 131 profile_.set_profile_name(user_context_.GetUserID());
127 132
128 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); 133 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_);
129 134
130 transformed_key_ = *user_context_.GetKey(); 135 transformed_key_ = *user_context_.GetKey();
131 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, 136 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF,
132 SystemSaltGetter::ConvertRawSaltToHexString( 137 SystemSaltGetter::ConvertRawSaltToHexString(
133 FakeCryptohomeClient::GetStubSystemSalt())); 138 FakeCryptohomeClient::GetStubSystemSalt()));
134 } 139 }
135 140
136 virtual ~CryptohomeAuthenticatorTest() {} 141 virtual ~CryptohomeAuthenticatorTest() {}
137 142
138 virtual void SetUp() { 143 virtual void SetUp() {
139 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); 144 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager);
140 145
141 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 146 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
142 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 147 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
148 mock_homedir_methods_ = new cryptohome::MockHomedirMethods;
149 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
150 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_);
143 151
144 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; 152 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
145 fake_cryptohome_client_ = new FakeCryptohomeClient; 153 fake_cryptohome_client_ = new FakeCryptohomeClient;
146 fake_dbus_thread_manager->SetCryptohomeClient( 154 fake_dbus_thread_manager->SetCryptohomeClient(
147 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 155 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_));
148 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); 156 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
149 157
150 SystemSaltGetter::Initialize(); 158 SystemSaltGetter::Initialize();
151 159
152 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_); 160 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_);
153 161
154 auth_ = new ChromeCryptohomeAuthenticator(&consumer_); 162 auth_ = new ChromeCryptohomeAuthenticator(&consumer_);
155 state_.reset(new TestAttemptState(user_context_, false)); 163 state_.reset(new TestAttemptState(user_context_, false));
156 } 164 }
157 165
158 // Tears down the test fixture. 166 // Tears down the test fixture.
159 virtual void TearDown() { 167 virtual void TearDown() {
160 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); 168 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL);
161 SystemSaltGetter::Shutdown(); 169 SystemSaltGetter::Shutdown();
162 DBusThreadManager::Shutdown(); 170 DBusThreadManager::Shutdown();
163 171
164 cryptohome::AsyncMethodCaller::Shutdown(); 172 cryptohome::AsyncMethodCaller::Shutdown();
165 mock_caller_ = NULL; 173 mock_caller_ = NULL;
174 cryptohome::HomedirMethods::Shutdown();
175 mock_homedir_methods_ = NULL;
166 } 176 }
167 177
168 base::FilePath PopulateTempFile(const char* data, int data_len) { 178 base::FilePath PopulateTempFile(const char* data, int data_len) {
169 base::FilePath out; 179 base::FilePath out;
170 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out); 180 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out);
171 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); 181 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL));
172 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len); 182 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len);
173 EXPECT_TRUE(base::CloseFile(tmp_file)); 183 EXPECT_TRUE(base::CloseFile(tmp_file));
174 return out; 184 return out;
175 } 185 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 269
260 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 270 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
261 ScopedTestCrosSettings test_cros_settings_; 271 ScopedTestCrosSettings test_cros_settings_;
262 272
263 TestingProfile profile_; 273 TestingProfile profile_;
264 scoped_ptr<TestingProfileManager> profile_manager_; 274 scoped_ptr<TestingProfileManager> profile_manager_;
265 FakeUserManager* user_manager_; 275 FakeUserManager* user_manager_;
266 ScopedUserManagerEnabler user_manager_enabler_; 276 ScopedUserManagerEnabler user_manager_enabler_;
267 277
268 cryptohome::MockAsyncMethodCaller* mock_caller_; 278 cryptohome::MockAsyncMethodCaller* mock_caller_;
279 cryptohome::MockHomedirMethods* mock_homedir_methods_;
269 280
270 MockAuthStatusConsumer consumer_; 281 MockAuthStatusConsumer consumer_;
271 282
272 scoped_refptr<CryptohomeAuthenticator> auth_; 283 scoped_refptr<CryptohomeAuthenticator> auth_;
273 scoped_ptr<TestAttemptState> state_; 284 scoped_ptr<TestAttemptState> state_;
274 FakeCryptohomeClient* fake_cryptohome_client_; 285 FakeCryptohomeClient* fake_cryptohome_client_;
275 286
276 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; 287 scoped_refptr<MockOwnerKeyUtil> owner_key_util_;
277 }; 288 };
278 289
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 535 }
525 536
526 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { 537 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) {
527 UserContext expected_user_context(user_context_); 538 UserContext expected_user_context(user_context_);
528 expected_user_context.SetUserIDHash( 539 expected_user_context.SetUserIDHash(
529 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 540 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
530 ExpectLoginSuccess(expected_user_context); 541 ExpectLoginSuccess(expected_user_context);
531 FailOnLoginFailure(); 542 FailOnLoginFailure();
532 543
533 // Set up mock async method caller to respond successfully to a cryptohome 544 // Set up mock async method caller to respond successfully to a cryptohome
534 // remove attempt and a cryptohome create attempt (indicated by the 545 // remove attempt.
535 // |CREATE_IF_MISSING| flag to AsyncMount).
536 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 546 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
537 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) 547 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
538 .Times(1) 548 .Times(1)
539 .RetiresOnSaturation(); 549 .RetiresOnSaturation();
540 EXPECT_CALL(*mock_caller_, 550
541 AsyncMount(user_context_.GetUserID(), 551 // Set up mock homedir methods to respond successfully to a cryptohome create
542 transformed_key_.GetSecret(), 552 // attempt.
543 cryptohome::CREATE_IF_MISSING, 553 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
544 _)) 554 std::string(),
545 .Times(1) 555 cryptohome::PRIV_DEFAULT);
546 .RetiresOnSaturation(); 556 cryptohome::MountParameters mount(false /* ephemeral */);
547 EXPECT_CALL(*mock_caller_, 557 mount.create_keys.push_back(cryptohome::KeyDefinition(
548 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 558 transformed_key_.GetSecret(),
549 .Times(1) 559 "gaia",
550 .RetiresOnSaturation(); 560 cryptohome::PRIV_DEFAULT));
561 EXPECT_CALL(*mock_homedir_methods_,
562 MountEx(cryptohome::Identification(user_context_.GetUserID()),
563 cryptohome::Authorization(auth_key),
564 mount,
565 _));
Darren Krahn 2014/08/26 17:59:47 optional: Multiple calls to MountEx should be avoi
bartfab (slow) 2014/08/26 18:10:22 Done.
551 566
552 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 567 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
553 SetAttemptState(auth_.get(), state_.release()); 568 SetAttemptState(auth_.get(), state_.release());
554 569
555 auth_->ResyncEncryptedData(); 570 auth_->ResyncEncryptedData();
556 base::MessageLoop::current()->Run(); 571 base::MessageLoop::current()->Run();
557 } 572 }
558 573
559 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { 574 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) {
560 FailOnLoginSuccess(); 575 FailOnLoginSuccess();
(...skipping 30 matching lines...) Expand all
591 FailOnLoginFailure(); 606 FailOnLoginFailure();
592 607
593 // Set up mock async method caller to respond successfully to a key migration. 608 // Set up mock async method caller to respond successfully to a key migration.
594 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 609 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
595 EXPECT_CALL( 610 EXPECT_CALL(
596 *mock_caller_, 611 *mock_caller_,
597 AsyncMigrateKey( 612 AsyncMigrateKey(
598 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) 613 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _))
599 .Times(1) 614 .Times(1)
600 .RetiresOnSaturation(); 615 .RetiresOnSaturation();
601 EXPECT_CALL(*mock_caller_, 616
602 AsyncMount(user_context_.GetUserID(), 617 // Set up mock homedir methods to respond successfully to a cryptohome mount
603 transformed_key_.GetSecret(), 618 // attempt.
604 cryptohome::MOUNT_FLAGS_NONE, 619 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
605 _)) 620 std::string(),
606 .Times(1) 621 cryptohome::PRIV_DEFAULT);
607 .RetiresOnSaturation(); 622 EXPECT_CALL(*mock_homedir_methods_,
608 EXPECT_CALL(*mock_caller_, 623 MountEx(cryptohome::Identification(user_context_.GetUserID()),
609 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 624 cryptohome::Authorization(auth_key),
610 .Times(1) 625 cryptohome::MountParameters(false /* ephemeral */),
611 .RetiresOnSaturation(); 626 _));
612 627
613 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 628 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
614 SetAttemptState(auth_.get(), state_.release()); 629 SetAttemptState(auth_.get(), state_.release());
615 630
616 auth_->RecoverEncryptedData(std::string()); 631 auth_->RecoverEncryptedData(std::string());
617 base::MessageLoop::current()->Run(); 632 base::MessageLoop::current()->Run();
618 } 633 }
619 634
620 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { 635 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) {
621 FailOnLoginSuccess(); 636 FailOnLoginSuccess();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 SetAndResolveState(auth_.get(), state_.release())); 676 SetAndResolveState(auth_.get(), state_.release()));
662 } 677 }
663 678
664 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { 679 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) {
665 UserContext expected_user_context(user_context_); 680 UserContext expected_user_context(user_context_);
666 expected_user_context.SetUserIDHash( 681 expected_user_context.SetUserIDHash(
667 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 682 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
668 ExpectLoginSuccess(expected_user_context); 683 ExpectLoginSuccess(expected_user_context);
669 FailOnLoginFailure(); 684 FailOnLoginFailure();
670 685
671 // Set up mock async method caller to respond successfully to a cryptohome 686 // Set up mock homedir methods to respond successfully to a cryptohome create
672 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). 687 // attempt.
673 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 688 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
674 EXPECT_CALL(*mock_caller_, 689 std::string(),
675 AsyncMount(user_context_.GetUserID(), 690 cryptohome::PRIV_DEFAULT);
676 transformed_key_.GetSecret(), 691 cryptohome::MountParameters mount(false /* ephemeral */);
677 cryptohome::CREATE_IF_MISSING, 692 mount.create_keys.push_back(cryptohome::KeyDefinition(
678 _)) 693 transformed_key_.GetSecret(),
679 .Times(1) 694 "gaia",
680 .RetiresOnSaturation(); 695 cryptohome::PRIV_DEFAULT));
681 EXPECT_CALL(*mock_caller_, 696 EXPECT_CALL(*mock_homedir_methods_,
682 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 697 MountEx(cryptohome::Identification(user_context_.GetUserID()),
683 .Times(1) 698 cryptohome::Authorization(auth_key),
684 .RetiresOnSaturation(); 699 mount,
700 _));
685 701
686 // Set up state as though a cryptohome mount attempt has occurred 702 // Set up state as though a cryptohome mount attempt has occurred
687 // and been rejected because the user doesn't exist; additionally, 703 // and been rejected because the user doesn't exist; additionally,
688 // an online auth attempt has completed successfully. 704 // an online auth attempt has completed successfully.
689 state_->PresetCryptohomeStatus(false, 705 state_->PresetCryptohomeStatus(false,
690 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 706 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
691 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 707 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
692 SetAttemptState(auth_.get(), state_.release()); 708 SetAttemptState(auth_.get(), state_.release());
693 709
694 RunResolve(auth_.get()); 710 RunResolve(auth_.get());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 744 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
729 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) 745 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
730 .Times(1) 746 .Times(1)
731 .RetiresOnSaturation(); 747 .RetiresOnSaturation();
732 748
733 auth_->AuthenticateToUnlock(user_context_); 749 auth_->AuthenticateToUnlock(user_context_);
734 base::MessageLoop::current()->Run(); 750 base::MessageLoop::current()->Run();
735 } 751 }
736 752
737 } // namespace chromeos 753 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/cryptohome/cryptohome_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698