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 #include <vector> |
8 | 9 |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
21 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" | 21 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
22 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 22 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 24 #include "chrome/browser/chromeos/settings/cros_settings.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 void ExpectPasswordChange() { | 253 void ExpectPasswordChange() { |
254 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) | 254 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) |
255 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) | 255 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) |
256 .RetiresOnSaturation(); | 256 .RetiresOnSaturation(); |
257 } | 257 } |
258 | 258 |
259 void ExpectGetKeyDataExCall(scoped_ptr<int64> key_type, | 259 void ExpectGetKeyDataExCall(scoped_ptr<int64> key_type, |
260 scoped_ptr<std::string> salt) { | 260 scoped_ptr<std::string> salt) { |
261 key_data_.clear(); | 261 key_definitions_.clear(); |
262 key_data_.push_back(new cryptohome::RetrievedKeyData( | 262 key_definitions_.push_back(cryptohome::KeyDefinition( |
263 cryptohome::RetrievedKeyData::TYPE_PASSWORD, | 263 std::string() /* secret */, |
264 kCryptohomeGAIAKeyLabel, | 264 kCryptohomeGAIAKeyLabel, |
265 1)); | 265 cryptohome::PRIV_DEFAULT)); |
266 key_data_.front()->privileges = cryptohome::PRIV_DEFAULT; | 266 cryptohome::KeyDefinition& key_definition = key_definitions_.back(); |
267 key_data_.front()->authorization_types.push_back( | 267 key_definition.revision = 1; |
268 cryptohome::RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256); | |
269 if (key_type) { | 268 if (key_type) { |
270 scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( | 269 key_definition.provider_data.push_back( |
271 new cryptohome::RetrievedKeyData::ProviderData("type")); | 270 cryptohome::KeyDefinition::ProviderData("type")); |
272 provider_data->number = key_type.Pass(); | 271 key_definition.provider_data.back().number = key_type.Pass(); |
273 key_data_.front()->provider_data.push_back(provider_data.release()); | |
274 } | 272 } |
275 if (salt) { | 273 if (salt) { |
276 scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( | 274 key_definition.provider_data.push_back( |
277 new cryptohome::RetrievedKeyData::ProviderData("salt")); | 275 cryptohome::KeyDefinition::ProviderData("salt")); |
278 provider_data->bytes = salt.Pass(); | 276 key_definition.provider_data.back().bytes = salt.Pass(); |
279 key_data_.front()->provider_data.push_back(provider_data.release()); | |
280 } | 277 } |
281 EXPECT_CALL(*mock_homedir_methods_, GetKeyDataEx( | 278 EXPECT_CALL(*mock_homedir_methods_, GetKeyDataEx( |
282 cryptohome::Identification(user_context_.GetUserID()), | 279 cryptohome::Identification(user_context_.GetUserID()), |
283 kCryptohomeGAIAKeyLabel, | 280 kCryptohomeGAIAKeyLabel, |
284 _)) | 281 _)) |
285 .WillOnce(WithArg<2>(Invoke( | 282 .WillOnce(WithArg<2>(Invoke( |
286 this, | 283 this, |
287 &CryptohomeAuthenticatorTest::InvokeGetDataExCallback))); | 284 &CryptohomeAuthenticatorTest::InvokeGetDataExCallback))); |
288 } | 285 } |
289 | 286 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 void SetOwnerState(bool owner_check_finished, bool check_result) { | 323 void SetOwnerState(bool owner_check_finished, bool check_result) { |
327 auth_->SetOwnerState(owner_check_finished, check_result); | 324 auth_->SetOwnerState(owner_check_finished, check_result); |
328 } | 325 } |
329 | 326 |
330 content::TestBrowserThreadBundle thread_bundle_; | 327 content::TestBrowserThreadBundle thread_bundle_; |
331 | 328 |
332 UserContext user_context_; | 329 UserContext user_context_; |
333 UserContext user_context_with_transformed_key_; | 330 UserContext user_context_with_transformed_key_; |
334 Key transformed_key_; | 331 Key transformed_key_; |
335 | 332 |
336 ScopedVector<cryptohome::RetrievedKeyData> key_data_; | 333 std::vector<cryptohome::KeyDefinition> key_definitions_; |
337 | 334 |
338 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | 335 ScopedDeviceSettingsTestHelper device_settings_test_helper_; |
339 ScopedTestCrosSettings test_cros_settings_; | 336 ScopedTestCrosSettings test_cros_settings_; |
340 | 337 |
341 TestingProfile profile_; | 338 TestingProfile profile_; |
342 scoped_ptr<TestingProfileManager> profile_manager_; | 339 scoped_ptr<TestingProfileManager> profile_manager_; |
343 FakeUserManager* user_manager_; | 340 FakeUserManager* user_manager_; |
344 ScopedUserManagerEnabler user_manager_enabler_; | 341 ScopedUserManagerEnabler user_manager_enabler_; |
345 | 342 |
346 cryptohome::MockAsyncMethodCaller* mock_caller_; | 343 cryptohome::MockAsyncMethodCaller* mock_caller_; |
347 cryptohome::MockHomedirMethods* mock_homedir_methods_; | 344 cryptohome::MockHomedirMethods* mock_homedir_methods_; |
348 | 345 |
349 MockAuthStatusConsumer consumer_; | 346 MockAuthStatusConsumer consumer_; |
350 | 347 |
351 scoped_refptr<CryptohomeAuthenticator> auth_; | 348 scoped_refptr<CryptohomeAuthenticator> auth_; |
352 scoped_ptr<TestAttemptState> state_; | 349 scoped_ptr<TestAttemptState> state_; |
353 FakeCryptohomeClient* fake_cryptohome_client_; | 350 FakeCryptohomeClient* fake_cryptohome_client_; |
354 | 351 |
355 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; | 352 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; |
356 | 353 |
357 private: | 354 private: |
358 void InvokeGetDataExCallback( | 355 void InvokeGetDataExCallback( |
359 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { | 356 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { |
360 callback.Run(true /* success */, | 357 callback.Run(true /* success */, |
361 cryptohome::MOUNT_ERROR_NONE, | 358 cryptohome::MOUNT_ERROR_NONE, |
362 key_data_.Pass()); | 359 key_definitions_); |
363 } | 360 } |
364 }; | 361 }; |
365 | 362 |
366 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { | 363 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { |
367 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) | 364 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) |
368 .Times(1) | 365 .Times(1) |
369 .RetiresOnSaturation(); | 366 .RetiresOnSaturation(); |
370 | 367 |
371 SetAttemptState(auth_.get(), state_.release()); | 368 SetAttemptState(auth_.get(), state_.release()); |
372 auth_->OnAuthSuccess(); | 369 auth_->OnAuthSuccess(); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // salt. | 828 // salt. |
832 ExpectGetKeyDataExCall( | 829 ExpectGetKeyDataExCall( |
833 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), | 830 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), |
834 scoped_ptr<std::string>()); | 831 scoped_ptr<std::string>()); |
835 | 832 |
836 auth_->AuthenticateToLogin(NULL, user_context_); | 833 auth_->AuthenticateToLogin(NULL, user_context_); |
837 base::RunLoop().Run(); | 834 base::RunLoop().Run(); |
838 } | 835 } |
839 | 836 |
840 } // namespace chromeos | 837 } // namespace chromeos |
OLD | NEW |