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

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

Issue 7562010: [ChromeOS] Fix login wrong password handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync, fix broken tests and add 3 new Created 9 years, 4 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 27 matching lines...) Expand all
38 using file_util::Delete; 38 using file_util::Delete;
39 using file_util::WriteFile; 39 using file_util::WriteFile;
40 using ::testing::AnyNumber; 40 using ::testing::AnyNumber;
41 using ::testing::DoAll; 41 using ::testing::DoAll;
42 using ::testing::Invoke; 42 using ::testing::Invoke;
43 using ::testing::Return; 43 using ::testing::Return;
44 using ::testing::SetArgumentPointee; 44 using ::testing::SetArgumentPointee;
45 using ::testing::_; 45 using ::testing::_;
46 46
47 namespace chromeos { 47 namespace chromeos {
48
48 class ResolveChecker : public base::ThreadTestHelper { 49 class ResolveChecker : public base::ThreadTestHelper {
49 public: 50 public:
50 ResolveChecker(TestAttemptState* state, 51 ResolveChecker(TestAttemptState* state,
51 ParallelAuthenticator* auth, 52 ParallelAuthenticator* auth,
52 ParallelAuthenticator::AuthState expected) 53 ParallelAuthenticator::AuthState expected)
53 : base::ThreadTestHelper( 54 : base::ThreadTestHelper(
54 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)), 55 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)),
55 state_(state), 56 state_(state),
56 auth_(auth), 57 auth_(auth),
57 expected_(expected) { 58 expected_(expected) {
58 } 59 }
59 ~ResolveChecker() {} 60 ~ResolveChecker() {}
60 61
61 virtual void RunTest() { 62 virtual void RunTest() {
62 auth_->set_attempt_state(state_); 63 auth_->set_attempt_state(state_);
63 set_test_result(expected_ == auth_->ResolveState()); 64 set_test_result(expected_ == auth_->ResolveState());
64 } 65 }
65 66
66 private: 67 private:
67 TestAttemptState* state_; 68 TestAttemptState* state_;
68 ParallelAuthenticator* auth_; 69 ParallelAuthenticator* auth_;
69 ParallelAuthenticator::AuthState expected_; 70 ParallelAuthenticator::AuthState expected_;
70 }; 71 };
71 72
73 class TestOnlineAttempt : public OnlineAttempt {
74 public:
75 TestOnlineAttempt(AuthAttemptState* state,
76 AuthAttemptStateResolver* resolver)
77 : OnlineAttempt(false, state, resolver) {
78 }
79 };
80
72 class ParallelAuthenticatorTest : public ::testing::Test { 81 class ParallelAuthenticatorTest : public ::testing::Test {
73 public: 82 public:
74 ParallelAuthenticatorTest() 83 ParallelAuthenticatorTest()
75 : message_loop_(MessageLoop::TYPE_UI), 84 : message_loop_(MessageLoop::TYPE_UI),
76 ui_thread_(BrowserThread::UI, &message_loop_), 85 ui_thread_(BrowserThread::UI, &message_loop_),
77 file_thread_(BrowserThread::FILE), 86 file_thread_(BrowserThread::FILE),
78 io_thread_(BrowserThread::IO), 87 io_thread_(BrowserThread::IO),
79 username_("me@nowhere.org"), 88 username_("me@nowhere.org"),
80 password_("fakepass") { 89 password_("fakepass") {
81 hash_ascii_.assign("0a010000000000a0"); 90 hash_ascii_.assign("0a010000000000a0");
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 BrowserThread::PostTask( 215 BrowserThread::PostTask(
207 BrowserThread::IO, FROM_HERE, 216 BrowserThread::IO, FROM_HERE,
208 NewRunnableMethod(auth, &ParallelAuthenticator::Resolve)); 217 NewRunnableMethod(auth, &ParallelAuthenticator::Resolve));
209 loop->Run(); 218 loop->Run();
210 } 219 }
211 220
212 void SetAttemptState(ParallelAuthenticator* auth, TestAttemptState* state) { 221 void SetAttemptState(ParallelAuthenticator* auth, TestAttemptState* state) {
213 auth->set_attempt_state(state); 222 auth->set_attempt_state(state);
214 } 223 }
215 224
225 void FakeOnlineAttempt() {
226 auth_->set_online_attempt(new TestOnlineAttempt(state_.get(), auth_.get()));
227 }
228
216 MessageLoop message_loop_; 229 MessageLoop message_loop_;
217 BrowserThread ui_thread_; 230 BrowserThread ui_thread_;
218 BrowserThread file_thread_; 231 BrowserThread file_thread_;
219 BrowserThread io_thread_; 232 BrowserThread io_thread_;
220 233
221 std::string username_; 234 std::string username_;
222 std::string password_; 235 std::string password_;
223 std::string hash_ascii_; 236 std::string hash_ascii_;
224 GaiaAuthConsumer::ClientLoginResult result_; 237 GaiaAuthConsumer::ClientLoginResult result_;
225 238
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 306
294 TEST_F(ParallelAuthenticatorTest, ResolveNothingDone) { 307 TEST_F(ParallelAuthenticatorTest, ResolveNothingDone) {
295 scoped_refptr<ResolveChecker> checker( 308 scoped_refptr<ResolveChecker> checker(
296 new ResolveChecker(state_.release(), 309 new ResolveChecker(state_.release(),
297 auth_.get(), 310 auth_.get(),
298 ParallelAuthenticator::CONTINUE)); 311 ParallelAuthenticator::CONTINUE));
299 EXPECT_TRUE(checker->Run()); 312 EXPECT_TRUE(checker->Run());
300 } 313 }
301 314
302 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChange) { 315 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChange) {
316 // Set a fake online attempt so that we return intermediate cryptohome state.
317 FakeOnlineAttempt();
318
303 // Set up state as though a cryptohome mount attempt has occurred 319 // Set up state as though a cryptohome mount attempt has occurred
304 // and been rejected. 320 // and been rejected.
305 state_->PresetCryptohomeStatus(false, 321 state_->PresetCryptohomeStatus(false,
306 chromeos::kCryptohomeMountErrorKeyFailure); 322 chromeos::kCryptohomeMountErrorKeyFailure);
307 scoped_refptr<ResolveChecker> checker( 323 scoped_refptr<ResolveChecker> checker(
308 new ResolveChecker(state_.release(), 324 new ResolveChecker(state_.release(),
309 auth_.get(), 325 auth_.get(),
310 ParallelAuthenticator::POSSIBLE_PW_CHANGE)); 326 ParallelAuthenticator::POSSIBLE_PW_CHANGE));
311 EXPECT_TRUE(checker->Run()); 327 EXPECT_TRUE(checker->Run());
312 } 328 }
313 329
330 TEST_F(ParallelAuthenticatorTest, ResolvePossiblePwChangeToFailedMount) {
331 // Set up state as though a cryptohome mount attempt has occurred
332 // and been rejected.
333 state_->PresetCryptohomeStatus(false,
334 chromeos::kCryptohomeMountErrorKeyFailure);
335
336 // When there is no online attempt and online results, POSSIBLE_PW_CHANGE
337 // will be resolved to FAILED_MOUNT.
338 scoped_refptr<ResolveChecker> checker(
339 new ResolveChecker(state_.release(),
340 auth_.get(),
341 ParallelAuthenticator::FAILED_MOUNT));
342 EXPECT_TRUE(checker->Run());
343 }
344
345 TEST_F(ParallelAuthenticatorTest, ResolveNeedOldPw) {
346 // Set up state as though a cryptohome mount attempt has occurred
347 // and been rejected because of unmatched key; additionally,
348 // an online auth attempt has completed successfully.
349 state_->PresetCryptohomeStatus(
350 false,
351 chromeos::kCryptohomeMountErrorKeyFailure);
352 state_->PresetOnlineLoginStatus(GaiaAuthConsumer::ClientLoginResult(),
353 LoginFailure::None());
354 scoped_refptr<ResolveChecker> checker(
355 new ResolveChecker(state_.release(),
356 auth_.get(),
357 ParallelAuthenticator::NEED_OLD_PW));
358 EXPECT_TRUE(checker->Run());
359 }
360
314 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) { 361 TEST_F(ParallelAuthenticatorTest, DriveFailedMount) {
315 FailOnLoginSuccess(); 362 FailOnLoginSuccess();
316 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); 363 ExpectLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME));
317 364
318 // Set up state as though a cryptohome mount attempt has occurred 365 // Set up state as though a cryptohome mount attempt has occurred
319 // and failed. 366 // and failed.
320 state_->PresetCryptohomeStatus(false, 0); 367 state_->PresetCryptohomeStatus(false, 0);
321 SetAttemptState(auth_, state_.release()); 368 SetAttemptState(auth_, state_.release());
322 369
323 RunResolve(auth_.get(), &message_loop_); 370 RunResolve(auth_.get(), &message_loop_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 436
390 auth_->ResyncEncryptedData(result_); 437 auth_->ResyncEncryptedData(result_);
391 message_loop_.Run(); 438 message_loop_.Run();
392 } 439 }
393 440
394 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) { 441 TEST_F(ParallelAuthenticatorTest, DriveRequestOldPassword) {
395 FailOnLoginSuccess(); 442 FailOnLoginSuccess();
396 ExpectPasswordChange(); 443 ExpectPasswordChange();
397 444
398 state_->PresetCryptohomeStatus(false, 445 state_->PresetCryptohomeStatus(false,
399 chromeos::kCryptohomeMountErrorKeyFailure); 446 chromeos::kCryptohomeMountErrorKeyFailure);
400 state_->PresetOnlineLoginStatus(result_, LoginFailure::None()); 447 state_->PresetOnlineLoginStatus(result_, LoginFailure::None());
401 SetAttemptState(auth_, state_.release()); 448 SetAttemptState(auth_, state_.release());
402 449
403 RunResolve(auth_.get(), &message_loop_); 450 RunResolve(auth_.get(), &message_loop_);
404 } 451 }
405 452
406 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { 453 TEST_F(ParallelAuthenticatorTest, DriveDataRecover) {
407 ExpectLoginSuccess(username_, password_, result_, false); 454 ExpectLoginSuccess(username_, password_, result_, false);
408 FailOnLoginFailure(); 455 FailOnLoginFailure();
409 456
(...skipping 30 matching lines...) Expand all
440 .WillOnce(Return(CryptohomeBlob(2, 0))) 487 .WillOnce(Return(CryptohomeBlob(2, 0)))
441 .RetiresOnSaturation(); 488 .RetiresOnSaturation();
442 489
443 SetAttemptState(auth_, state_.release()); 490 SetAttemptState(auth_, state_.release());
444 491
445 auth_->RecoverEncryptedData(std::string(), result_); 492 auth_->RecoverEncryptedData(std::string(), result_);
446 message_loop_.Run(); 493 message_loop_.Run();
447 } 494 }
448 495
449 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) { 496 TEST_F(ParallelAuthenticatorTest, ResolveNoMount) {
497 // Set a fake online attempt so that we return intermediate cryptohome state.
498 FakeOnlineAttempt();
499
450 // Set up state as though a cryptohome mount attempt has occurred 500 // Set up state as though a cryptohome mount attempt has occurred
451 // and been rejected because the user doesn't exist. 501 // and been rejected because the user doesn't exist.
452 state_->PresetCryptohomeStatus( 502 state_->PresetCryptohomeStatus(
453 false, 503 false,
454 chromeos::kCryptohomeMountErrorUserDoesNotExist); 504 chromeos::kCryptohomeMountErrorUserDoesNotExist);
455 scoped_refptr<ResolveChecker> checker( 505 scoped_refptr<ResolveChecker> checker(
456 new ResolveChecker(state_.release(), 506 new ResolveChecker(state_.release(),
457 auth_.get(), 507 auth_.get(),
458 ParallelAuthenticator::NO_MOUNT)); 508 ParallelAuthenticator::NO_MOUNT));
459 EXPECT_TRUE(checker->Run()); 509 EXPECT_TRUE(checker->Run());
460 } 510 }
461 511
512 TEST_F(ParallelAuthenticatorTest, ResolveNoMountToFailedMount) {
513 // Set up state as though a cryptohome mount attempt has occurred
514 // and been rejected because the user doesn't exist.
515 state_->PresetCryptohomeStatus(
516 false,
517 chromeos::kCryptohomeMountErrorUserDoesNotExist);
518
519 // When there is no online attempt and online results, NO_MOUNT will be
520 // resolved to FAILED_MOUNT.
521 scoped_refptr<ResolveChecker> checker(
522 new ResolveChecker(state_.release(),
523 auth_.get(),
524 ParallelAuthenticator::FAILED_MOUNT));
525 EXPECT_TRUE(checker->Run());
526 }
527
462 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) { 528 TEST_F(ParallelAuthenticatorTest, ResolveCreateNew) {
463 // Set up state as though a cryptohome mount attempt has occurred 529 // Set up state as though a cryptohome mount attempt has occurred
464 // and been rejected because the user doesn't exist; additionally, 530 // and been rejected because the user doesn't exist; additionally,
465 // an online auth attempt has completed successfully. 531 // an online auth attempt has completed successfully.
466 state_->PresetCryptohomeStatus( 532 state_->PresetCryptohomeStatus(
467 false, 533 false,
468 chromeos::kCryptohomeMountErrorUserDoesNotExist); 534 chromeos::kCryptohomeMountErrorUserDoesNotExist);
469 state_->PresetOnlineLoginStatus(GaiaAuthConsumer::ClientLoginResult(), 535 state_->PresetOnlineLoginStatus(GaiaAuthConsumer::ClientLoginResult(),
470 LoginFailure::None()); 536 LoginFailure::None());
471 scoped_refptr<ResolveChecker> checker( 537 scoped_refptr<ResolveChecker> checker(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 FilePath tmp_file_path = FakeLocalaccountFile(username_); 790 FilePath tmp_file_path = FakeLocalaccountFile(username_);
725 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value()); 791 ReadLocalaccountFile(auth_.get(), tmp_file_path.BaseName().value());
726 792
727 auth_->AuthenticateToUnlock(username_, ""); 793 auth_->AuthenticateToUnlock(username_, "");
728 message_loop_.Run(); 794 message_loop_.Run();
729 795
730 Delete(tmp_file_path, false); 796 Delete(tmp_file_path, false);
731 } 797 }
732 798
733 } // namespace chromeos 799 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/parallel_authenticator.cc ('k') | chrome/browser/resources/chromeos/login/oobe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698