Commit 771a2a96 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Move federated matches from profile to account store

Bug: 1032992
Change-Id: I91a8aac1d668e42c8e6fe5ae6fd86c86343a2ae0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089764
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747675}
parent a21dc0d5
......@@ -141,12 +141,24 @@ void MultiStorePasswordSaveManager::MoveCredentialsToAccountStore() {
// in both profile and account store.
// 3. Moving credentials upon an update. FormFetch will have an outdated
// credentials. Fix it if this turns out to be a product requirement.
// 4. Migrating federated matches if applicable.
const std::vector<const PasswordForm*> account_store_matches =
std::vector<const PasswordForm*> account_store_matches =
AccountStoreMatches(form_fetcher_->GetNonFederatedMatches());
for (const PasswordForm* match :
ProfileStoreMatches(form_fetcher_->GetNonFederatedMatches())) {
const std::vector<const PasswordForm*> account_store_federated_matches =
AccountStoreMatches(form_fetcher_->GetFederatedMatches());
account_store_matches.insert(account_store_matches.end(),
account_store_federated_matches.begin(),
account_store_federated_matches.end());
std::vector<const PasswordForm*> profile_store_matches =
ProfileStoreMatches(form_fetcher_->GetNonFederatedMatches());
const std::vector<const PasswordForm*> profile_store_federated_matches =
ProfileStoreMatches(form_fetcher_->GetFederatedMatches());
profile_store_matches.insert(profile_store_matches.end(),
profile_store_federated_matches.begin(),
profile_store_federated_matches.end());
for (const PasswordForm* match : profile_store_matches) {
DCHECK(!match->IsUsingAccountStore());
// Ignore credentials matches for other usernames.
if (match->username_value != pending_credentials_.username_value)
......
......@@ -169,6 +169,12 @@ class MultiStorePasswordSaveManagerTest : public testing::Test {
fetcher_->NotifyFetchCompleted();
}
void SetFederatedAndNotifyFetchCompleted(
const std::vector<const autofill::PasswordForm*>& federated) {
fetcher_->set_federated(federated);
fetcher_->NotifyFetchCompleted();
}
void SetAccountStoreEnabled(bool is_enabled) {
ON_CALL(*client()->GetPasswordFeatureManager(),
IsOptedInForAccountStorage())
......@@ -180,6 +186,17 @@ class MultiStorePasswordSaveManagerTest : public testing::Test {
.WillByDefault(Return(store));
}
PasswordForm CreateSavedFederated() {
autofill::PasswordForm federated;
federated.origin = GURL("https://example.in/login");
federated.signon_realm = "federation://example.in/google.com";
federated.type = autofill::PasswordForm::Type::kApi;
federated.federation_origin =
url::Origin::Create(GURL("https://google.com/"));
federated.username_value = ASCIIToUTF16("federated_username");
return federated;
}
MockPasswordManagerClient* client() { return &client_; }
MockFormSaver* mock_account_form_saver() { return mock_account_form_saver_; }
MockFormSaver* mock_profile_form_saver() { return mock_profile_form_saver_; }
......@@ -518,4 +535,25 @@ TEST_F(MultiStorePasswordSaveManagerTest,
password_save_manager()->MoveCredentialsToAccountStore();
}
TEST_F(MultiStorePasswordSaveManagerTest,
MoveFederatedCredentialsFromProfileToAccountStore) {
PasswordForm federated_match_in_profile_store = CreateSavedFederated();
federated_match_in_profile_store.in_store =
PasswordForm::Store::kProfileStore;
SetFederatedAndNotifyFetchCompleted({&federated_match_in_profile_store});
password_save_manager()->CreatePendingCredentials(
federated_match_in_profile_store, observed_form_, submitted_form_,
/*is_http_auth=*/false,
/*is_credential_api_save=*/false);
EXPECT_CALL(*mock_profile_form_saver(),
Remove(federated_match_in_profile_store));
EXPECT_CALL(*mock_account_form_saver(),
Save(federated_match_in_profile_store, _, _));
password_save_manager()->MoveCredentialsToAccountStore();
}
} // namespace password_manager
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