Commit 74640a89 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[iOS] Make the leak detection backend available on iOS

Bug: 986317

Change-Id: I9d799cd24551f13bc58eac91c843d2da19aa7851
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832267Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702059}
parent 5c895ed2
...@@ -102,6 +102,10 @@ jumbo_static_library("browser") { ...@@ -102,6 +102,10 @@ jumbo_static_library("browser") {
"import/password_csv_reader.h", "import/password_csv_reader.h",
"import/password_importer.cc", "import/password_importer.cc",
"import/password_importer.h", "import/password_importer.h",
"leak_detection_delegate.cc",
"leak_detection_delegate.h",
"leak_detection_delegate_helper.cc",
"leak_detection_delegate_helper.h",
"leak_detection_dialog_utils.cc", "leak_detection_dialog_utils.cc",
"leak_detection_dialog_utils.h", "leak_detection_dialog_utils.h",
"leaked_credentials_table.cc", "leaked_credentials_table.cc",
...@@ -243,6 +247,7 @@ jumbo_static_library("browser") { ...@@ -243,6 +247,7 @@ jumbo_static_library("browser") {
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/os_crypt", "//components/os_crypt",
"//components/password_manager/core/browser/form_parsing", "//components/password_manager/core/browser/form_parsing",
"//components/password_manager/core/browser/leak_detection:leak_detection",
"//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers", "//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/pref_registry", "//components/pref_registry",
...@@ -276,15 +281,8 @@ jumbo_static_library("browser") { ...@@ -276,15 +281,8 @@ jumbo_static_library("browser") {
"hsts_query.h", "hsts_query.h",
"http_credentials_cleaner.cc", "http_credentials_cleaner.cc",
"http_credentials_cleaner.h", "http_credentials_cleaner.h",
"leak_detection_delegate.cc",
"leak_detection_delegate.h",
"leak_detection_delegate_helper.cc",
"leak_detection_delegate_helper.h",
]
deps += [
"//components/password_manager/core/browser/leak_detection:leak_detection",
"//components/safe_browsing/common:safe_browsing_prefs",
] ]
deps += [ "//components/safe_browsing/common:safe_browsing_prefs" ]
} }
if ((is_posix && !is_mac && !is_ios) || is_fuchsia) { if ((is_posix && !is_mac && !is_ios) || is_fuchsia) {
...@@ -517,6 +515,8 @@ source_set("unit_tests") { ...@@ -517,6 +515,8 @@ source_set("unit_tests") {
"import/csv_reader_unittest.cc", "import/csv_reader_unittest.cc",
"import/password_csv_reader_unittest.cc", "import/password_csv_reader_unittest.cc",
"import/password_importer_unittest.cc", "import/password_importer_unittest.cc",
"leak_detection_delegate_helper_unittest.cc",
"leak_detection_delegate_unittest.cc",
"leak_detection_dialog_utils_unittest.cc", "leak_detection_dialog_utils_unittest.cc",
"leaked_credentials_table_unittest.cc", "leaked_credentials_table_unittest.cc",
"login_database_unittest.cc", "login_database_unittest.cc",
...@@ -564,8 +564,6 @@ source_set("unit_tests") { ...@@ -564,8 +564,6 @@ source_set("unit_tests") {
sources += [ sources += [
"hsts_query_unittest.cc", "hsts_query_unittest.cc",
"http_credentials_cleaner_unittest.cc", "http_credentials_cleaner_unittest.cc",
"leak_detection_delegate_helper_unittest.cc",
"leak_detection_delegate_unittest.cc",
] ]
} }
if (password_reuse_detection_support) { if (password_reuse_detection_support) {
...@@ -598,7 +596,9 @@ source_set("unit_tests") { ...@@ -598,7 +596,9 @@ source_set("unit_tests") {
"//components/password_manager/core/browser:proto", "//components/password_manager/core/browser:proto",
"//components/password_manager/core/browser/form_parsing:unit_tests", "//components/password_manager/core/browser/form_parsing:unit_tests",
"//components/password_manager/core/browser/form_parsing/fuzzer:unit_tests", "//components/password_manager/core/browser/form_parsing/fuzzer:unit_tests",
"//components/password_manager/core/browser/leak_detection",
"//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers", "//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers",
"//components/password_manager/core/browser/leak_detection:unit_tests",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/prefs:test_support", "//components/prefs:test_support",
"//components/security_state/core", "//components/security_state/core",
...@@ -630,13 +630,6 @@ source_set("unit_tests") { ...@@ -630,13 +630,6 @@ source_set("unit_tests") {
"//components/safe_browsing/common:safe_browsing_prefs", "//components/safe_browsing/common:safe_browsing_prefs",
] ]
} }
if (!is_ios) {
deps += [
"//components/password_manager/core/browser/leak_detection",
"//components/password_manager/core/browser/leak_detection:unit_tests",
]
}
} }
fuzzer_test("csv_reader_fuzzer") { fuzzer_test("csv_reader_fuzzer") {
......
...@@ -24,12 +24,7 @@ void RunGetCallback(GetCallback callback, const CredentialInfo& info) { ...@@ -24,12 +24,7 @@ void RunGetCallback(GetCallback callback, const CredentialInfo& info) {
} // namespace } // namespace
CredentialManagerImpl::CredentialManagerImpl(PasswordManagerClient* client) CredentialManagerImpl::CredentialManagerImpl(PasswordManagerClient* client)
: client_(client) : client_(client), leak_delegate_(client) {
#if !defined(OS_IOS)
,
leak_delegate_(client)
#endif // !defined(OS_IOS)
{
auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin, auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin,
client_->GetPrefs()); client_->GetPrefs());
} }
...@@ -59,10 +54,8 @@ void CredentialManagerImpl::Store(const CredentialInfo& credential, ...@@ -59,10 +54,8 @@ void CredentialManagerImpl::Store(const CredentialInfo& credential,
CreatePasswordFormFromCredentialInfo(credential, origin)); CreatePasswordFormFromCredentialInfo(credential, origin));
// Check whether a stored password credential was leaked. // Check whether a stored password credential was leaked.
#if !defined(OS_IOS)
if (credential.type == CredentialType::CREDENTIAL_TYPE_PASSWORD) if (credential.type == CredentialType::CREDENTIAL_TYPE_PASSWORD)
leak_delegate_.StartLeakCheck(*form); leak_delegate_.StartLeakCheck(*form);
#endif
std::string signon_realm = origin.GetOrigin().spec(); std::string signon_realm = origin.GetOrigin().spec();
PasswordStore::FormDigest observed_digest( PasswordStore::FormDigest observed_digest(
......
...@@ -53,11 +53,11 @@ class CredentialManagerImpl ...@@ -53,11 +53,11 @@ class CredentialManagerImpl
// Exposed publicly for testing. // Exposed publicly for testing.
PasswordStore::FormDigest GetSynthesizedFormForOrigin() const; PasswordStore::FormDigest GetSynthesizedFormForOrigin() const;
#if defined(UNIT_TEST) && !defined(OS_IOS) #if defined(UNIT_TEST)
void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) { void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) {
leak_delegate_.set_leak_factory(std::move(factory)); leak_delegate_.set_leak_factory(std::move(factory));
} }
#endif // defined(UNIT_TEST) && !defined(OS_IOS) #endif // defined(UNIT_TEST)
private: private:
// CredentialManagerPendingRequestTaskDelegate: // CredentialManagerPendingRequestTaskDelegate:
...@@ -95,10 +95,8 @@ class CredentialManagerImpl ...@@ -95,10 +95,8 @@ class CredentialManagerImpl
std::unique_ptr<CredentialManagerPendingPreventSilentAccessTask> std::unique_ptr<CredentialManagerPendingPreventSilentAccessTask>
pending_require_user_mediation_; pending_require_user_mediation_;
#if !defined(OS_IOS)
// Helper for making the requests on leak detection. // Helper for making the requests on leak detection.
LeakDetectionDelegate leak_delegate_; LeakDetectionDelegate leak_delegate_;
#endif // !defined(OS_IOS)
DISALLOW_COPY_AND_ASSIGN(CredentialManagerImpl); DISALLOW_COPY_AND_ASSIGN(CredentialManagerImpl);
}; };
......
...@@ -191,11 +191,9 @@ void PasswordManager::RegisterLocalPrefs(PrefRegistrySimple* registry) { ...@@ -191,11 +191,9 @@ void PasswordManager::RegisterLocalPrefs(PrefRegistrySimple* registry) {
} }
PasswordManager::PasswordManager(PasswordManagerClient* client) PasswordManager::PasswordManager(PasswordManagerClient* client)
: client_(client) : client_(client),
#if !defined(OS_IOS)
,
leak_delegate_(client) leak_delegate_(client)
#endif // !defined(OS_IOS)
{ {
DCHECK(client_); DCHECK(client_);
} }
...@@ -796,9 +794,7 @@ void PasswordManager::OnLoginSuccessful() { ...@@ -796,9 +794,7 @@ void PasswordManager::OnLoginSuccessful() {
DCHECK(submitted_manager->GetSubmittedForm()); DCHECK(submitted_manager->GetSubmittedForm());
client_->GetStoreResultFilter()->ReportFormLoginSuccess(*submitted_manager); client_->GetStoreResultFilter()->ReportFormLoginSuccess(*submitted_manager);
#if !defined(OS_IOS)
leak_delegate_.StartLeakCheck(submitted_manager->GetPendingCredentials()); leak_delegate_.StartLeakCheck(submitted_manager->GetPendingCredentials());
#endif
auto submission_event = auto submission_event =
submitted_manager->GetSubmittedForm()->submission_event; submitted_manager->GetSubmittedForm()->submission_event;
......
...@@ -163,11 +163,10 @@ class PasswordManager : public FormSubmissionObserver { ...@@ -163,11 +163,10 @@ class PasswordManager : public FormSubmissionObserver {
PasswordFormManager* GetSubmittedManagerForTest() const { PasswordFormManager* GetSubmittedManagerForTest() const {
return GetSubmittedManager(); return GetSubmittedManager();
} }
#if !defined(OS_IOS)
void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) { void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) {
leak_delegate_.set_leak_factory(std::move(factory)); leak_delegate_.set_leak_factory(std::move(factory));
} }
#endif // !defined(OS_IOS)
#endif // defined(UNIT_TEST) #endif // defined(UNIT_TEST)
...@@ -346,11 +345,9 @@ class PasswordManager : public FormSubmissionObserver { ...@@ -346,11 +345,9 @@ class PasswordManager : public FormSubmissionObserver {
// CredentialManagerImpl takes care of it. // CredentialManagerImpl takes care of it.
bool store_password_called_ = false; bool store_password_called_ = false;
#if !defined(OS_IOS)
// Helper for making the requests on leak detection. // Helper for making the requests on leak detection.
LeakDetectionDelegate leak_delegate_; LeakDetectionDelegate leak_delegate_;
#endif // !defined(OS_IOS)
base::Optional<PossibleUsernameData> possible_username_; base::Optional<PossibleUsernameData> possible_username_;
DISALLOW_COPY_AND_ASSIGN(PasswordManager); DISALLOW_COPY_AND_ASSIGN(PasswordManager);
......
...@@ -55,6 +55,7 @@ source_set("passwords") { ...@@ -55,6 +55,7 @@ source_set("passwords") {
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//components/password_manager/core/browser:affiliation", "//components/password_manager/core/browser:affiliation",
"//components/password_manager/core/browser/form_parsing", "//components/password_manager/core/browser/form_parsing",
"//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/password_manager/ios", "//components/password_manager/ios",
"//components/prefs", "//components/prefs",
...@@ -176,6 +177,7 @@ source_set("unit_tests") { ...@@ -176,6 +177,7 @@ source_set("unit_tests") {
"//components/autofill/ios/browser", "//components/autofill/ios/browser",
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//components/password_manager/core/browser:test_support", "//components/password_manager/core/browser:test_support",
"//components/password_manager/core/browser/leak_detection:leak_detection_interface_headers",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/password_manager/ios", "//components/password_manager/ios",
"//components/password_manager/ios:test_support", "//components/password_manager/ios:test_support",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define IOS_CHROME_BROWSER_PASSWORDS_CREDENTIAL_MANAGER_H_ #define IOS_CHROME_BROWSER_PASSWORDS_CREDENTIAL_MANAGER_H_
#include "components/password_manager/core/browser/credential_manager_impl.h" #include "components/password_manager/core/browser/credential_manager_impl.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_check_factory.h"
#import "ios/web/public/web_state.h" #import "ios/web/public/web_state.h"
namespace web { namespace web {
...@@ -31,6 +32,13 @@ class CredentialManager { ...@@ -31,6 +32,13 @@ class CredentialManager {
web::WebState* web_state); web::WebState* web_state);
~CredentialManager(); ~CredentialManager();
#if defined(UNIT_TEST)
void set_leak_factory(
std::unique_ptr<password_manager::LeakDetectionCheckFactory> factory) {
impl_.set_leak_factory(std::move(factory));
}
#endif // defined(UNIT_TEST)
private: private:
// HandleScriptCommand parses JSON message and invokes Get, Store or // HandleScriptCommand parses JSON message and invokes Get, Store or
// PreventSilentAccess on CredentialManagerImpl. // PreventSilentAccess on CredentialManagerImpl.
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_check.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_check_factory.h"
#include "components/password_manager/core/browser/test_password_store.h" #include "components/password_manager/core/browser/test_password_store.h"
#include "ios/chrome/browser/passwords/credential_manager_util.h" #include "ios/chrome/browser/passwords/credential_manager_util.h"
#import "ios/chrome/browser/passwords/test/test_password_manager_client.h" #import "ios/chrome/browser/passwords/test/test_password_manager_client.h"
...@@ -21,6 +23,7 @@ ...@@ -21,6 +23,7 @@
#include "net/ssl/ssl_connection_status_flags.h" #include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/cert_test_util.h" #include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h" #include "net/test/test_data_directory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -49,6 +52,21 @@ constexpr char kFileOrigin[] = "file://example_file"; ...@@ -49,6 +52,21 @@ constexpr char kFileOrigin[] = "file://example_file";
// SSL certificate to load for testing. // SSL certificate to load for testing.
constexpr char kCertFileName[] = "ok_cert.pem"; constexpr char kCertFileName[] = "ok_cert.pem";
class MockLeakDetectionCheck : public password_manager::LeakDetectionCheck {
public:
MOCK_METHOD3(Start, void(const GURL&, base::string16, base::string16));
};
class MockLeakDetectionCheckFactory
: public password_manager::LeakDetectionCheckFactory {
public:
MOCK_CONST_METHOD3(TryCreateLeakCheck,
std::unique_ptr<password_manager::LeakDetectionCheck>(
password_manager::LeakDetectionDelegateInterface*,
signin::IdentityManager*,
scoped_refptr<network::SharedURLLoaderFactory>));
};
} // namespace } // namespace
class CredentialManagerBaseTest class CredentialManagerBaseTest
...@@ -161,6 +179,18 @@ class CredentialManagerTest : public CredentialManagerBaseTest { ...@@ -161,6 +179,18 @@ class CredentialManagerTest : public CredentialManagerBaseTest {
// Tests storing a PasswordCredential. // Tests storing a PasswordCredential.
TEST_F(CredentialManagerTest, StorePasswordCredential) { TEST_F(CredentialManagerTest, StorePasswordCredential) {
auto mock_factory =
std::make_unique<testing::StrictMock<MockLeakDetectionCheckFactory>>();
auto* weak_factory = mock_factory.get();
manager_->set_leak_factory(std::move(mock_factory));
auto check_instance = std::make_unique<MockLeakDetectionCheck>();
EXPECT_CALL(*check_instance,
Start(GURL(kHttpsWebOrigin), base::ASCIIToUTF16("id"),
base::ASCIIToUTF16("pencil")));
EXPECT_CALL(*weak_factory, TryCreateLeakCheck)
.WillOnce(testing::Return(testing::ByMove(std::move(check_instance))));
// Call API method |store|. // Call API method |store|.
ExecuteJavaScript( ExecuteJavaScript(
@"var credential = new PasswordCredential({" @"var credential = new PasswordCredential({"
......
...@@ -28,6 +28,8 @@ TestPasswordManagerClient::TestPasswordManagerClient() ...@@ -28,6 +28,8 @@ TestPasswordManagerClient::TestPasswordManagerClient()
password_manager::prefs::kCredentialsEnableAutosignin, true); password_manager::prefs::kCredentialsEnableAutosignin, true);
prefs_->registry()->RegisterBooleanPref( prefs_->registry()->RegisterBooleanPref(
password_manager::prefs::kWasAutoSignInFirstRunExperienceShown, true); password_manager::prefs::kWasAutoSignInFirstRunExperienceShown, true);
prefs_->registry()->RegisterBooleanPref(
password_manager::prefs::kPasswordLeakDetectionEnabled, true);
} }
TestPasswordManagerClient::~TestPasswordManagerClient() = default; TestPasswordManagerClient::~TestPasswordManagerClient() = default;
......
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