Commit 51281a7f authored by Viktor Semeniuk's avatar Viktor Semeniuk Committed by Chromium LUCI CQ

Added AddCompromisedCredentialsSync to PasswordStoreSync

This change adds function to add compromised credentials. Later it will
be used sync compromised credentials.

Bug: 1137775

Change-Id: I44732583482ad5bf9e2a2bb1f85c907914c86352
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580529
Commit-Queue: Viktor Semeniuk <vsemeniuk@google.com>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838636}
parent a96e7d90
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -700,6 +701,13 @@ PasswordStoreChangeList PasswordStore::AddLoginSync(const PasswordForm& form, ...@@ -700,6 +701,13 @@ PasswordStoreChangeList PasswordStore::AddLoginSync(const PasswordForm& form,
return AddLoginImpl(form, error); return AddLoginImpl(form, error);
} }
bool PasswordStore::AddCompromisedCredentialsSync(
base::span<const CompromisedCredentials> issues) {
return base::ranges::all_of(issues, [this](const auto& issue) {
return AddCompromisedCredentialsImpl(issue);
});
}
PasswordStoreChangeList PasswordStore::UpdateLoginSync( PasswordStoreChangeList PasswordStore::UpdateLoginSync(
const PasswordForm& form, const PasswordForm& form,
UpdateLoginError* error) { UpdateLoginError* error) {
......
...@@ -582,6 +582,8 @@ class PasswordStore : protected PasswordStoreSync, ...@@ -582,6 +582,8 @@ class PasswordStore : protected PasswordStoreSync,
// PasswordStoreSync: // PasswordStoreSync:
PasswordStoreChangeList AddLoginSync(const PasswordForm& form, PasswordStoreChangeList AddLoginSync(const PasswordForm& form,
AddLoginError* error) override; AddLoginError* error) override;
bool AddCompromisedCredentialsSync(
base::span<const CompromisedCredentials> issues) override;
PasswordStoreChangeList UpdateLoginSync(const PasswordForm& form, PasswordStoreChangeList UpdateLoginSync(const PasswordForm& form,
UpdateLoginError* error) override; UpdateLoginError* error) override;
PasswordStoreChangeList RemoveLoginSync(const PasswordForm& form) override; PasswordStoreChangeList RemoveLoginSync(const PasswordForm& form) override;
...@@ -655,6 +657,7 @@ class PasswordStore : protected PasswordStoreSync, ...@@ -655,6 +657,7 @@ class PasswordStore : protected PasswordStoreSync,
private: private:
FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest,
UpdatePasswordsStoredForAffiliatedWebsites); UpdatePasswordsStoredForAffiliatedWebsites);
FRIEND_TEST_ALL_PREFIXES(PasswordStoreTest, AddCompromisedCredentialsSync);
using LoginsResult = std::vector<std::unique_ptr<PasswordForm>>; using LoginsResult = std::vector<std::unique_ptr<PasswordForm>>;
using LoginsTask = base::OnceCallback<LoginsResult()>; using LoginsTask = base::OnceCallback<LoginsResult()>;
......
...@@ -20,6 +20,7 @@ class MetadataBatch; ...@@ -20,6 +20,7 @@ class MetadataBatch;
namespace password_manager { namespace password_manager {
struct CompromisedCredentials;
struct PasswordForm; struct PasswordForm;
using PrimaryKeyToFormMap = std::map<int, std::unique_ptr<PasswordForm>>; using PrimaryKeyToFormMap = std::map<int, std::unique_ptr<PasswordForm>>;
...@@ -130,6 +131,12 @@ class PasswordStoreSync { ...@@ -130,6 +131,12 @@ class PasswordStoreSync {
const PasswordForm& form, const PasswordForm& form,
AddLoginError* error = nullptr) = 0; AddLoginError* error = nullptr) = 0;
// Synchronous implementation to add compromised credentials. Operation will
// be terminated if any insertion into the database fails. Returns whether
// operation was successful.
virtual bool AddCompromisedCredentialsSync(
base::span<const CompromisedCredentials> issues) = 0;
// Synchronous implementation to update the given login. // Synchronous implementation to update the given login.
virtual PasswordStoreChangeList UpdateLoginSync( virtual PasswordStoreChangeList UpdateLoginSync(
const PasswordForm& form, const PasswordForm& form,
......
...@@ -1797,4 +1797,53 @@ TEST_F(PasswordStoreTest, RemoveFieldInfo) { ...@@ -1797,4 +1797,53 @@ TEST_F(PasswordStoreTest, RemoveFieldInfo) {
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
TEST_F(PasswordStoreTest, AddCompromisedCredentialsSync) {
scoped_refptr<PasswordStoreImpl> store = CreatePasswordStore();
store->Init(/*prefs=*/nullptr);
constexpr PasswordFormData kTestCredential = {
PasswordForm::Scheme::kHtml,
kTestWebRealm1,
kTestWebOrigin1,
"",
L"",
L"username_element_1",
L"password_element_1",
L"username",
L"",
kTestLastUsageTime,
1,
};
std::unique_ptr<PasswordForm> test_form =
FillPasswordFormWithData(kTestCredential);
const std::vector<CompromisedCredentials> compromised_credentials = {
CompromisedCredentials(test_form->signon_realm, test_form->username_value,
base::Time(), CompromiseType::kLeaked,
IsMuted(false)),
CompromisedCredentials(test_form->signon_realm, test_form->username_value,
base::Time(), CompromiseType::kReused,
IsMuted(false))};
AddLoginError add_login_error = AddLoginError::kDbError;
store->ScheduleTask(base::BindOnce(IgnoreResult(&PasswordStore::AddLoginSync),
store, *test_form, &add_login_error));
store->ScheduleTask(base::BindOnce(
IgnoreResult(&PasswordStore::AddCompromisedCredentialsSync), store,
compromised_credentials));
WaitForPasswordStore();
EXPECT_EQ(add_login_error, AddLoginError::kNone);
MockCompromisedCredentialsConsumer consumer;
EXPECT_CALL(consumer,
OnGetCompromisedCredentials(UnorderedElementsAre(
compromised_credentials[0], compromised_credentials[1])));
store->GetAllCompromisedCredentials(&consumer);
WaitForPasswordStore();
store->ShutdownOnUIThread();
}
} // namespace password_manager } // namespace password_manager
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/password_manager/core/browser/insecure_credentials_table.h"
#include "components/password_manager/core/browser/password_form.h" #include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_store_sync.h" #include "components/password_manager/core/browser/password_store_sync.h"
#include "components/sync/base/client_tag_hash.h" #include "components/sync/base/client_tag_hash.h"
...@@ -225,6 +226,10 @@ class MockPasswordStoreSync : public PasswordStoreSync { ...@@ -225,6 +226,10 @@ class MockPasswordStoreSync : public PasswordStoreSync {
AddLoginSync, AddLoginSync,
(const PasswordForm&, AddLoginError*), (const PasswordForm&, AddLoginError*),
(override)); (override));
MOCK_METHOD(bool,
AddCompromisedCredentialsSync,
(base::span<const CompromisedCredentials>),
(override));
MOCK_METHOD(PasswordStoreChangeList, MOCK_METHOD(PasswordStoreChangeList,
UpdateLoginSync, UpdateLoginSync,
(const PasswordForm&, UpdateLoginError*), (const PasswordForm&, UpdateLoginError*),
......
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