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

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

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
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 5
6 #include <stdint.h> 6 #include <stdint.h>
7
8 #include <memory>
7 #include <string> 9 #include <string>
8 #include <utility> 10 #include <utility>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
14 #include "base/macros.h" 16 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 19 #include "base/run_loop.h"
18 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
20 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" 22 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 23 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
22 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 24 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
23 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 25 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h" 26 #include "chrome/browser/chromeos/profiles/profile_helper.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h" 27 #include "chrome/browser/chromeos/settings/cros_settings.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 switches::kLoginManager); 163 switches::kLoginManager);
162 164
163 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 165 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
164 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 166 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
165 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; 167 mock_homedir_methods_ = new cryptohome::MockHomedirMethods;
166 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 168 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
167 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); 169 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_);
168 170
169 fake_cryptohome_client_ = new FakeCryptohomeClient; 171 fake_cryptohome_client_ = new FakeCryptohomeClient;
170 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( 172 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient(
171 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 173 std::unique_ptr<CryptohomeClient>(fake_cryptohome_client_));
172 174
173 SystemSaltGetter::Initialize(); 175 SystemSaltGetter::Initialize();
174 176
175 auth_ = new ChromeCryptohomeAuthenticator(&consumer_); 177 auth_ = new ChromeCryptohomeAuthenticator(&consumer_);
176 state_.reset(new TestAttemptState(user_context_, false)); 178 state_.reset(new TestAttemptState(user_context_, false));
177 } 179 }
178 180
179 // Tears down the test fixture. 181 // Tears down the test fixture.
180 void TearDown() override { 182 void TearDown() override {
181 SystemSaltGetter::Shutdown(); 183 SystemSaltGetter::Shutdown();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit)) 242 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit))
241 .RetiresOnSaturation(); 243 .RetiresOnSaturation();
242 } 244 }
243 245
244 void ExpectPasswordChange() { 246 void ExpectPasswordChange() {
245 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 247 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
246 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) 248 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit))
247 .RetiresOnSaturation(); 249 .RetiresOnSaturation();
248 } 250 }
249 251
250 void ExpectGetKeyDataExCall(scoped_ptr<int64_t> key_type, 252 void ExpectGetKeyDataExCall(std::unique_ptr<int64_t> key_type,
251 scoped_ptr<std::string> salt) { 253 std::unique_ptr<std::string> salt) {
252 key_definitions_.clear(); 254 key_definitions_.clear();
253 key_definitions_.push_back(cryptohome::KeyDefinition( 255 key_definitions_.push_back(cryptohome::KeyDefinition(
254 std::string() /* secret */, 256 std::string() /* secret */,
255 kCryptohomeGAIAKeyLabel, 257 kCryptohomeGAIAKeyLabel,
256 cryptohome::PRIV_DEFAULT)); 258 cryptohome::PRIV_DEFAULT));
257 cryptohome::KeyDefinition& key_definition = key_definitions_.back(); 259 cryptohome::KeyDefinition& key_definition = key_definitions_.back();
258 key_definition.revision = 1; 260 key_definition.revision = 1;
259 if (key_type) { 261 if (key_type) {
260 key_definition.provider_data.push_back( 262 key_definition.provider_data.push_back(
261 cryptohome::KeyDefinition::ProviderData("type")); 263 cryptohome::KeyDefinition::ProviderData("type"));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 UserContext user_context_; 320 UserContext user_context_;
319 UserContext user_context_with_transformed_key_; 321 UserContext user_context_with_transformed_key_;
320 Key transformed_key_; 322 Key transformed_key_;
321 323
322 std::vector<cryptohome::KeyDefinition> key_definitions_; 324 std::vector<cryptohome::KeyDefinition> key_definitions_;
323 325
324 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 326 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
325 ScopedTestCrosSettings test_cros_settings_; 327 ScopedTestCrosSettings test_cros_settings_;
326 328
327 TestingProfile profile_; 329 TestingProfile profile_;
328 scoped_ptr<TestingProfileManager> profile_manager_; 330 std::unique_ptr<TestingProfileManager> profile_manager_;
329 user_manager::FakeUserManager* user_manager_; 331 user_manager::FakeUserManager* user_manager_;
330 ScopedUserManagerEnabler user_manager_enabler_; 332 ScopedUserManagerEnabler user_manager_enabler_;
331 333
332 cryptohome::MockAsyncMethodCaller* mock_caller_; 334 cryptohome::MockAsyncMethodCaller* mock_caller_;
333 cryptohome::MockHomedirMethods* mock_homedir_methods_; 335 cryptohome::MockHomedirMethods* mock_homedir_methods_;
334 336
335 MockAuthStatusConsumer consumer_; 337 MockAuthStatusConsumer consumer_;
336 338
337 scoped_refptr<CryptohomeAuthenticator> auth_; 339 scoped_refptr<CryptohomeAuthenticator> auth_;
338 scoped_ptr<TestAttemptState> state_; 340 std::unique_ptr<TestAttemptState> state_;
339 FakeCryptohomeClient* fake_cryptohome_client_; 341 FakeCryptohomeClient* fake_cryptohome_client_;
340 342
341 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; 343 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_;
342 344
343 private: 345 private:
344 void InvokeGetDataExCallback( 346 void InvokeGetDataExCallback(
345 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { 347 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) {
346 callback.Run(true /* success */, 348 callback.Run(true /* success */,
347 cryptohome::MOUNT_ERROR_NONE, 349 cryptohome::MOUNT_ERROR_NONE,
348 key_definitions_); 350 key_definitions_);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 // remove attempt. 565 // remove attempt.
564 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 566 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
565 EXPECT_CALL( 567 EXPECT_CALL(
566 *mock_caller_, 568 *mock_caller_,
567 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _)) 569 AsyncRemove(cryptohome::Identification(user_context_.GetAccountId()), _))
568 .Times(1) 570 .Times(1)
569 .RetiresOnSaturation(); 571 .RetiresOnSaturation();
570 572
571 // Set up mock homedir methods to respond successfully to a cryptohome create 573 // Set up mock homedir methods to respond successfully to a cryptohome create
572 // attempt. 574 // attempt.
573 ExpectGetKeyDataExCall(scoped_ptr<int64_t>(), scoped_ptr<std::string>()); 575 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(),
576 std::unique_ptr<std::string>());
574 ExpectMountExCall(true /* expect_create_attempt */); 577 ExpectMountExCall(true /* expect_create_attempt */);
575 578
576 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 579 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
577 SetAttemptState(auth_.get(), state_.release()); 580 SetAttemptState(auth_.get(), state_.release());
578 581
579 auth_->ResyncEncryptedData(); 582 auth_->ResyncEncryptedData();
580 base::MessageLoop::current()->Run(); 583 base::MessageLoop::current()->Run();
581 } 584 }
582 585
583 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { 586 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 623 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
621 EXPECT_CALL( 624 EXPECT_CALL(
622 *mock_caller_, 625 *mock_caller_,
623 AsyncMigrateKey(cryptohome::Identification(user_context_.GetAccountId()), 626 AsyncMigrateKey(cryptohome::Identification(user_context_.GetAccountId()),
624 _, transformed_key_.GetSecret(), _)) 627 _, transformed_key_.GetSecret(), _))
625 .Times(1) 628 .Times(1)
626 .RetiresOnSaturation(); 629 .RetiresOnSaturation();
627 630
628 // Set up mock homedir methods to respond successfully to a cryptohome mount 631 // Set up mock homedir methods to respond successfully to a cryptohome mount
629 // attempt. 632 // attempt.
630 ExpectGetKeyDataExCall(scoped_ptr<int64_t>(), scoped_ptr<std::string>()); 633 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(),
634 std::unique_ptr<std::string>());
631 ExpectMountExCall(false /* expect_create_attempt */); 635 ExpectMountExCall(false /* expect_create_attempt */);
632 636
633 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 637 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
634 SetAttemptState(auth_.get(), state_.release()); 638 SetAttemptState(auth_.get(), state_.release());
635 639
636 auth_->RecoverEncryptedData(std::string()); 640 auth_->RecoverEncryptedData(std::string());
637 base::MessageLoop::current()->Run(); 641 base::MessageLoop::current()->Run();
638 } 642 }
639 643
640 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { 644 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 687
684 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { 688 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) {
685 UserContext expected_user_context(user_context_with_transformed_key_); 689 UserContext expected_user_context(user_context_with_transformed_key_);
686 expected_user_context.SetUserIDHash( 690 expected_user_context.SetUserIDHash(
687 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 691 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
688 ExpectLoginSuccess(expected_user_context); 692 ExpectLoginSuccess(expected_user_context);
689 FailOnLoginFailure(); 693 FailOnLoginFailure();
690 694
691 // Set up mock homedir methods to respond successfully to a cryptohome create 695 // Set up mock homedir methods to respond successfully to a cryptohome create
692 // attempt. 696 // attempt.
693 ExpectGetKeyDataExCall(scoped_ptr<int64_t>(), scoped_ptr<std::string>()); 697 ExpectGetKeyDataExCall(std::unique_ptr<int64_t>(),
698 std::unique_ptr<std::string>());
694 ExpectMountExCall(true /* expect_create_attempt */); 699 ExpectMountExCall(true /* expect_create_attempt */);
695 700
696 // Set up state as though a cryptohome mount attempt has occurred 701 // Set up state as though a cryptohome mount attempt has occurred
697 // and been rejected because the user doesn't exist; additionally, 702 // and been rejected because the user doesn't exist; additionally,
698 // an online auth attempt has completed successfully. 703 // an online auth attempt has completed successfully.
699 state_->PresetCryptohomeStatus(false, 704 state_->PresetCryptohomeStatus(false,
700 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 705 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
701 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); 706 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone());
702 SetAttemptState(auth_.get(), state_.release()); 707 SetAttemptState(auth_.get(), state_.release());
703 708
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 expected_user_context.SetUserIDHash( 759 expected_user_context.SetUserIDHash(
755 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); 760 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
756 ExpectLoginSuccess(expected_user_context); 761 ExpectLoginSuccess(expected_user_context);
757 FailOnLoginFailure(); 762 FailOnLoginFailure();
758 763
759 // Set up mock homedir methods to respond with key metadata indicating that a 764 // Set up mock homedir methods to respond with key metadata indicating that a
760 // pre-hashed key was used to create the cryptohome and allow a successful 765 // pre-hashed key was used to create the cryptohome and allow a successful
761 // mount when this pre-hashed key is used. 766 // mount when this pre-hashed key is used.
762 767
763 ExpectGetKeyDataExCall( 768 ExpectGetKeyDataExCall(
764 make_scoped_ptr(new int64_t(Key::KEY_TYPE_SALTED_SHA256)), 769 base::WrapUnique(new int64_t(Key::KEY_TYPE_SALTED_SHA256)),
765 make_scoped_ptr(new std::string(kSalt))); 770 base::WrapUnique(new std::string(kSalt)));
766 ExpectMountExCall(false /* expect_create_attempt */); 771 ExpectMountExCall(false /* expect_create_attempt */);
767 772
768 auth_->AuthenticateToLogin(NULL, user_context_); 773 auth_->AuthenticateToLogin(NULL, user_context_);
769 base::RunLoop().Run(); 774 base::RunLoop().Run();
770 } 775 }
771 776
772 TEST_F(CryptohomeAuthenticatorTest, FailLoginWithMissingSalt) { 777 TEST_F(CryptohomeAuthenticatorTest, FailLoginWithMissingSalt) {
773 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); 778 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt);
774 779
775 FailOnLoginSuccess(); 780 FailOnLoginSuccess();
776 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 781 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME));
777 782
778 // Set up mock homedir methods to respond with key metadata indicating that a 783 // Set up mock homedir methods to respond with key metadata indicating that a
779 // pre-hashed key was used to create the cryptohome but without the required 784 // pre-hashed key was used to create the cryptohome but without the required
780 // salt. 785 // salt.
781 ExpectGetKeyDataExCall( 786 ExpectGetKeyDataExCall(
782 make_scoped_ptr(new int64_t(Key::KEY_TYPE_SALTED_SHA256)), 787 base::WrapUnique(new int64_t(Key::KEY_TYPE_SALTED_SHA256)),
783 scoped_ptr<std::string>()); 788 std::unique_ptr<std::string>());
784 789
785 auth_->AuthenticateToLogin(NULL, user_context_); 790 auth_->AuthenticateToLogin(NULL, user_context_);
786 base::RunLoop().Run(); 791 base::RunLoop().Run();
787 } 792 }
788 793
789 } // namespace chromeos 794 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/auth/chrome_login_performer.h ('k') | chrome/browser/chromeos/login/auth/mount_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698