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

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

Issue 296773002: Add a Key class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 | Annotate | Revision Log
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/parallel_authenticator.h" 5 #include "chrome/browser/chromeos/login/auth/parallel_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/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.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/auth/key.h"
16 #include "chrome/browser/chromeos/login/auth/mock_login_status_consumer.h" 17 #include "chrome/browser/chromeos/login/auth/mock_login_status_consumer.h"
17 #include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" 18 #include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h"
18 #include "chrome/browser/chromeos/login/auth/test_attempt_state.h" 19 #include "chrome/browser/chromeos/login/auth/test_attempt_state.h"
19 #include "chrome/browser/chromeos/login/auth/user_context.h" 20 #include "chrome/browser/chromeos/login/auth/user_context.h"
20 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 21 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
21 #include "chrome/browser/chromeos/login/users/user_manager.h" 22 #include "chrome/browser/chromeos/login/users/user_manager.h"
22 #include "chrome/browser/chromeos/settings/cros_settings.h" 23 #include "chrome/browser/chromeos/settings/cros_settings.h"
23 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 24 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 25 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
25 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
(...skipping 13 matching lines...) Expand all
39 40
40 using ::testing::Invoke; 41 using ::testing::Invoke;
41 using ::testing::Return; 42 using ::testing::Return;
42 using ::testing::_; 43 using ::testing::_;
43 44
44 namespace chromeos { 45 namespace chromeos {
45 46
46 class ParallelAuthenticatorTest : public testing::Test { 47 class ParallelAuthenticatorTest : public testing::Test {
47 public: 48 public:
48 ParallelAuthenticatorTest() 49 ParallelAuthenticatorTest()
49 : username_("me@nowhere.org"), 50 : user_context_("me@nowhere.org"),
50 password_("fakepass"),
51 hash_ascii_(ParallelAuthenticator::HashPassword(
52 password_,
53 SystemSaltGetter::ConvertRawSaltToHexString(
54 FakeCryptohomeClient::GetStubSystemSalt()))),
55 user_manager_enabler_(new MockUserManager), 51 user_manager_enabler_(new MockUserManager),
56 mock_caller_(NULL) { 52 mock_caller_(NULL) {
53 user_context_.SetKey(Key("fakepass"));
54 transformed_key_ = *user_context_.GetKey();
55 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF,
56 SystemSaltGetter::ConvertRawSaltToHexString(
57 FakeCryptohomeClient::GetStubSystemSalt()));
57 } 58 }
58 59
59 virtual ~ParallelAuthenticatorTest() { 60 virtual ~ParallelAuthenticatorTest() {
60 DCHECK(!mock_caller_); 61 DCHECK(!mock_caller_);
61 } 62 }
62 63
63 virtual void SetUp() { 64 virtual void SetUp() {
64 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); 65 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager);
65 66
66 mock_caller_ = new cryptohome::MockAsyncMethodCaller; 67 mock_caller_ = new cryptohome::MockAsyncMethodCaller;
67 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); 68 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_);
68 69
69 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; 70 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
70 fake_cryptohome_client_ = new FakeCryptohomeClient; 71 fake_cryptohome_client_ = new FakeCryptohomeClient;
71 fake_dbus_thread_manager->SetCryptohomeClient( 72 fake_dbus_thread_manager->SetCryptohomeClient(
72 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_)); 73 scoped_ptr<CryptohomeClient>(fake_cryptohome_client_));
73 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); 74 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
74 75
75 SystemSaltGetter::Initialize(); 76 SystemSaltGetter::Initialize();
76 77
77 auth_ = new ParallelAuthenticator(&consumer_); 78 auth_ = new ParallelAuthenticator(&consumer_);
78 UserContext user_context(username_); 79 state_.reset(new TestAttemptState(user_context_, false));
79 user_context.SetPassword(password_);
80 state_.reset(new TestAttemptState(user_context, false));
81 } 80 }
82 81
83 // Tears down the test fixture. 82 // Tears down the test fixture.
84 virtual void TearDown() { 83 virtual void TearDown() {
85 SystemSaltGetter::Shutdown(); 84 SystemSaltGetter::Shutdown();
86 DBusThreadManager::Shutdown(); 85 DBusThreadManager::Shutdown();
87 86
88 cryptohome::AsyncMethodCaller::Shutdown(); 87 cryptohome::AsyncMethodCaller::Shutdown();
89 mock_caller_ = NULL; 88 mock_caller_ = NULL;
90 } 89 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 .WillOnce(Invoke(MockConsumer::OnFailQuit)) 130 .WillOnce(Invoke(MockConsumer::OnFailQuit))
132 .RetiresOnSaturation(); 131 .RetiresOnSaturation();
133 } 132 }
134 133
135 void ExpectRetailModeLoginSuccess() { 134 void ExpectRetailModeLoginSuccess() {
136 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess(_)) 135 EXPECT_CALL(consumer_, OnRetailModeLoginSuccess(_))
137 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit)) 136 .WillOnce(Invoke(MockConsumer::OnRetailModeSuccessQuit))
138 .RetiresOnSaturation(); 137 .RetiresOnSaturation();
139 } 138 }
140 139
141 void ExpectLoginSuccess(const std::string& username, 140 void ExpectLoginSuccess(const UserContext& user_context) {
142 const std::string& password,
143 const std::string& username_hash,
144 bool pending) {
145 UserContext user_context(username);
146 user_context.SetPassword(password);
147 user_context.SetUserIDHash(username_hash);
148 EXPECT_CALL(consumer_, OnLoginSuccess(user_context)) 141 EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
149 .WillOnce(Invoke(MockConsumer::OnSuccessQuit)) 142 .WillOnce(Invoke(MockConsumer::OnSuccessQuit))
150 .RetiresOnSaturation(); 143 .RetiresOnSaturation();
151 } 144 }
152 145
153 void ExpectGuestLoginSuccess() { 146 void ExpectGuestLoginSuccess() {
154 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess()) 147 EXPECT_CALL(consumer_, OnOffTheRecordLoginSuccess())
155 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit)) 148 .WillOnce(Invoke(MockConsumer::OnGuestSuccessQuit))
156 .RetiresOnSaturation(); 149 .RetiresOnSaturation();
157 } 150 }
(...skipping 18 matching lines...) Expand all
176 auth->set_attempt_state(state); 169 auth->set_attempt_state(state);
177 return auth->ResolveState(); 170 return auth->ResolveState();
178 } 171 }
179 172
180 void SetOwnerState(bool owner_check_finished, bool check_result) { 173 void SetOwnerState(bool owner_check_finished, bool check_result) {
181 auth_->SetOwnerState(owner_check_finished, check_result); 174 auth_->SetOwnerState(owner_check_finished, check_result);
182 } 175 }
183 176
184 content::TestBrowserThreadBundle thread_bundle_; 177 content::TestBrowserThreadBundle thread_bundle_;
185 178
186 std::string username_; 179 UserContext user_context_;
187 std::string password_; 180 Key transformed_key_;
188 std::string username_hash_;
189 std::string hash_ascii_;
190 181
191 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 182 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
192 ScopedTestCrosSettings test_cros_settings_; 183 ScopedTestCrosSettings test_cros_settings_;
193 184
194 ScopedUserManagerEnabler user_manager_enabler_; 185 ScopedUserManagerEnabler user_manager_enabler_;
195 186
196 cryptohome::MockAsyncMethodCaller* mock_caller_; 187 cryptohome::MockAsyncMethodCaller* mock_caller_;
197 188
198 MockConsumer consumer_; 189 MockConsumer consumer_;
199 scoped_refptr<ParallelAuthenticator> auth_; 190 scoped_refptr<ParallelAuthenticator> auth_;
200 scoped_ptr<TestAttemptState> state_; 191 scoped_ptr<TestAttemptState> state_;
201 FakeCryptohomeClient* fake_cryptohome_client_; 192 FakeCryptohomeClient* fake_cryptohome_client_;
202 }; 193 };
203 194
204 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { 195 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) {
205 UserContext user_context(username_); 196 EXPECT_CALL(consumer_, OnLoginSuccess(user_context_))
206 user_context.SetPassword(password_);
207 user_context.SetUserIDHash(username_hash_);
208 EXPECT_CALL(consumer_, OnLoginSuccess(user_context))
209 .Times(1) 197 .Times(1)
210 .RetiresOnSaturation(); 198 .RetiresOnSaturation();
211 199
212 SetAttemptState(auth_.get(), state_.release()); 200 SetAttemptState(auth_.get(), state_.release());
213 auth_->OnLoginSuccess(); 201 auth_->OnLoginSuccess();
214 } 202 }
215 203
216 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { 204 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) {
217 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) 205 EXPECT_CALL(consumer_, OnPasswordChangeDetected())
218 .Times(1) 206 .Times(1)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 SetAndResolveState(auth_.get(), state_.release())); 249 SetAndResolveState(auth_.get(), state_.release()));
262 } 250 }
263 251
264 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { 252 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) {
265 // Set up state as though a cryptohome mount attempt has occurred 253 // Set up state as though a cryptohome mount attempt has occurred
266 // and succeeded but we are in safe mode and the current user is not owner. 254 // and succeeded but we are in safe mode and the current user is not owner.
267 // This test will check that the "safe-mode" policy is not set and will let 255 // This test will check that the "safe-mode" policy is not set and will let
268 // the mount finish successfully. 256 // the mount finish successfully.
269 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 257 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
270 SetOwnerState(false, false); 258 SetOwnerState(false, false);
271 // and test that the mount has succeeded. 259 // Test that the mount has succeeded.
272 UserContext user_context(username_); 260 state_.reset(new TestAttemptState(user_context_, false));
273 user_context.SetPassword(password_);
274 state_.reset(new TestAttemptState(user_context, false));
275 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 261 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
276 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, 262 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN,
277 SetAndResolveState(auth_.get(), state_.release())); 263 SetAndResolveState(auth_.get(), state_.release()));
278 } 264 }
279 265
280 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { 266 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) {
281 FailOnLoginSuccess(); // Set failing on success as the default... 267 FailOnLoginSuccess(); // Set failing on success as the default...
282 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); 268 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED);
283 ExpectLoginFailure(failure); 269 ExpectLoginFailure(failure);
284 270
(...skipping 21 matching lines...) Expand all
306 EXPECT_EQ(ParallelAuthenticator::CONTINUE, 292 EXPECT_EQ(ParallelAuthenticator::CONTINUE,
307 SetAndResolveState(auth_.get(), state_.release())); 293 SetAndResolveState(auth_.get(), state_.release()));
308 EXPECT_TRUE(LoginState::Get()->IsInSafeMode()); 294 EXPECT_TRUE(LoginState::Get()->IsInSafeMode());
309 295
310 // Simulate TPM token ready event. 296 // Simulate TPM token ready event.
311 DeviceSettingsService::Get()->OnTPMTokenReady(); 297 DeviceSettingsService::Get()->OnTPMTokenReady();
312 298
313 // Flush all the pending operations. The operations should induce an owner 299 // Flush all the pending operations. The operations should induce an owner
314 // verification. 300 // verification.
315 device_settings_test_helper_.Flush(); 301 device_settings_test_helper_.Flush();
316 // and test that the mount has succeeded. 302 // Test that the mount has succeeded.
317 UserContext user_context(username_); 303 state_.reset(new TestAttemptState(user_context_, false));
318 user_context.SetPassword(password_);
319 state_.reset(new TestAttemptState(user_context, false));
320 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 304 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
321 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, 305 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED,
322 SetAndResolveState(auth_.get(), state_.release())); 306 SetAndResolveState(auth_.get(), state_.release()));
323 307
324 // Unset global objects used by this test. 308 // Unset global objects used by this test.
325 LoginState::Shutdown(); 309 LoginState::Shutdown();
326 EXPECT_TRUE( 310 EXPECT_TRUE(
327 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); 311 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider));
328 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); 312 CrosSettings::Get()->AddSettingsProvider(device_settings_provider);
329 } 313 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); 378 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
395 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)) 379 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_))
396 .Times(1) 380 .Times(1)
397 .RetiresOnSaturation(); 381 .RetiresOnSaturation();
398 382
399 auth_->LoginRetailMode(); 383 auth_->LoginRetailMode();
400 base::MessageLoop::current()->Run(); 384 base::MessageLoop::current()->Run();
401 } 385 }
402 386
403 TEST_F(ParallelAuthenticatorTest, DriveDataResync) { 387 TEST_F(ParallelAuthenticatorTest, DriveDataResync) {
404 ExpectLoginSuccess(username_, 388 UserContext expected_user_context(user_context_);
405 password_, 389 expected_user_context.SetUserIDHash(
406 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, 390 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
407 false); 391 ExpectLoginSuccess(expected_user_context);
408 FailOnLoginFailure(); 392 FailOnLoginFailure();
409 393
410 // Set up mock async method caller to respond successfully to a cryptohome 394 // Set up mock async method caller to respond successfully to a cryptohome
411 // remove attempt and a cryptohome create attempt (indicated by the 395 // remove attempt and a cryptohome create attempt (indicated by the
412 // |CREATE_IF_MISSING| flag to AsyncMount). 396 // |CREATE_IF_MISSING| flag to AsyncMount).
413 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 397 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
414 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) 398 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
415 .Times(1) 399 .Times(1)
416 .RetiresOnSaturation(); 400 .RetiresOnSaturation();
417 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, 401 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
418 cryptohome::CREATE_IF_MISSING, _)) 402 transformed_key_.GetSecret(),
403 cryptohome::CREATE_IF_MISSING,
404 _))
419 .Times(1) 405 .Times(1)
420 .RetiresOnSaturation(); 406 .RetiresOnSaturation();
421 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) 407 EXPECT_CALL(*mock_caller_,
408 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
422 .Times(1) 409 .Times(1)
423 .RetiresOnSaturation(); 410 .RetiresOnSaturation();
424 411
425 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 412 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
426 SetAttemptState(auth_.get(), state_.release()); 413 SetAttemptState(auth_.get(), state_.release());
427 414
428 auth_->ResyncEncryptedData(); 415 auth_->ResyncEncryptedData();
429 base::MessageLoop::current()->Run(); 416 base::MessageLoop::current()->Run();
430 } 417 }
431 418
432 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { 419 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) {
433 FailOnLoginSuccess(); 420 FailOnLoginSuccess();
434 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)); 421 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED));
435 422
436 // Set up mock async method caller to fail a cryptohome remove attempt. 423 // Set up mock async method caller to fail a cryptohome remove attempt.
437 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); 424 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE);
438 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) 425 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _))
439 .Times(1) 426 .Times(1)
440 .RetiresOnSaturation(); 427 .RetiresOnSaturation();
441 428
442 SetAttemptState(auth_.get(), state_.release()); 429 SetAttemptState(auth_.get(), state_.release());
443 430
444 auth_->ResyncEncryptedData(); 431 auth_->ResyncEncryptedData();
445 base::MessageLoop::current()->Run(); 432 base::MessageLoop::current()->Run();
446 } 433 }
447 434
448 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { 435 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) {
449 FailOnLoginSuccess(); 436 FailOnLoginSuccess();
450 ExpectPasswordChange(); 437 ExpectPasswordChange();
451 438
452 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 439 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
453 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 440 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
454 SetAttemptState(auth_.get(), state_.release()); 441 SetAttemptState(auth_.get(), state_.release());
455 442
456 RunResolve(auth_.get()); 443 RunResolve(auth_.get());
457 } 444 }
458 445
459 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { 446 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) {
460 ExpectLoginSuccess(username_, 447 UserContext expected_user_context(user_context_);
461 password_, 448 expected_user_context.SetUserIDHash(
462 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, 449 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
463 false); 450 ExpectLoginSuccess(expected_user_context);
464 FailOnLoginFailure(); 451 FailOnLoginFailure();
465 452
466 // Set up mock async method caller to respond successfully to a key migration. 453 // Set up mock async method caller to respond successfully to a key migration.
467 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 454 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
468 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) 455 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(),
456 _,
457 transformed_key_.GetSecret(),
458 _))
469 .Times(1) 459 .Times(1)
470 .RetiresOnSaturation(); 460 .RetiresOnSaturation();
471 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, 461 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
472 cryptohome::MOUNT_FLAGS_NONE, _)) 462 transformed_key_.GetSecret(),
463 cryptohome::MOUNT_FLAGS_NONE,
464 _))
473 .Times(1) 465 .Times(1)
474 .RetiresOnSaturation(); 466 .RetiresOnSaturation();
475 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) 467 EXPECT_CALL(*mock_caller_,
468 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
476 .Times(1) 469 .Times(1)
477 .RetiresOnSaturation(); 470 .RetiresOnSaturation();
478 471
479 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 472 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
480 SetAttemptState(auth_.get(), state_.release()); 473 SetAttemptState(auth_.get(), state_.release());
481 474
482 auth_->RecoverEncryptedData(std::string()); 475 auth_->RecoverEncryptedData(std::string());
483 base::MessageLoop::current()->Run(); 476 base::MessageLoop::current()->Run();
484 } 477 }
485 478
486 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { 479 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) {
487 FailOnLoginSuccess(); 480 FailOnLoginSuccess();
488 ExpectPasswordChange(); 481 ExpectPasswordChange();
489 482
490 // Set up mock async method caller to fail a key migration attempt, 483 // Set up mock async method caller to fail a key migration attempt,
491 // asserting that the wrong password was used. 484 // asserting that the wrong password was used.
492 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); 485 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE);
493 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) 486 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(user_context_.GetUserID(),
487 _,
488 transformed_key_.GetSecret(),
489 _))
494 .Times(1) 490 .Times(1)
495 .RetiresOnSaturation(); 491 .RetiresOnSaturation();
496 492
497 SetAttemptState(auth_.get(), state_.release()); 493 SetAttemptState(auth_.get(), state_.release());
498 494
499 auth_->RecoverEncryptedData(std::string()); 495 auth_->RecoverEncryptedData(std::string());
500 base::MessageLoop::current()->Run(); 496 base::MessageLoop::current()->Run();
501 } 497 }
502 498
503 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) { 499 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) {
(...skipping 14 matching lines...) Expand all
518 // an online auth attempt has completed successfully. 514 // an online auth attempt has completed successfully.
519 state_->PresetCryptohomeStatus(false, 515 state_->PresetCryptohomeStatus(false,
520 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 516 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
521 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 517 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
522 518
523 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, 519 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW,
524 SetAndResolveState(auth_.get(), state_.release())); 520 SetAndResolveState(auth_.get(), state_.release()));
525 } 521 }
526 522
527 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { 523 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) {
528 ExpectLoginSuccess(username_, 524 UserContext expected_user_context(user_context_);
529 password_, 525 expected_user_context.SetUserIDHash(
530 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, 526 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername);
531 false); 527 ExpectLoginSuccess(expected_user_context);
532 FailOnLoginFailure(); 528 FailOnLoginFailure();
533 529
534 // Set up mock async method caller to respond successfully to a cryptohome 530 // Set up mock async method caller to respond successfully to a cryptohome
535 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). 531 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount).
536 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 532 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
537 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, 533 EXPECT_CALL(*mock_caller_, AsyncMount(user_context_.GetUserID(),
538 cryptohome::CREATE_IF_MISSING, _)) 534 transformed_key_.GetSecret(),
535 cryptohome::CREATE_IF_MISSING,
536 _))
539 .Times(1) 537 .Times(1)
540 .RetiresOnSaturation(); 538 .RetiresOnSaturation();
541 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) 539 EXPECT_CALL(*mock_caller_,
540 AsyncGetSanitizedUsername(user_context_.GetUserID(), _))
542 .Times(1) 541 .Times(1)
543 .RetiresOnSaturation(); 542 .RetiresOnSaturation();
544 543
545 // Set up state as though a cryptohome mount attempt has occurred 544 // Set up state as though a cryptohome mount attempt has occurred
546 // and been rejected because the user doesn't exist; additionally, 545 // and been rejected because the user doesn't exist; additionally,
547 // an online auth attempt has completed successfully. 546 // an online auth attempt has completed successfully.
548 state_->PresetCryptohomeStatus(false, 547 state_->PresetCryptohomeStatus(false,
549 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); 548 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST);
550 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 549 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
551 SetAttemptState(auth_.get(), state_.release()); 550 SetAttemptState(auth_.get(), state_.release());
552 551
553 RunResolve(auth_.get()); 552 RunResolve(auth_.get());
554 } 553 }
555 554
556 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { 555 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) {
557 ExpectLoginSuccess(username_, password_, username_hash_, false); 556 ExpectLoginSuccess(user_context_);
558 FailOnLoginFailure(); 557 FailOnLoginFailure();
559 558
560 // Set up state as though a cryptohome mount attempt has occurred and 559 // Set up state as though a cryptohome mount attempt has occurred and
561 // succeeded. 560 // succeeded.
562 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 561 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
563 SetAttemptState(auth_.get(), state_.release()); 562 SetAttemptState(auth_.get(), state_.release());
564 563
565 RunResolve(auth_.get()); 564 RunResolve(auth_.get());
566 } 565 }
567 566
568 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { 567 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) {
569 ExpectLoginSuccess(username_, password_, username_hash_, false); 568 ExpectLoginSuccess(user_context_);
570 FailOnLoginFailure(); 569 FailOnLoginFailure();
571 570
572 // Set up state as though a cryptohome mount attempt has occurred and 571 // Set up state as though a cryptohome mount attempt has occurred and
573 // succeeded. 572 // succeeded.
574 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); 573 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE);
575 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); 574 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone());
576 SetAttemptState(auth_.get(), state_.release()); 575 SetAttemptState(auth_.get(), state_.release());
577 576
578 RunResolve(auth_.get()); 577 RunResolve(auth_.get());
579 } 578 }
580 579
581 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { 580 TEST_F(ParallelAuthenticatorTest, DriveUnlock) {
582 ExpectLoginSuccess(username_, std::string(), std::string(), false); 581 ExpectLoginSuccess(user_context_);
583 FailOnLoginFailure(); 582 FailOnLoginFailure();
584 583
585 // Set up mock async method caller to respond successfully to a cryptohome 584 // Set up mock async method caller to respond successfully to a cryptohome
586 // key-check attempt. 585 // key-check attempt.
587 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); 586 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
588 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) 587 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _))
589 .Times(1) 588 .Times(1)
590 .RetiresOnSaturation(); 589 .RetiresOnSaturation();
591 590
592 auth_->AuthenticateToUnlock(UserContext(username_)); 591 auth_->AuthenticateToUnlock(user_context_);
593 base::MessageLoop::current()->Run(); 592 base::MessageLoop::current()->Run();
594 } 593 }
595 594
596 } // namespace chromeos 595 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/auth/parallel_authenticator.cc ('k') | chrome/browser/chromeos/login/auth/user_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698