Commit ea59d7fc authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Add reauth before password export file selection

This CL adds a reauthentication step before the user is asked to even
select a file for exporting passwords to.

Bug: 700003
Change-Id: Ie89529a27ce86ed74b0b3c98bf56abefb1a52899
Reviewed-on: https://chromium-review.googlesource.com/739661Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512412}
parent bed9cb9d
......@@ -241,6 +241,15 @@ void PasswordsPrivateDelegateImpl::ImportPasswords(
void PasswordsPrivateDelegateImpl::ExportPasswords(
content::WebContents* web_contents) {
// Save |web_contents| so that it can be used later when GetNativeWindow() is
// called. Note: This is safe because the |web_contents| is used before
// exiting this method. TODO(crbug.com/495290): Pass the native window
// directly to the reauth-handling code.
web_contents_ = web_contents;
if (!password_access_authenticator_.EnsureUserIsAuthenticated()) {
return;
}
password_manager_porter_->set_web_contents(web_contents);
password_manager_porter_->Store();
}
......
......@@ -254,4 +254,24 @@ TEST_F(PasswordsPrivateDelegateImplTest, TestFailedReauthOnView) {
EXPECT_EQ(base::Value::Type::NONE, captured_args.type()) << captured_args;
}
TEST_F(PasswordsPrivateDelegateImplTest, TestReauthOnExport) {
SetUpPasswordStore({CreateSampleForm()});
PasswordsPrivateDelegateImpl delegate(&profile_);
// Spin the loop to allow PasswordStore tasks posted on the creation of
// |delegate| to be completed.
base::RunLoop().RunUntilIdle();
bool reauth_called = false;
delegate.SetOsReauthCallForTesting(base::BindRepeating(
&FakeOsReauthCall, &reauth_called, ReauthResult::PASS));
delegate.ExportPasswords(nullptr);
EXPECT_TRUE(reauth_called);
// TODO(crbug.com/341477): Once the export flow has defined messages to UI,
// such as progress indication, intercept them with PasswordEventObserver and
// check that exporting is aborted if the authentication failed.
}
} // namespace extensions
......@@ -87,7 +87,9 @@ PasswordManagerPorter::PasswordManagerPorter(
PasswordManagerPorter::~PasswordManagerPorter() {}
void PasswordManagerPorter::Store() {
DCHECK(web_contents_);
// In unittests a null WebContents means: "Abort creating the file Selector."
if (!web_contents_)
return;
PresentFileSelector(web_contents_,
PasswordManagerPorter::Type::PASSWORD_EXPORT);
}
......
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