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

Side by Side Diff: components/password_manager/core/browser/login_database_unittest.cc

Issue 169173005: Update incomplete credentials in Login Database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compilation fix for newer master Created 6 years, 10 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
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 "components/password_manager/core/browser/login_database.h" 5 #include "components/password_manager/core/browser/login_database.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // Normal data. 619 // Normal data.
620 vec.push_back(ASCIIToUTF16("first")); 620 vec.push_back(ASCIIToUTF16("first"));
621 vec.push_back(ASCIIToUTF16("second")); 621 vec.push_back(ASCIIToUTF16("second"));
622 vec.push_back(ASCIIToUTF16("third")); 622 vec.push_back(ASCIIToUTF16("third"));
623 623
624 temp = SerializeVector(vec); 624 temp = SerializeVector(vec);
625 output = DeserializeVector(temp); 625 output = DeserializeVector(temp);
626 EXPECT_THAT(output, Eq(vec)); 626 EXPECT_THAT(output, Eq(vec));
627 } 627 }
628 628
629 TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) {
630 std::vector<autofill::PasswordForm*> result;
631 // Verify the database is empty.
632 EXPECT_TRUE(db_.GetAutofillableLogins(&result));
633 ASSERT_EQ(0U, result.size());
634
635 // Save an incomplete form. Note that it only has a few fields set, ex. it's
636 // missing 'action', 'username_element' and 'password_element'. Such forms
637 // are sometimes inserted during import from other browsers (which may not
638 // store this info).
639 PasswordForm incomplete_form;
640 incomplete_form.origin = GURL("http://accounts.google.com/LoginAuth");
641 incomplete_form.signon_realm = "http://accounts.google.com/";
642 incomplete_form.username_value = ASCIIToUTF16("my_username");
643 incomplete_form.password_value = ASCIIToUTF16("my_password");
644 incomplete_form.ssl_valid = false;
645 incomplete_form.preferred = true;
646 incomplete_form.blacklisted_by_user = false;
647 incomplete_form.scheme = PasswordForm::SCHEME_HTML;
648 EXPECT_TRUE(db_.AddLogin(incomplete_form));
649
650 // A form on some website. It should trigger a match with the stored one.
651 PasswordForm encountered_form;
652 encountered_form.origin = GURL("http://accounts.google.com/LoginAuth");
653 encountered_form.signon_realm = "http://accounts.google.com/";
654 encountered_form.action = GURL("http://accounts.google.com/Login");
655 encountered_form.username_element = ASCIIToUTF16("Email");
656 encountered_form.password_element = ASCIIToUTF16("Passwd");
657 encountered_form.submit_element = ASCIIToUTF16("signIn");
658
659 // Get matches for encountered_form.
660 EXPECT_TRUE(db_.GetLogins(encountered_form, &result));
661 ASSERT_EQ(1U, result.size());
662 EXPECT_EQ(incomplete_form.origin, result[0]->origin);
663 EXPECT_EQ(incomplete_form.signon_realm, result[0]->signon_realm);
664 EXPECT_EQ(incomplete_form.username_value, result[0]->username_value);
665 #if defined(OS_MACOSX)
666 // On Mac, passwords are not stored in login database, instead they're in
667 // the keychain.
668 EXPECT_TRUE(result[0]->password_value.empty());
669 #else
670 EXPECT_EQ(incomplete_form.password_value, result[0]->password_value);
671 #endif // !OS_MACOSX
672 EXPECT_TRUE(result[0]->preferred);
673 EXPECT_FALSE(result[0]->ssl_valid);
674
675 // We should return empty 'action', 'username_element', 'password_element'
676 // and 'submit_element' as we can't be sure if the credentials were entered
677 // in this particular form on the page.
678 EXPECT_EQ(GURL(), result[0]->action);
679 EXPECT_TRUE(result[0]->username_element.empty());
680 EXPECT_TRUE(result[0]->password_element.empty());
681 EXPECT_TRUE(result[0]->submit_element.empty());
682 ClearResults(&result);
683
684 // Let's say this login form worked. Now update the stored credentials with
685 // 'action', 'username_element', 'password_element' and 'submit_element' from
686 // the encountered form.
687 PasswordForm completed_form(incomplete_form);
688 completed_form.action = encountered_form.action;
689 completed_form.username_element = encountered_form.username_element;
690 completed_form.password_element = encountered_form.password_element;
691 completed_form.submit_element = encountered_form.submit_element;
692 EXPECT_TRUE(db_.UpdateLogin(completed_form, NULL));
693
694 // Get matches for encountered_form again.
695 EXPECT_TRUE(db_.GetLogins(encountered_form, &result));
696 ASSERT_EQ(1U, result.size());
697
698 // This time we should have all the info available.
699 PasswordForm expected_form(completed_form);
700 #if defined(OS_MACOSX)
701 expected_form.password_value.clear();
702 #endif // OS_MACOSX
703 EXPECT_EQ(expected_form, *result[0]);
704 }
705
629 #if defined(OS_POSIX) 706 #if defined(OS_POSIX)
630 // Only the current user has permission to read the database. 707 // Only the current user has permission to read the database.
631 // 708 //
632 // Only POSIX because GetPosixFilePermissions() only exists on POSIX. 709 // Only POSIX because GetPosixFilePermissions() only exists on POSIX.
633 // This tests that sql::Connection::set_restrict_to_user() was called, 710 // This tests that sql::Connection::set_restrict_to_user() was called,
634 // and that function is a noop on non-POSIX platforms in any case. 711 // and that function is a noop on non-POSIX platforms in any case.
635 TEST_F(LoginDatabaseTest, FilePermissions) { 712 TEST_F(LoginDatabaseTest, FilePermissions) {
636 int mode = base::FILE_PERMISSION_MASK; 713 int mode = base::FILE_PERMISSION_MASK;
637 EXPECT_TRUE(base::GetPosixFilePermissions(file_, &mode)); 714 EXPECT_TRUE(base::GetPosixFilePermissions(file_, &mode));
638 EXPECT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode); 715 EXPECT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode);
639 } 716 }
640 #endif // defined(OS_POSIX) 717 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/login_database.cc ('k') | components/password_manager/core/browser/password_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698