Commit 998b3b74 authored by Irina Fedorova's avatar Irina Fedorova Committed by Commit Bot

Sort weak credentials

This CL adds a sort of weak credentials to GetWeakCredentials(). It uses
the same comparator as used to display the list of saved passwords in
the UI.

Bug: 1119752
Change-Id: Iac597b71a55321f1a72a2d0f378f506976c8d21f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418815
Commit-Queue: Irina Fedorova <irfedorova@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808900}
parent e973f430
......@@ -10,11 +10,13 @@
#include "base/bind.h"
#include "base/containers/flat_set.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/compromised_credentials_table.h"
#include "components/password_manager/core/browser/password_list_sorter.h"
#include "components/password_manager/core/browser/ui/credential_utils.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"
#include "components/password_manager/core/browser/ui/weak_check_utility.h"
......@@ -309,7 +311,15 @@ InsecureCredentialsManager::GetCompromisedCredentials() const {
std::vector<CredentialWithPassword>
InsecureCredentialsManager::GetWeakCredentials() const {
return ExtractInsecureCredentials(credentials_to_forms_, &IsWeak);
std::vector<CredentialWithPassword> weak_credentials =
ExtractInsecureCredentials(credentials_to_forms_, &IsWeak);
auto get_sort_key = [this](const CredentialWithPassword& credential) {
return CreateSortKey(GetSavedPasswordsFor(credential)[0],
IgnoreStore(true));
};
base::ranges::sort(weak_credentials, {}, get_sort_key);
return weak_credentials;
}
SavedPasswordsPresenter::SavedPasswordsView
......
......@@ -66,6 +66,7 @@ PasswordForm MakeSavedPassword(base::StringPiece signon_realm,
base::StringPiece username_element = "") {
PasswordForm form;
form.signon_realm = std::string(signon_realm);
form.url = GURL(signon_realm);
form.username_value = base::ASCIIToUTF16(username);
form.password_value = base::ASCIIToUTF16(password);
form.username_element = base::ASCIIToUTF16(username_element);
......@@ -90,6 +91,12 @@ CredentialWithPassword MakeCompromisedCredential(
return credential_with_password;
}
CredentialWithPassword MakeWeakCredential(const PasswordForm& form) {
CredentialWithPassword weak_credential{CredentialView(form)};
weak_credential.insecure_type = InsecureCredentialTypeFlags::kWeakCredential;
return weak_credential;
}
CredentialWithPassword MakeWeakAndCompromisedCredential(
const PasswordForm& form,
const CompromisedCredentials& credential) {
......@@ -787,6 +794,30 @@ TEST_F(InsecureCredentialsManagerTest, RemoveInsecureCredential) {
EXPECT_THAT(GetSavedPasswordForUsername(kExampleCom, kUsername1), IsEmpty());
}
// Verifues that GetWeakCredentials() returns sorted weak credentials by using
// CreateSortKey.
TEST_F(InsecureCredentialsManagerTest, GetWeakCredentialsReturnsSortedData) {
const std::vector<PasswordForm> password_forms = {
MakeSavedPassword("http://example-a.com", "user_a1", "pwd"),
MakeSavedPassword("http://example-a.com", "user_a2", "pwd"),
MakeSavedPassword("http://example-b.com", "user_a", "pwd"),
MakeSavedPassword("http://example-c.com", "user_a", "pwd")};
store().AddLogin(password_forms[0]);
store().AddLogin(password_forms[1]);
store().AddLogin(password_forms[2]);
store().AddLogin(password_forms[3]);
RunUntilIdle();
provider().StartWeakCheck();
RunUntilIdle();
EXPECT_THAT(provider().GetWeakCredentials(),
ElementsAre(MakeWeakCredential(password_forms[0]),
MakeWeakCredential(password_forms[1]),
MakeWeakCredential(password_forms[2]),
MakeWeakCredential(password_forms[3])));
}
namespace {
class InsecureCredentialsManagerWithTwoStoresTest : public ::testing::Test {
protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment