Commit a881f6dd authored by Jonathan Mengedoht's avatar Jonathan Mengedoht Committed by Commit Bot

Add navigation throttle for wellknow change password and test init.

Bug: 927473
Change-Id: I251f368f1b1db2c121105172827c69bf05cd6eb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2224870
Commit-Queue: Jonathan Mengedoht <mengedoht@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780322}
parent 1e777486
...@@ -460,6 +460,7 @@ ...@@ -460,6 +460,7 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h"
#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
#include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h"
#include "chrome/browser/webauthn/authenticator_request_scheduler.h" #include "chrome/browser/webauthn/authenticator_request_scheduler.h"
#include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h"
...@@ -4047,6 +4048,10 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation( ...@@ -4047,6 +4048,10 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation(
MaybeAddThrottle( MaybeAddThrottle(
GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle), GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle),
&throttles); &throttles);
MaybeAddThrottle(
WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle),
&throttles);
#endif #endif
throttles.push_back( throttles.push_back(
......
...@@ -1094,6 +1094,8 @@ static_library("ui") { ...@@ -1094,6 +1094,8 @@ static_library("ui") {
"passwords/passwords_leak_dialog_delegate.h", "passwords/passwords_leak_dialog_delegate.h",
"passwords/passwords_model_delegate.cc", "passwords/passwords_model_delegate.cc",
"passwords/passwords_model_delegate.h", "passwords/passwords_model_delegate.h",
"passwords/well_known_change_password_navigation_throttle.cc",
"passwords/well_known_change_password_navigation_throttle.h",
"pdf/adobe_reader_info_win.cc", "pdf/adobe_reader_info_win.cc",
"pdf/adobe_reader_info_win.h", "pdf/adobe_reader_info_win.h",
"pdf/chrome_pdf_web_contents_helper_client.cc", "pdf/chrome_pdf_web_contents_helper_client.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
#include "base/logging.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "url/gurl.h"
namespace {
using content::NavigationHandle;
using content::NavigationThrottle;
bool IsWellKnownChangePasswordUrl(const GURL& url) {
return url.is_valid() && url.has_path() &&
(url.PathForRequest() == "/.well-known/change-password" ||
url.PathForRequest() == "/.well-known/change-password/");
}
} // namespace
// static
std::unique_ptr<WellKnownChangePasswordNavigationThrottle>
WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(
NavigationHandle* handle) {
const GURL& url = handle->GetURL();
// The order is important. We have to check if it as a well-known change
// password url first. We should only check the feature flag when the feature
// would be used. Otherwise the we would not see a difference between control
// and experiment groups on the dashboards.
if (IsWellKnownChangePasswordUrl(url) &&
base::FeatureList::IsEnabled(
password_manager::features::kWellKnownChangePassword)) {
return base::WrapUnique(
new WellKnownChangePasswordNavigationThrottle(handle));
}
return nullptr;
}
WellKnownChangePasswordNavigationThrottle::
WellKnownChangePasswordNavigationThrottle(NavigationHandle* handle)
: NavigationThrottle(handle) {}
WellKnownChangePasswordNavigationThrottle::
~WellKnownChangePasswordNavigationThrottle() = default;
NavigationThrottle::ThrottleCheckResult
WellKnownChangePasswordNavigationThrottle::WillStartRequest() {
return NavigationThrottle::PROCEED;
}
NavigationThrottle::ThrottleCheckResult
WellKnownChangePasswordNavigationThrottle::WillFailRequest() {
return NavigationThrottle::PROCEED;
}
NavigationThrottle::ThrottleCheckResult
WellKnownChangePasswordNavigationThrottle::WillProcessResponse() {
return NavigationThrottle::PROCEED;
}
const char* WellKnownChangePasswordNavigationThrottle::GetNameForLogging() {
return "WellKnownChangePasswordNavigationThrottle";
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PASSWORDS_WELL_KNOWN_CHANGE_PASSWORD_NAVIGATION_THROTTLE_H_
#define CHROME_BROWSER_UI_PASSWORDS_WELL_KNOWN_CHANGE_PASSWORD_NAVIGATION_THROTTLE_H_
#include <memory>
#include "content/public/browser/navigation_throttle.h"
namespace content {
class NavigationHandle;
} // namespace content
// This NavigationThrottle checks whether a site supports the
// .well-known/change-password url. To check whether a site supports the
// change-password url, we also request a .well-known path that is defined to
// return a 404. When that one returns a 404 and the change password path a 200
// we assume the site supports the change-password url. If the site does not
// support the change password url, the user gets redirected to the base path
// '/'.
class WellKnownChangePasswordNavigationThrottle
: public content::NavigationThrottle {
public:
~WellKnownChangePasswordNavigationThrottle() override;
static std::unique_ptr<WellKnownChangePasswordNavigationThrottle>
MaybeCreateThrottleFor(content::NavigationHandle* handle);
// We don't need to override WillRedirectRequest since a redirect is the
// expected behaviour and does not need manual intervention.
// content::NavigationThrottle:
ThrottleCheckResult WillStartRequest() override;
ThrottleCheckResult WillFailRequest() override;
ThrottleCheckResult WillProcessResponse() override;
const char* GetNameForLogging() override;
private:
explicit WellKnownChangePasswordNavigationThrottle(
content::NavigationHandle* handle);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_WELL_KNOWN_CHANGE_PASSWORD_NAVIGATION_THROTTLE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/test/mock_navigation_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
// Test with parameter for kWellKnownChangePassword feature state.
class WellKnownChangePasswordNavigationThrottleTest
: public ChromeRenderViewHostTestHarness,
public testing::WithParamInterface<bool> {
public:
WellKnownChangePasswordNavigationThrottleTest() {
bool flag_enabled = GetParam();
scoped_features_.InitWithFeatureState(
password_manager::features::kWellKnownChangePassword, flag_enabled);
}
~WellKnownChangePasswordNavigationThrottleTest() override = default;
std::unique_ptr<WellKnownChangePasswordNavigationThrottle>
CreateNavigationThrottleForUrl(const GURL& url) {
content::MockNavigationHandle handle(url, main_rfh());
return WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(
&handle);
}
private:
base::test::ScopedFeatureList scoped_features_;
};
TEST_P(WellKnownChangePasswordNavigationThrottleTest,
CreateNavigationThrottle_ChangePasswordUrl) {
bool flag_enabled = GetParam();
// change-password url without trailing slash
GURL url("https://google.com/.well-known/change-password");
EXPECT_EQ(!!CreateNavigationThrottleForUrl(url), flag_enabled);
// change-password url with trailing slash
url = GURL("https://google.com/.well-known/change-password/");
EXPECT_EQ(!!CreateNavigationThrottleForUrl(url), flag_enabled);
}
TEST_P(WellKnownChangePasswordNavigationThrottleTest,
NeverCreateNavigationThrottle) {
GURL url("https://google.com/.well-known/time");
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
url = GURL("https://google.com/foo");
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
url = GURL("chrome://settings/");
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
url = GURL("mailto:?subject=test");
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
}
INSTANTIATE_TEST_SUITE_P(All,
WellKnownChangePasswordNavigationThrottleTest,
testing::Bool());
...@@ -3616,6 +3616,7 @@ test("unit_tests") { ...@@ -3616,6 +3616,7 @@ test("unit_tests") {
"../browser/ui/bookmarks/bookmark_editor_unittest.cc", "../browser/ui/bookmarks/bookmark_editor_unittest.cc",
"../browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc", "../browser/ui/bookmarks/bookmark_ui_utils_desktop_unittest.cc",
"../browser/ui/bookmarks/recently_used_folders_combo_model_unittest.cc", "../browser/ui/bookmarks/recently_used_folders_combo_model_unittest.cc",
"../browser/ui/passwords/well_known_change_password_navigation_throttle_unittest.cc",
"../browser/ui/sync/profile_signin_confirmation_helper_unittest.cc", "../browser/ui/sync/profile_signin_confirmation_helper_unittest.cc",
"../browser/ui/sync/sync_promo_ui_unittest.cc", "../browser/ui/sync/sync_promo_ui_unittest.cc",
"../browser/ui/toolbar/app_menu_icon_controller_unittest.cc", "../browser/ui/toolbar/app_menu_icon_controller_unittest.cc",
......
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