OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/parallel_authenticator.h" | 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { | 228 TEST_F(ParallelAuthenticatorTest, OnLoginSuccess) { |
229 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, | 229 EXPECT_CALL(consumer_, OnLoginSuccess(UserContext(username_, |
230 password_, | 230 password_, |
231 std::string(), | 231 std::string(), |
232 username_hash_), | 232 username_hash_), |
233 false, false)) | 233 false, false)) |
234 .Times(1) | 234 .Times(1) |
235 .RetiresOnSaturation(); | 235 .RetiresOnSaturation(); |
236 | 236 |
237 SetAttemptState(auth_, state_.release()); | 237 SetAttemptState(auth_.get(), state_.release()); |
238 auth_->OnLoginSuccess(false); | 238 auth_->OnLoginSuccess(false); |
239 } | 239 } |
240 | 240 |
241 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { | 241 TEST_F(ParallelAuthenticatorTest, OnPasswordChangeDetected) { |
242 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) | 242 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) |
243 .Times(1) | 243 .Times(1) |
244 .RetiresOnSaturation(); | 244 .RetiresOnSaturation(); |
245 SetAttemptState(auth_, state_.release()); | 245 SetAttemptState(auth_.get(), state_.release()); |
246 auth_->OnPasswordChangeDetected(); | 246 auth_->OnPasswordChangeDetected(); |
247 } | 247 } |
248 | 248 |
249 TEST_F(ParallelAuthenticatorTest, ResolveNothingDone) { | 249 TEST_F(ParallelAuthenticatorTest, ResolveNothingDone) { |
250 EXPECT_EQ(ParallelAuthenticator::CONTINUE, | 250 EXPECT_EQ(ParallelAuthenticator::CONTINUE, |
251 SetAndResolveState(auth_, state_.release())); | 251 SetAndResolveState(auth_.get(), state_.release())); |
252 } | 252 } |
253 | 253 |
254 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChange) { | 254 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChange) { |
255 // Set a fake online attempt so that we return intermediate cryptohome state. | 255 // Set a fake online attempt so that we return intermediate cryptohome state. |
256 FakeOnlineAttempt(); | 256 FakeOnlineAttempt(); |
257 | 257 |
258 // Set up state as though a cryptohome mount attempt has occurred | 258 // Set up state as though a cryptohome mount attempt has occurred |
259 // and been rejected. | 259 // and been rejected. |
260 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 260 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
261 | 261 |
262 EXPECT_EQ(ParallelAuthenticator::POSSIBLE_PW_CHANGE, | 262 EXPECT_EQ(ParallelAuthenticator::POSSIBLE_PW_CHANGE, |
263 SetAndResolveState(auth_, state_.release())); | 263 SetAndResolveState(auth_.get(), state_.release())); |
264 } | 264 } |
265 | 265 |
266 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChangeToFailedMount) { | 266 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChangeToFailedMount) { |
267 // Set up state as though a cryptohome mount attempt has occurred | 267 // Set up state as though a cryptohome mount attempt has occurred |
268 // and been rejected. | 268 // and been rejected. |
269 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 269 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
270 | 270 |
271 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE | 271 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE |
272 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, | 272 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, |
273 SetAndResolveState(auth_, state_.release())); | 273 SetAndResolveState(auth_.get(), state_.release())); |
274 } | 274 } |
275 | 275 |
276 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) { | 276 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) { |
277 // Set up state as though a cryptohome mount attempt has occurred | 277 // Set up state as though a cryptohome mount attempt has occurred |
278 // and been rejected because of unmatched key; additionally, | 278 // and been rejected because of unmatched key; additionally, |
279 // an online auth attempt has completed successfully. | 279 // an online auth attempt has completed successfully. |
280 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 280 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
281 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 281 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
282 | 282 |
283 EXPECT_EQ(ParallelAuthenticator::NEED_OLD_PW, | 283 EXPECT_EQ(ParallelAuthenticator::NEED_OLD_PW, |
284 SetAndResolveState(auth_, state_.release())); | 284 SetAndResolveState(auth_.get(), state_.release())); |
285 } | 285 } |
286 | 286 |
287 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) { | 287 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededDirectFailedMount) { |
288 // Set up state as though a cryptohome mount attempt has occurred | 288 // Set up state as though a cryptohome mount attempt has occurred |
289 // and succeeded but we are in safe mode and the current user is not owner. | 289 // and succeeded but we are in safe mode and the current user is not owner. |
290 // This is a high level test to verify the proper transitioning in this mode | 290 // This is a high level test to verify the proper transitioning in this mode |
291 // only. It is not testing that we properly verify that the user is an owner | 291 // only. It is not testing that we properly verify that the user is an owner |
292 // or that we really are in "safe-mode". | 292 // or that we really are in "safe-mode". |
293 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 293 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
294 SetOwnerState(true, false); | 294 SetOwnerState(true, false); |
295 | 295 |
296 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, | 296 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, |
297 SetAndResolveState(auth_, state_.release())); | 297 SetAndResolveState(auth_.get(), state_.release())); |
298 } | 298 } |
299 | 299 |
300 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { | 300 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededMount) { |
301 // Set up state as though a cryptohome mount attempt has occurred | 301 // Set up state as though a cryptohome mount attempt has occurred |
302 // and succeeded but we are in safe mode and the current user is not owner. | 302 // and succeeded but we are in safe mode and the current user is not owner. |
303 // This test will check that the "safe-mode" policy is not set and will let | 303 // This test will check that the "safe-mode" policy is not set and will let |
304 // the mount finish successfully. | 304 // the mount finish successfully. |
305 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 305 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
306 SetOwnerState(false, false); | 306 SetOwnerState(false, false); |
307 // and test that the mount has succeeded. | 307 // and test that the mount has succeeded. |
308 state_.reset(new TestAttemptState(UserContext(username_, | 308 state_.reset(new TestAttemptState(UserContext(username_, |
309 password_, | 309 password_, |
310 std::string()), | 310 std::string()), |
311 hash_ascii_, | 311 hash_ascii_, |
312 "", | 312 "", |
313 "", | 313 "", |
314 User::USER_TYPE_REGULAR, | 314 User::USER_TYPE_REGULAR, |
315 false)); | 315 false)); |
316 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 316 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
317 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, | 317 EXPECT_EQ(ParallelAuthenticator::OFFLINE_LOGIN, |
318 SetAndResolveState(auth_, state_.release())); | 318 SetAndResolveState(auth_.get(), state_.release())); |
319 } | 319 } |
320 | 320 |
321 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { | 321 TEST_F(ParallelAuthenticatorTest, ResolveOwnerNeededFailedMount) { |
322 FailOnLoginSuccess(); // Set failing on success as the default... | 322 FailOnLoginSuccess(); // Set failing on success as the default... |
323 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); | 323 LoginFailure failure = LoginFailure(LoginFailure::OWNER_REQUIRED); |
324 ExpectLoginFailure(failure); | 324 ExpectLoginFailure(failure); |
325 | 325 |
326 MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager = | 326 MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager = |
327 new MockDBusThreadManagerWithoutGMock; | 327 new MockDBusThreadManagerWithoutGMock; |
328 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | 328 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
(...skipping 10 matching lines...) Expand all Loading... |
339 // Remove the real DeviceSettingsProvider and replace it with a stub. | 339 // Remove the real DeviceSettingsProvider and replace it with a stub. |
340 device_settings_provider = | 340 device_settings_provider = |
341 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); | 341 CrosSettings::Get()->GetProvider(chromeos::kReportDeviceVersionInfo); |
342 EXPECT_TRUE(device_settings_provider != NULL); | 342 EXPECT_TRUE(device_settings_provider != NULL); |
343 EXPECT_TRUE( | 343 EXPECT_TRUE( |
344 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); | 344 CrosSettings::Get()->RemoveSettingsProvider(device_settings_provider)); |
345 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); | 345 CrosSettings::Get()->AddSettingsProvider(&stub_settings_provider); |
346 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); | 346 CrosSettings::Get()->SetBoolean(kPolicyMissingMitigationMode, true); |
347 | 347 |
348 EXPECT_EQ(ParallelAuthenticator::CONTINUE, | 348 EXPECT_EQ(ParallelAuthenticator::CONTINUE, |
349 SetAndResolveState(auth_, state_.release())); | 349 SetAndResolveState(auth_.get(), state_.release())); |
350 // Let the owner verification run. | 350 // Let the owner verification run. |
351 device_settings_test_helper_.Flush(); | 351 device_settings_test_helper_.Flush(); |
352 // and test that the mount has succeeded. | 352 // and test that the mount has succeeded. |
353 state_.reset(new TestAttemptState(UserContext(username_, | 353 state_.reset(new TestAttemptState(UserContext(username_, |
354 password_, | 354 password_, |
355 std::string()), | 355 std::string()), |
356 hash_ascii_, | 356 hash_ascii_, |
357 "", | 357 "", |
358 "", | 358 "", |
359 User::USER_TYPE_REGULAR, | 359 User::USER_TYPE_REGULAR, |
360 false)); | 360 false)); |
361 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 361 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
362 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, | 362 EXPECT_EQ(ParallelAuthenticator::OWNER_REQUIRED, |
363 SetAndResolveState(auth_, state_.release())); | 363 SetAndResolveState(auth_.get(), state_.release())); |
364 | 364 |
365 EXPECT_TRUE( | 365 EXPECT_TRUE( |
366 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); | 366 CrosSettings::Get()->RemoveSettingsProvider(&stub_settings_provider)); |
367 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); | 367 CrosSettings::Get()->AddSettingsProvider(device_settings_provider); |
368 DBusThreadManager::Get()->Shutdown(); | 368 DBusThreadManager::Get()->Shutdown(); |
369 } | 369 } |
370 | 370 |
371 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { | 371 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { |
372 FailOnLoginSuccess(); | 372 FailOnLoginSuccess(); |
373 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); | 373 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); |
374 | 374 |
375 // Set up state as though a cryptohome mount attempt has occurred | 375 // Set up state as though a cryptohome mount attempt has occurred |
376 // and failed. | 376 // and failed. |
377 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE); | 377 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_NONE); |
378 SetAttemptState(auth_, state_.release()); | 378 SetAttemptState(auth_.get(), state_.release()); |
379 | 379 |
380 RunResolve(auth_.get()); | 380 RunResolve(auth_.get()); |
381 } | 381 } |
382 | 382 |
383 TEST_F(ParallelAuthenticatorTest, DriveGuestLogin) { | 383 TEST_F(ParallelAuthenticatorTest, DriveGuestLogin) { |
384 ExpectGuestLoginSuccess(); | 384 ExpectGuestLoginSuccess(); |
385 FailOnLoginFailure(); | 385 FailOnLoginFailure(); |
386 | 386 |
387 // Set up mock cryptohome library to respond as though a tmpfs mount | 387 // Set up mock cryptohome library to respond as though a tmpfs mount |
388 // attempt has occurred and succeeded. | 388 // attempt has occurred and succeeded. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 .RetiresOnSaturation(); | 456 .RetiresOnSaturation(); |
457 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 457 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
458 cryptohome::CREATE_IF_MISSING, _)) | 458 cryptohome::CREATE_IF_MISSING, _)) |
459 .Times(1) | 459 .Times(1) |
460 .RetiresOnSaturation(); | 460 .RetiresOnSaturation(); |
461 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) | 461 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) |
462 .Times(1) | 462 .Times(1) |
463 .RetiresOnSaturation(); | 463 .RetiresOnSaturation(); |
464 | 464 |
465 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 465 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
466 SetAttemptState(auth_, state_.release()); | 466 SetAttemptState(auth_.get(), state_.release()); |
467 | 467 |
468 auth_->ResyncEncryptedData(); | 468 auth_->ResyncEncryptedData(); |
469 message_loop_.Run(); | 469 message_loop_.Run(); |
470 } | 470 } |
471 | 471 |
472 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { | 472 TEST_F(ParallelAuthenticatorTest, DriveResyncFail) { |
473 FailOnLoginSuccess(); | 473 FailOnLoginSuccess(); |
474 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)); | 474 ExpectLoginFailure(LoginFailure(LoginFailure::DATA_REMOVAL_FAILED)); |
475 | 475 |
476 // Set up mock cryptohome library to fail a cryptohome remove attempt. | 476 // Set up mock cryptohome library to fail a cryptohome remove attempt. |
477 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 477 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
478 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) | 478 EXPECT_CALL(*mock_caller_, AsyncRemove(username_, _)) |
479 .Times(1) | 479 .Times(1) |
480 .RetiresOnSaturation(); | 480 .RetiresOnSaturation(); |
481 | 481 |
482 SetAttemptState(auth_, state_.release()); | 482 SetAttemptState(auth_.get(), state_.release()); |
483 | 483 |
484 auth_->ResyncEncryptedData(); | 484 auth_->ResyncEncryptedData(); |
485 message_loop_.Run(); | 485 message_loop_.Run(); |
486 } | 486 } |
487 | 487 |
488 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { | 488 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { |
489 FailOnLoginSuccess(); | 489 FailOnLoginSuccess(); |
490 ExpectPasswordChange(); | 490 ExpectPasswordChange(); |
491 | 491 |
492 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 492 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
493 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 493 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
494 SetAttemptState(auth_, state_.release()); | 494 SetAttemptState(auth_.get(), state_.release()); |
495 | 495 |
496 RunResolve(auth_.get()); | 496 RunResolve(auth_.get()); |
497 } | 497 } |
498 | 498 |
499 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { | 499 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { |
500 ExpectLoginSuccess(username_, | 500 ExpectLoginSuccess(username_, |
501 password_, | 501 password_, |
502 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, | 502 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, |
503 false); | 503 false); |
504 FailOnLoginFailure(); | 504 FailOnLoginFailure(); |
505 | 505 |
506 // Set up mock cryptohome library to respond successfully to a key migration. | 506 // Set up mock cryptohome library to respond successfully to a key migration. |
507 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 507 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
508 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 508 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
509 .Times(1) | 509 .Times(1) |
510 .RetiresOnSaturation(); | 510 .RetiresOnSaturation(); |
511 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 511 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
512 cryptohome::MOUNT_FLAGS_NONE, _)) | 512 cryptohome::MOUNT_FLAGS_NONE, _)) |
513 .Times(1) | 513 .Times(1) |
514 .RetiresOnSaturation(); | 514 .RetiresOnSaturation(); |
515 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) | 515 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) |
516 .Times(1) | 516 .Times(1) |
517 .RetiresOnSaturation(); | 517 .RetiresOnSaturation(); |
518 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 518 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
519 .WillOnce(Return(std::string())) | 519 .WillOnce(Return(std::string())) |
520 .RetiresOnSaturation(); | 520 .RetiresOnSaturation(); |
521 | 521 |
522 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 522 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
523 SetAttemptState(auth_, state_.release()); | 523 SetAttemptState(auth_.get(), state_.release()); |
524 | 524 |
525 auth_->RecoverEncryptedData(std::string()); | 525 auth_->RecoverEncryptedData(std::string()); |
526 message_loop_.Run(); | 526 message_loop_.Run(); |
527 } | 527 } |
528 | 528 |
529 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { | 529 TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { |
530 FailOnLoginSuccess(); | 530 FailOnLoginSuccess(); |
531 ExpectPasswordChange(); | 531 ExpectPasswordChange(); |
532 | 532 |
533 // Set up mock cryptohome library to fail a key migration attempt, | 533 // Set up mock cryptohome library to fail a key migration attempt, |
534 // asserting that the wrong password was used. | 534 // asserting that the wrong password was used. |
535 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 535 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
536 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) | 536 EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) |
537 .Times(1) | 537 .Times(1) |
538 .RetiresOnSaturation(); | 538 .RetiresOnSaturation(); |
539 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 539 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
540 .WillOnce(Return(std::string())) | 540 .WillOnce(Return(std::string())) |
541 .RetiresOnSaturation(); | 541 .RetiresOnSaturation(); |
542 | 542 |
543 SetAttemptState(auth_, state_.release()); | 543 SetAttemptState(auth_.get(), state_.release()); |
544 | 544 |
545 auth_->RecoverEncryptedData(std::string()); | 545 auth_->RecoverEncryptedData(std::string()); |
546 message_loop_.Run(); | 546 message_loop_.Run(); |
547 } | 547 } |
548 | 548 |
549 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { | 549 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { |
550 // Set a fake online attempt so that we return intermediate cryptohome state. | 550 // Set a fake online attempt so that we return intermediate cryptohome state. |
551 FakeOnlineAttempt(); | 551 FakeOnlineAttempt(); |
552 | 552 |
553 // Set up state as though a cryptohome mount attempt has occurred | 553 // Set up state as though a cryptohome mount attempt has occurred |
554 // and been rejected because the user doesn't exist. | 554 // and been rejected because the user doesn't exist. |
555 state_->PresetCryptohomeStatus(false, | 555 state_->PresetCryptohomeStatus(false, |
556 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 556 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
557 | 557 |
558 EXPECT_EQ(ParallelAuthenticator::NO_MOUNT, | 558 EXPECT_EQ(ParallelAuthenticator::NO_MOUNT, |
559 SetAndResolveState(auth_, state_.release())); | 559 SetAndResolveState(auth_.get(), state_.release())); |
560 } | 560 } |
561 | 561 |
562 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) { | 562 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) { |
563 // Set up state as though a cryptohome mount attempt has occurred | 563 // Set up state as though a cryptohome mount attempt has occurred |
564 // and been rejected because the user doesn't exist. | 564 // and been rejected because the user doesn't exist. |
565 state_->PresetCryptohomeStatus(false, | 565 state_->PresetCryptohomeStatus(false, |
566 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 566 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
567 | 567 |
568 // When there is no online attempt and online results, NO_MOUNT will be | 568 // When there is no online attempt and online results, NO_MOUNT will be |
569 // resolved to FAILED_MOUNT. | 569 // resolved to FAILED_MOUNT. |
570 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, | 570 EXPECT_EQ(ParallelAuthenticator::FAILED_MOUNT, |
571 SetAndResolveState(auth_, state_.release())); | 571 SetAndResolveState(auth_.get(), state_.release())); |
572 } | 572 } |
573 | 573 |
574 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { | 574 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { |
575 // Set up state as though a cryptohome mount attempt has occurred | 575 // Set up state as though a cryptohome mount attempt has occurred |
576 // and been rejected because the user doesn't exist; additionally, | 576 // and been rejected because the user doesn't exist; additionally, |
577 // an online auth attempt has completed successfully. | 577 // an online auth attempt has completed successfully. |
578 state_->PresetCryptohomeStatus(false, | 578 state_->PresetCryptohomeStatus(false, |
579 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 579 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
580 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 580 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
581 | 581 |
582 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, | 582 EXPECT_EQ(ParallelAuthenticator::CREATE_NEW, |
583 SetAndResolveState(auth_, state_.release())); | 583 SetAndResolveState(auth_.get(), state_.release())); |
584 } | 584 } |
585 | 585 |
586 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { | 586 TEST_F(ParallelAuthenticatorTest, DriveCreateForNewUser) { |
587 ExpectLoginSuccess(username_, | 587 ExpectLoginSuccess(username_, |
588 password_, | 588 password_, |
589 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, | 589 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername, |
590 false); | 590 false); |
591 FailOnLoginFailure(); | 591 FailOnLoginFailure(); |
592 | 592 |
593 // Set up mock cryptohome library to respond successfully to a cryptohome | 593 // Set up mock cryptohome library to respond successfully to a cryptohome |
594 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). | 594 // create attempt (indicated by the |CREATE_IF_MISSING| flag to AsyncMount). |
595 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 595 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
596 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, | 596 EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, |
597 cryptohome::CREATE_IF_MISSING, _)) | 597 cryptohome::CREATE_IF_MISSING, _)) |
598 .Times(1) | 598 .Times(1) |
599 .RetiresOnSaturation(); | 599 .RetiresOnSaturation(); |
600 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) | 600 EXPECT_CALL(*mock_caller_, AsyncGetSanitizedUsername(username_, _)) |
601 .Times(1) | 601 .Times(1) |
602 .RetiresOnSaturation(); | 602 .RetiresOnSaturation(); |
603 | 603 |
604 // Set up state as though a cryptohome mount attempt has occurred | 604 // Set up state as though a cryptohome mount attempt has occurred |
605 // and been rejected because the user doesn't exist; additionally, | 605 // and been rejected because the user doesn't exist; additionally, |
606 // an online auth attempt has completed successfully. | 606 // an online auth attempt has completed successfully. |
607 state_->PresetCryptohomeStatus(false, | 607 state_->PresetCryptohomeStatus(false, |
608 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 608 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
609 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 609 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
610 SetAttemptState(auth_, state_.release()); | 610 SetAttemptState(auth_.get(), state_.release()); |
611 | 611 |
612 RunResolve(auth_.get()); | 612 RunResolve(auth_.get()); |
613 } | 613 } |
614 | 614 |
615 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { | 615 TEST_F(ParallelAuthenticatorTest, DriveOfflineLogin) { |
616 ExpectLoginSuccess(username_, password_, username_hash_, false); | 616 ExpectLoginSuccess(username_, password_, username_hash_, false); |
617 FailOnLoginFailure(); | 617 FailOnLoginFailure(); |
618 | 618 |
619 // Set up state as though a cryptohome mount attempt has occurred and | 619 // Set up state as though a cryptohome mount attempt has occurred and |
620 // succeeded. | 620 // succeeded. |
621 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 621 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
622 GoogleServiceAuthError error = | 622 GoogleServiceAuthError error = |
623 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET); | 623 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET); |
624 state_->PresetOnlineLoginStatus(LoginFailure::FromNetworkAuthFailure(error)); | 624 state_->PresetOnlineLoginStatus(LoginFailure::FromNetworkAuthFailure(error)); |
625 SetAttemptState(auth_, state_.release()); | 625 SetAttemptState(auth_.get(), state_.release()); |
626 | 626 |
627 RunResolve(auth_.get()); | 627 RunResolve(auth_.get()); |
628 } | 628 } |
629 | 629 |
630 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginDelayedOnline) { | 630 TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginDelayedOnline) { |
631 ExpectLoginSuccess(username_, password_, username_hash_, true); | 631 ExpectLoginSuccess(username_, password_, username_hash_, true); |
632 FailOnLoginFailure(); | 632 FailOnLoginFailure(); |
633 | 633 |
634 // Set up state as though a cryptohome mount attempt has occurred and | 634 // Set up state as though a cryptohome mount attempt has occurred and |
635 // succeeded. | 635 // succeeded. |
636 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 636 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
637 // state_ is released further down. | 637 // state_ is released further down. |
638 SetAttemptState(auth_, state_.get()); | 638 SetAttemptState(auth_.get(), state_.get()); |
639 RunResolve(auth_.get()); | 639 RunResolve(auth_.get()); |
640 | 640 |
641 // Offline login has completed, so now we "complete" the online request. | 641 // Offline login has completed, so now we "complete" the online request. |
642 GoogleServiceAuthError error( | 642 GoogleServiceAuthError error( |
643 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 643 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
644 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); | 644 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); |
645 state_.release()->PresetOnlineLoginStatus(failure); | 645 state_.release()->PresetOnlineLoginStatus(failure); |
646 ExpectLoginFailure(failure); | 646 ExpectLoginFailure(failure); |
647 | 647 |
648 RunResolve(auth_.get()); | 648 RunResolve(auth_.get()); |
(...skipping 12 matching lines...) Expand all Loading... |
661 .Times(1) | 661 .Times(1) |
662 .RetiresOnSaturation(); | 662 .RetiresOnSaturation(); |
663 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 663 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
664 .WillOnce(Return(std::string())) | 664 .WillOnce(Return(std::string())) |
665 .RetiresOnSaturation(); | 665 .RetiresOnSaturation(); |
666 | 666 |
667 // Set up state as though a cryptohome mount attempt has occurred and | 667 // Set up state as though a cryptohome mount attempt has occurred and |
668 // succeeded; also, an online request that never made it. | 668 // succeeded; also, an online request that never made it. |
669 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 669 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
670 // state_ is released further down. | 670 // state_ is released further down. |
671 SetAttemptState(auth_, state_.get()); | 671 SetAttemptState(auth_.get(), state_.get()); |
672 RunResolve(auth_.get()); | 672 RunResolve(auth_.get()); |
673 | 673 |
674 // Offline login has completed, so now we "complete" the online request. | 674 // Offline login has completed, so now we "complete" the online request. |
675 GoogleServiceAuthError error( | 675 GoogleServiceAuthError error( |
676 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 676 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
677 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); | 677 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); |
678 state_.release()->PresetOnlineLoginStatus(failure); | 678 state_.release()->PresetOnlineLoginStatus(failure); |
679 ExpectLoginFailure(failure); | 679 ExpectLoginFailure(failure); |
680 | 680 |
681 RunResolve(auth_.get()); | 681 RunResolve(auth_.get()); |
(...skipping 18 matching lines...) Expand all Loading... |
700 ExpectLoginSuccess(username_, password_, username_hash_, true); | 700 ExpectLoginSuccess(username_, password_, username_hash_, true); |
701 FailOnLoginFailure(); | 701 FailOnLoginFailure(); |
702 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 702 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
703 .WillOnce(Return(std::string())) | 703 .WillOnce(Return(std::string())) |
704 .RetiresOnSaturation(); | 704 .RetiresOnSaturation(); |
705 | 705 |
706 // Set up state as though a cryptohome mount attempt has occurred and | 706 // Set up state as though a cryptohome mount attempt has occurred and |
707 // succeeded; also, an online request that never made it. | 707 // succeeded; also, an online request that never made it. |
708 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 708 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
709 // state_ is released further down. | 709 // state_ is released further down. |
710 SetAttemptState(auth_, state_.get()); | 710 SetAttemptState(auth_.get(), state_.get()); |
711 RunResolve(auth_.get()); | 711 RunResolve(auth_.get()); |
712 | 712 |
713 // Offline login has completed, so now we "complete" the online request. | 713 // Offline login has completed, so now we "complete" the online request. |
714 GoogleServiceAuthError error( | 714 GoogleServiceAuthError error( |
715 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 715 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
716 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); | 716 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); |
717 state_.release()->PresetOnlineLoginStatus(failure); | 717 state_.release()->PresetOnlineLoginStatus(failure); |
718 ExpectLoginFailure(failure); | 718 ExpectLoginFailure(failure); |
719 | 719 |
720 RunResolve(auth_.get()); | 720 RunResolve(auth_.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
741 } | 741 } |
742 | 742 |
743 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { | 743 TEST_F(ParallelAuthenticatorTest, DriveOnlineLogin) { |
744 ExpectLoginSuccess(username_, password_, username_hash_, false); | 744 ExpectLoginSuccess(username_, password_, username_hash_, false); |
745 FailOnLoginFailure(); | 745 FailOnLoginFailure(); |
746 | 746 |
747 // Set up state as though a cryptohome mount attempt has occurred and | 747 // Set up state as though a cryptohome mount attempt has occurred and |
748 // succeeded. | 748 // succeeded. |
749 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 749 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
750 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); | 750 state_->PresetOnlineLoginStatus(LoginFailure::LoginFailureNone()); |
751 SetAttemptState(auth_, state_.release()); | 751 SetAttemptState(auth_.get(), state_.release()); |
752 | 752 |
753 RunResolve(auth_.get()); | 753 RunResolve(auth_.get()); |
754 } | 754 } |
755 | 755 |
756 // http://crbug.com/106538 | 756 // http://crbug.com/106538 |
757 TEST_F(ParallelAuthenticatorTest, DISABLED_DriveNeedNewPassword) { | 757 TEST_F(ParallelAuthenticatorTest, DISABLED_DriveNeedNewPassword) { |
758 FailOnLoginSuccess(); // Set failing on success as the default... | 758 FailOnLoginSuccess(); // Set failing on success as the default... |
759 // ...but expect ONE successful login first. | 759 // ...but expect ONE successful login first. |
760 ExpectLoginSuccess(username_, password_, username_hash_, true); | 760 ExpectLoginSuccess(username_, password_, username_hash_, true); |
761 GoogleServiceAuthError error( | 761 GoogleServiceAuthError error( |
762 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 762 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
763 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); | 763 LoginFailure failure = LoginFailure::FromNetworkAuthFailure(error); |
764 ExpectLoginFailure(failure); | 764 ExpectLoginFailure(failure); |
765 | 765 |
766 // Set up state as though a cryptohome mount attempt has occurred and | 766 // Set up state as though a cryptohome mount attempt has occurred and |
767 // succeeded. | 767 // succeeded. |
768 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 768 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
769 state_->PresetOnlineLoginStatus(failure); | 769 state_->PresetOnlineLoginStatus(failure); |
770 SetAttemptState(auth_, state_.release()); | 770 SetAttemptState(auth_.get(), state_.release()); |
771 | 771 |
772 RunResolve(auth_.get()); | 772 RunResolve(auth_.get()); |
773 } | 773 } |
774 | 774 |
775 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { | 775 TEST_F(ParallelAuthenticatorTest, DriveUnlock) { |
776 ExpectLoginSuccess(username_, std::string(), std::string(), false); | 776 ExpectLoginSuccess(username_, std::string(), std::string(), false); |
777 FailOnLoginFailure(); | 777 FailOnLoginFailure(); |
778 | 778 |
779 // Set up mock cryptohome library to respond successfully to a cryptohome | 779 // Set up mock cryptohome library to respond successfully to a cryptohome |
780 // key-check attempt. | 780 // key-check attempt. |
781 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 781 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
782 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) | 782 EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) |
783 .Times(1) | 783 .Times(1) |
784 .RetiresOnSaturation(); | 784 .RetiresOnSaturation(); |
785 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) | 785 EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt()) |
786 .WillOnce(Return(std::string())) | 786 .WillOnce(Return(std::string())) |
787 .RetiresOnSaturation(); | 787 .RetiresOnSaturation(); |
788 | 788 |
789 auth_->AuthenticateToUnlock(UserContext(username_, | 789 auth_->AuthenticateToUnlock(UserContext(username_, |
790 std::string(), | 790 std::string(), |
791 std::string())); | 791 std::string())); |
792 message_loop_.Run(); | 792 message_loop_.Run(); |
793 } | 793 } |
794 | 794 |
795 } // namespace chromeos | 795 } // namespace chromeos |
OLD | NEW |