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

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: Rebased. 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/OWNERS » ('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/dbus_thread_manager.h" 35 #include "chromeos/dbus/dbus_thread_manager.h"
32 #include "chromeos/dbus/fake_cryptohome_client.h" 36 #include "chromeos/dbus/fake_cryptohome_client.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 fake_cryptohome_client_ = new FakeCryptohomeClient; 152 fake_cryptohome_client_ = new FakeCryptohomeClient;
145 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( 153 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient(
146 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 154 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_));
147 155
148 SystemSaltGetter::Initialize(); 156 SystemSaltGetter::Initialize();
149 157
150 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_); 158 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_);
151 159
152 auth_ = new ChromeCryptohomeAuthenticator(&consumer_); 160 auth_ = new ChromeCryptohomeAuthenticator(&consumer_);
153 state_.reset(new TestAttemptState(user_context_, false)); 161 state_.reset(new TestAttemptState(user_context_, false));
154 } 162 }
155 163
156 // Tears down the test fixture. 164 // Tears down the test fixture.
157 virtual void TearDown() { 165 virtual void TearDown() {
158 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); 166 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL);
159 SystemSaltGetter::Shutdown(); 167 SystemSaltGetter::Shutdown();
160 DBusThreadManager::Shutdown(); 168 DBusThreadManager::Shutdown();
161 169
162 cryptohome::AsyncMethodCaller::Shutdown(); 170 cryptohome::AsyncMethodCaller::Shutdown();
163 mock_caller_ = NULL; 171 mock_caller_ = NULL;
172 cryptohome::HomedirMethods::Shutdown();
173 mock_homedir_methods_ = NULL;
164 } 174 }
165 175
166 base::FilePath PopulateTempFile(const char* data, int data_len) { 176 base::FilePath PopulateTempFile(const char* data, int data_len) {
167 base::FilePath out; 177 base::FilePath out;
168 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out); 178 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out);
169 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); 179 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL));
170 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len); 180 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len);
171 EXPECT_TRUE(base::CloseFile(tmp_file)); 181 EXPECT_TRUE(base::CloseFile(tmp_file));
172 return out; 182 return out;
173 } 183 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 267
258 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 268 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
259 ScopedTestCrosSettings test_cros_settings_; 269 ScopedTestCrosSettings test_cros_settings_;
260 270
261 TestingProfile profile_; 271 TestingProfile profile_;
262 scoped_ptr<TestingProfileManager> profile_manager_; 272 scoped_ptr<TestingProfileManager> profile_manager_;
263 FakeUserManager* user_manager_; 273 FakeUserManager* user_manager_;
264 ScopedUserManagerEnabler user_manager_enabler_; 274 ScopedUserManagerEnabler user_manager_enabler_;
265 275
266 cryptohome::MockAsyncMethodCaller* mock_caller_; 276 cryptohome::MockAsyncMethodCaller* mock_caller_;
277 cryptohome::MockHomedirMethods* mock_homedir_methods_;
267 278
268 MockAuthStatusConsumer consumer_; 279 MockAuthStatusConsumer consumer_;
269 280
270 scoped_refptr<CryptohomeAuthenticator> auth_; 281 scoped_refptr<CryptohomeAuthenticator> auth_;
271 scoped_ptr<TestAttemptState> state_; 282 scoped_ptr<TestAttemptState> state_;
272 FakeCryptohomeClient* fake_cryptohome_client_; 283 FakeCryptohomeClient* fake_cryptohome_client_;
273 284
274 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; 285 scoped_refptr<MockOwnerKeyUtil> owner_key_util_;
275 }; 286 };
276 287
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 533 }
523 534
524 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { 535 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) {
525 UserContext expected_user_context(user_context_); 536 UserContext expected_user_context(user_context_);
526 expected_user_context.SetUserIDHash( 537 expected_user_context.SetUserIDHash(
527 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 538 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
528 ExpectLoginSuccess(expected_user_context); 539 ExpectLoginSuccess(expected_user_context);
529 FailOnLoginFailure(); 540 FailOnLoginFailure();
530 541
531 // Set up mock async method caller to respond successfully to a cryptohome 542 // Set up mock async method caller to respond successfully to a cryptohome
532 // remove attempt and a cryptohome create attempt (indicated by the 543 // remove attempt.
533 // |CREATE_IF_MISSING| flag to AsyncMount).
534 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 544 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
535 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) 545 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
536 .Times(1) 546 .Times(1)
537 .RetiresOnSaturation(); 547 .RetiresOnSaturation();
538 EXPECT_CALL(*mock_caller_, 548
539 AsyncMount(user_context_.GetUserID(), 549 // Set up mock homedir methods to respond successfully to a cryptohome create
540 transformed_key_.GetSecret(), 550 // attempt.
541 cryptohome::CREATE_IF_MISSING, 551 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
542 _)) 552 std::string(),
543 .Times(1) 553 cryptohome::PRIV_DEFAULT);
544 .RetiresOnSaturation(); 554 cryptohome::MountParameters mount(false /* ephemeral */);
545 EXPECT_CALL(*mock_caller_, 555 mount.create_keys.push_back(cryptohome::KeyDefinition(
546 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 556 transformed_key_.GetSecret(),
547 .Times(1) 557 "gaia",
548 .RetiresOnSaturation(); 558 cryptohome::PRIV_DEFAULT));
559 EXPECT_CALL(*mock_homedir_methods_,
560 MountEx(cryptohome::Identification(user_context_.GetUserID()),
561 cryptohome::Authorization(auth_key),
562 mount,
563 _))
564 .Times(1);
549 565
550 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 566 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
551 SetAttemptState(auth_.get(), state_.release()); 567 SetAttemptState(auth_.get(), state_.release());
552 568
553 auth_->ResyncEncryptedData(); 569 auth_->ResyncEncryptedData();
554 base::MessageLoop::current()->Run(); 570 base::MessageLoop::current()->Run();
555 } 571 }
556 572
557 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { 573 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) {
558 FailOnLoginSuccess(); 574 FailOnLoginSuccess();
(...skipping 30 matching lines...) Expand all
589 FailOnLoginFailure(); 605 FailOnLoginFailure();
590 606
591 // Set up mock async method caller to respond successfully to a key migration. 607 // Set up mock async method caller to respond successfully to a key migration.
592 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 608 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
593 EXPECT_CALL( 609 EXPECT_CALL(
594 *mock_caller_, 610 *mock_caller_,
595 AsyncMigrateKey( 611 AsyncMigrateKey(
596 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) 612 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _))
597 .Times(1) 613 .Times(1)
598 .RetiresOnSaturation(); 614 .RetiresOnSaturation();
599 EXPECT_CALL(*mock_caller_, 615
600 AsyncMount(user_context_.GetUserID(), 616 // Set up mock homedir methods to respond successfully to a cryptohome mount
601 transformed_key_.GetSecret(), 617 // attempt.
602 cryptohome::MOUNT_FLAGS_NONE, 618 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
603 _)) 619 std::string(),
604 .Times(1) 620 cryptohome::PRIV_DEFAULT);
605 .RetiresOnSaturation(); 621 EXPECT_CALL(*mock_homedir_methods_,
606 EXPECT_CALL(*mock_caller_, 622 MountEx(cryptohome::Identification(user_context_.GetUserID()),
607 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 623 cryptohome::Authorization(auth_key),
608 .Times(1) 624 cryptohome::MountParameters(false /* ephemeral */),
609 .RetiresOnSaturation(); 625 _));
610 626
611 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 627 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
612 SetAttemptState(auth_.get(), state_.release()); 628 SetAttemptState(auth_.get(), state_.release());
613 629
614 auth_->RecoverEncryptedData(std::string()); 630 auth_->RecoverEncryptedData(std::string());
615 base::MessageLoop::current()->Run(); 631 base::MessageLoop::current()->Run();
616 } 632 }
617 633
618 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { 634 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) {
619 FailOnLoginSuccess(); 635 FailOnLoginSuccess();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 SetAndResolveState(auth_.get(), state_.release())); 675 SetAndResolveState(auth_.get(), state_.release()));
660 } 676 }
661 677
662 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { 678 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) {
663 UserContext expected_user_context(user_context_); 679 UserContext expected_user_context(user_context_);
664 expected_user_context.SetUserIDHash( 680 expected_user_context.SetUserIDHash(
665 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 681 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
666 ExpectLoginSuccess(expected_user_context); 682 ExpectLoginSuccess(expected_user_context);
667 FailOnLoginFailure(); 683 FailOnLoginFailure();
668 684
669 // Set up mock async method caller to respond successfully to a cryptohome 685 // Set up mock homedir methods to respond successfully to a cryptohome create
670 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). 686 // attempt.
671 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 687 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(),
672 EXPECT_CALL(*mock_caller_, 688 std::string(),
673 AsyncMount(user_context_.GetUserID(), 689 cryptohome::PRIV_DEFAULT);
674 transformed_key_.GetSecret(), 690 cryptohome::MountParameters mount(false /* ephemeral */);
675 cryptohome::CREATE_IF_MISSING, 691 mount.create_keys.push_back(cryptohome::KeyDefinition(
676 _)) 692 transformed_key_.GetSecret(),
677 .Times(1) 693 "gaia",
678 .RetiresOnSaturation(); 694 cryptohome::PRIV_DEFAULT));
679 EXPECT_CALL(*mock_caller_, 695 EXPECT_CALL(*mock_homedir_methods_,
680 AsyncGetSanitizedUsername(user_context_.GetUserID(), _)) 696 MountEx(cryptohome::Identification(user_context_.GetUserID()),
681 .Times(1) 697 cryptohome::Authorization(auth_key),
682 .RetiresOnSaturation(); 698 mount,
699 _));
683 700
684 // Set up state as though a cryptohome mount attempt has occurred 701 // Set up state as though a cryptohome mount attempt has occurred
685 // and been rejected because the user doesn't exist; additionally, 702 // and been rejected because the user doesn't exist; additionally,
686 // an online auth attempt has completed successfully. 703 // an online auth attempt has completed successfully.
687 state_->PresetCryptohomeStatus(false, 704 state_->PresetCryptohomeStatus(false,
688 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 705 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
689 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 706 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
690 SetAttemptState(auth_.get(), state_.release()); 707 SetAttemptState(auth_.get(), state_.release());
691 708
692 RunResolve(auth_.get()); 709 RunResolve(auth_.get());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
727 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) 744 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
728 .Times(1) 745 .Times(1)
729 .RetiresOnSaturation(); 746 .RetiresOnSaturation();
730 747
731 auth_->AuthenticateToUnlock(user_context_); 748 auth_->AuthenticateToUnlock(user_context_);
732 base::MessageLoop::current()->Run(); 749 base::MessageLoop::current()->Run();
733 } 750 }
734 751
735 } // namespace chromeos 752 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/cryptohome/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698