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/cryptohome_parameters.h" | 28 #include "chromeos/cryptohome/cryptohome_parameters.h" |
30 #include "chromeos/cryptohome/homedir_methods.h" | 29 #include "chromeos/cryptohome/homedir_methods.h" |
31 #include "chromeos/cryptohome/mock_async_method_caller.h" | 30 #include "chromeos/cryptohome/mock_async_method_caller.h" |
32 #include "chromeos/cryptohome/mock_homedir_methods.h" | 31 #include "chromeos/cryptohome/mock_homedir_methods.h" |
33 #include "chromeos/cryptohome/system_salt_getter.h" | 32 #include "chromeos/cryptohome/system_salt_getter.h" |
34 #include "chromeos/dbus/cros_disks_client.h" | 33 #include "chromeos/dbus/cros_disks_client.h" |
35 #include "chromeos/dbus/dbus_thread_manager.h" | 34 #include "chromeos/dbus/dbus_thread_manager.h" |
36 #include "chromeos/dbus/fake_cryptohome_client.h" | 35 #include "chromeos/dbus/fake_cryptohome_client.h" |
37 #include "chromeos/login/auth/key.h" | 36 #include "chromeos/login/auth/key.h" |
38 #include "chromeos/login/auth/mock_auth_status_consumer.h" | 37 #include "chromeos/login/auth/mock_auth_status_consumer.h" |
39 #include "chromeos/login/auth/mock_url_fetchers.h" | 38 #include "chromeos/login/auth/mock_url_fetchers.h" |
40 #include "chromeos/login/auth/test_attempt_state.h" | 39 #include "chromeos/login/auth/test_attempt_state.h" |
41 #include "chromeos/login/auth/user_context.h" | 40 #include "chromeos/login/auth/user_context.h" |
41 #include "components/ownership/mock_owner_key_util.h" | |
42 #include "content/public/test/test_browser_thread_bundle.h" | 42 #include "content/public/test/test_browser_thread_bundle.h" |
43 #include "crypto/nss_util_internal.h" | 43 #include "crypto/nss_util_internal.h" |
44 #include "crypto/scoped_test_nss_chromeos_user.h" | 44 #include "crypto/scoped_test_nss_chromeos_user.h" |
45 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 45 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
46 #include "net/base/net_errors.h" | 46 #include "net/base/net_errors.h" |
47 #include "net/url_request/url_request_status.h" | 47 #include "net/url_request/url_request_status.h" |
48 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
50 #include "third_party/cros_system_api/dbus/service_constants.h" | 50 #include "third_party/cros_system_api/dbus/service_constants.h" |
51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 class CryptohomeAuthenticatorTest : public testing::Test { | 118 class CryptohomeAuthenticatorTest : public testing::Test { |
119 public: | 119 public: |
120 CryptohomeAuthenticatorTest() | 120 CryptohomeAuthenticatorTest() |
121 : user_context_("me@nowhere.org"), | 121 : user_context_("me@nowhere.org"), |
122 user_manager_(new FakeUserManager()), | 122 user_manager_(new FakeUserManager()), |
123 user_manager_enabler_(user_manager_), | 123 user_manager_enabler_(user_manager_), |
124 mock_caller_(NULL), | 124 mock_caller_(NULL), |
125 mock_homedir_methods_(NULL), | 125 mock_homedir_methods_(NULL), |
126 owner_key_util_(new MockOwnerKeyUtil) { | 126 owner_key_util_(new ownership::MockOwnerKeyUtil) { |
127 user_context_.SetKey(Key("fakepass")); | 127 user_context_.SetKey(Key("fakepass")); |
128 user_context_.SetUserIDHash("me_nowhere_com_hash"); | 128 user_context_.SetUserIDHash("me_nowhere_com_hash"); |
129 const user_manager::User* user = | 129 const user_manager::User* user = |
130 user_manager_->AddUser(user_context_.GetUserID()); | 130 user_manager_->AddUser(user_context_.GetUserID()); |
131 profile_.set_profile_name(user_context_.GetUserID()); | 131 profile_.set_profile_name(user_context_.GetUserID()); |
132 | 132 |
133 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); | 133 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); |
134 | 134 |
135 transformed_key_ = *user_context_.GetKey(); | 135 transformed_key_ = *user_context_.GetKey(); |
136 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, | 136 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, |
(...skipping 11 matching lines...) Expand all Loading... | |
148 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; | 148 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; |
149 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 149 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
150 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); | 150 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); |
151 | 151 |
152 fake_cryptohome_client_ = new FakeCryptohomeClient; | 152 fake_cryptohome_client_ = new FakeCryptohomeClient; |
153 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( | 153 chromeos::DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( |
154 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); | 154 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); |
155 | 155 |
156 SystemSaltGetter::Initialize(); | 156 SystemSaltGetter::Initialize(); |
157 | 157 |
158 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_); | 158 OwnerSettingsService::SetOwnerKeyUtilForTesting(owner_key_util_); |
erikwright (departed)
2014/08/28 16:31:50
It's a pain that the other code under test statica
| |
159 | 159 |
160 auth_ = new ChromeCryptohomeAuthenticator(&consumer_); | 160 auth_ = new ChromeCryptohomeAuthenticator(&consumer_); |
161 state_.reset(new TestAttemptState(user_context_, false)); | 161 state_.reset(new TestAttemptState(user_context_, false)); |
162 } | 162 } |
163 | 163 |
164 // Tears down the test fixture. | 164 // Tears down the test fixture. |
165 virtual void TearDown() { | 165 virtual void TearDown() { |
166 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); | 166 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); |
167 SystemSaltGetter::Shutdown(); | 167 SystemSaltGetter::Shutdown(); |
168 DBusThreadManager::Shutdown(); | 168 DBusThreadManager::Shutdown(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 | 275 |
276 cryptohome::MockAsyncMethodCaller* mock_caller_; | 276 cryptohome::MockAsyncMethodCaller* mock_caller_; |
277 cryptohome::MockHomedirMethods* mock_homedir_methods_; | 277 cryptohome::MockHomedirMethods* mock_homedir_methods_; |
278 | 278 |
279 MockAuthStatusConsumer consumer_; | 279 MockAuthStatusConsumer consumer_; |
280 | 280 |
281 scoped_refptr<CryptohomeAuthenticator> auth_; | 281 scoped_refptr<CryptohomeAuthenticator> auth_; |
282 scoped_ptr<TestAttemptState> state_; | 282 scoped_ptr<TestAttemptState> state_; |
283 FakeCryptohomeClient* fake_cryptohome_client_; | 283 FakeCryptohomeClient* fake_cryptohome_client_; |
284 | 284 |
285 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; | 285 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; |
286 }; | 286 }; |
287 | 287 |
288 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { | 288 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { |
289 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) | 289 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) |
290 .Times(1) | 290 .Times(1) |
291 .RetiresOnSaturation(); | 291 .RetiresOnSaturation(); |
292 | 292 |
293 SetAttemptState(auth_.get(), state_.release()); | 293 SetAttemptState(auth_.get(), state_.release()); |
294 auth_->OnAuthSuccess(); | 294 auth_->OnAuthSuccess(); |
295 } | 295 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 SetOwnerState(false, false); | 350 SetOwnerState(false, false); |
351 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN, | 351 EXPECT_EQ(CryptohomeAuthenticator::OFFLINE_LOGIN, |
352 SetAndResolveState(auth_.get(), state_.release())); | 352 SetAndResolveState(auth_.get(), state_.release())); |
353 } | 353 } |
354 | 354 |
355 // Test the case that login switches to SafeMode and a User that is not the | 355 // Test the case that login switches to SafeMode and a User that is not the |
356 // owner tries to log in. The login should fail because of the missing owner | 356 // owner tries to log in. The login should fail because of the missing owner |
357 // private key. | 357 // private key. |
358 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededFailedMount) { | 358 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededFailedMount) { |
359 crypto::ScopedTestNSSChromeOSUser user_slot(user_context_.GetUserIDHash()); | 359 crypto::ScopedTestNSSChromeOSUser user_slot(user_context_.GetUserIDHash()); |
360 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); | 360 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); |
erikwright (departed)
2014/08/28 16:31:50
For these two tests that want to use a different k
| |
361 | 361 |
362 profile_manager_.reset( | 362 profile_manager_.reset( |
363 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 363 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
364 ASSERT_TRUE(profile_manager_->SetUp()); | 364 ASSERT_TRUE(profile_manager_->SetUp()); |
365 | 365 |
366 FailOnLoginSuccess(); // Set failing on success as the default... | 366 FailOnLoginSuccess(); // Set failing on success as the default... |
367 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); | 367 AuthFailure failure = AuthFailure(AuthFailure::OWNER_REQUIRED); |
368 ExpectLoginFailure(failure); | 368 ExpectLoginFailure(failure); |
369 | 369 |
370 // Set up state as though a cryptohome mount attempt has occurred | 370 // Set up state as though a cryptohome mount attempt has occurred |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
744 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) | 744 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) |
745 .Times(1) | 745 .Times(1) |
746 .RetiresOnSaturation(); | 746 .RetiresOnSaturation(); |
747 | 747 |
748 auth_->AuthenticateToUnlock(user_context_); | 748 auth_->AuthenticateToUnlock(user_context_); |
749 base::MessageLoop::current()->Run(); | 749 base::MessageLoop::current()->Run(); |
750 } | 750 } |
751 | 751 |
752 } // namespace chromeos | 752 } // namespace chromeos |
OLD | NEW |