| OLD | NEW |
| 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" | |
| 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 23 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 27 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
| 28 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
| 29 #include "chromeos/cryptohome/mock_async_method_caller.h" | 28 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 30 #include "chromeos/cryptohome/system_salt_getter.h" | 29 #include "chromeos/cryptohome/system_salt_getter.h" |
| 31 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 32 #include "chromeos/dbus/fake_cryptohome_client.h" | 31 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 33 #include "chromeos/login/auth/key.h" | 32 #include "chromeos/login/auth/key.h" |
| 34 #include "chromeos/login/auth/mock_auth_status_consumer.h" | 33 #include "chromeos/login/auth/mock_auth_status_consumer.h" |
| 35 #include "chromeos/login/auth/mock_url_fetchers.h" | 34 #include "chromeos/login/auth/mock_url_fetchers.h" |
| 36 #include "chromeos/login/auth/test_attempt_state.h" | 35 #include "chromeos/login/auth/test_attempt_state.h" |
| 37 #include "chromeos/login/auth/user_context.h" | 36 #include "chromeos/login/auth/user_context.h" |
| 37 #include "components/ownership/mock_owner_key_util.h" |
| 38 #include "content/public/test/test_browser_thread_bundle.h" | 38 #include "content/public/test/test_browser_thread_bundle.h" |
| 39 #include "crypto/nss_util_internal.h" | 39 #include "crypto/nss_util_internal.h" |
| 40 #include "crypto/scoped_test_nss_chromeos_user.h" | 40 #include "crypto/scoped_test_nss_chromeos_user.h" |
| 41 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 41 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
| 42 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
| 43 #include "net/url_request/url_request_status.h" | 43 #include "net/url_request/url_request_status.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 44 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 46 #include "third_party/cros_system_api/dbus/service_constants.h" | 46 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 47 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 class CryptohomeAuthenticatorTest : public testing::Test { | 114 class CryptohomeAuthenticatorTest : public testing::Test { |
| 115 public: | 115 public: |
| 116 CryptohomeAuthenticatorTest() | 116 CryptohomeAuthenticatorTest() |
| 117 : user_context_("me@nowhere.org"), | 117 : user_context_("me@nowhere.org"), |
| 118 user_manager_(new FakeUserManager()), | 118 user_manager_(new FakeUserManager()), |
| 119 user_manager_enabler_(user_manager_), | 119 user_manager_enabler_(user_manager_), |
| 120 mock_caller_(NULL), | 120 mock_caller_(NULL), |
| 121 owner_key_util_(new MockOwnerKeyUtil) { | 121 owner_key_util_(new ownership::MockOwnerKeyUtil) { |
| 122 user_context_.SetKey(Key("fakepass")); | 122 user_context_.SetKey(Key("fakepass")); |
| 123 user_context_.SetUserIDHash("me_nowhere_com_hash"); | 123 user_context_.SetUserIDHash("me_nowhere_com_hash"); |
| 124 const user_manager::User* user = | 124 const user_manager::User* user = |
| 125 user_manager_->AddUser(user_context_.GetUserID()); | 125 user_manager_->AddUser(user_context_.GetUserID()); |
| 126 profile_.set_profile_name(user_context_.GetUserID()); | 126 profile_.set_profile_name(user_context_.GetUserID()); |
| 127 | 127 |
| 128 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); | 128 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); |
| 129 | 129 |
| 130 transformed_key_ = *user_context_.GetKey(); | 130 transformed_key_ = *user_context_.GetKey(); |
| 131 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, | 131 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 ScopedUserManagerEnabler user_manager_enabler_; | 264 ScopedUserManagerEnabler user_manager_enabler_; |
| 265 | 265 |
| 266 cryptohome::MockAsyncMethodCaller* mock_caller_; | 266 cryptohome::MockAsyncMethodCaller* mock_caller_; |
| 267 | 267 |
| 268 MockAuthStatusConsumer consumer_; | 268 MockAuthStatusConsumer consumer_; |
| 269 | 269 |
| 270 scoped_refptr<CryptohomeAuthenticator> auth_; | 270 scoped_refptr<CryptohomeAuthenticator> auth_; |
| 271 scoped_ptr<TestAttemptState> state_; | 271 scoped_ptr<TestAttemptState> state_; |
| 272 FakeCryptohomeClient* fake_cryptohome_client_; | 272 FakeCryptohomeClient* fake_cryptohome_client_; |
| 273 | 273 |
| 274 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; | 274 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; |
| 275 }; | 275 }; |
| 276 | 276 |
| 277 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { | 277 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { |
| 278 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) | 278 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) |
| 279 .Times(1) | 279 .Times(1) |
| 280 .RetiresOnSaturation(); | 280 .RetiresOnSaturation(); |
| 281 | 281 |
| 282 SetAttemptState(auth_.get(), state_.release()); | 282 SetAttemptState(auth_.get(), state_.release()); |
| 283 auth_->OnAuthSuccess(); | 283 auth_->OnAuthSuccess(); |
| 284 } | 284 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 726 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 727 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) | 727 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) |
| 728 .Times(1) | 728 .Times(1) |
| 729 .RetiresOnSaturation(); | 729 .RetiresOnSaturation(); |
| 730 | 730 |
| 731 auth_->AuthenticateToUnlock(user_context_); | 731 auth_->AuthenticateToUnlock(user_context_); |
| 732 base::MessageLoop::current()->Run(); | 732 base::MessageLoop::current()->Run(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 } // namespace chromeos | 735 } // namespace chromeos |
| OLD | NEW |