Commit 3dd37620 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

Reland "[iOS] Make the leak detection backend available on iOS"

This is a reland of 74640a89

TBR=vasilii@chromium.org

Original change's description:
> [iOS] Make the leak detection backend available on iOS
>
> Bug: 986317
>
> Change-Id: I9d799cd24551f13bc58eac91c843d2da19aa7851
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832267
> Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org>
> Commit-Queue: Ioana Pandele <ioanap@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#702059}

Bug: 986317
Change-Id: I490b8d96074e1786b74905a083f0554fe914b4c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1840771Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702835}
parent 6c96f225
......@@ -102,6 +102,10 @@ jumbo_static_library("browser") {
"import/password_csv_reader.h",
"import/password_importer.cc",
"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.h",
"leaked_credentials_table.cc",
......@@ -243,6 +247,7 @@ jumbo_static_library("browser") {
"//components/keyed_service/core",
"//components/os_crypt",
"//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/common",
"//components/pref_registry",
......@@ -276,15 +281,8 @@ jumbo_static_library("browser") {
"hsts_query.h",
"http_credentials_cleaner.cc",
"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) {
......@@ -517,6 +515,8 @@ source_set("unit_tests") {
"import/csv_reader_unittest.cc",
"import/password_csv_reader_unittest.cc",
"import/password_importer_unittest.cc",
"leak_detection_delegate_helper_unittest.cc",
"leak_detection_delegate_unittest.cc",
"leak_detection_dialog_utils_unittest.cc",
"leaked_credentials_table_unittest.cc",
"login_database_unittest.cc",
......@@ -564,8 +564,6 @@ source_set("unit_tests") {
sources += [
"hsts_query_unittest.cc",
"http_credentials_cleaner_unittest.cc",
"leak_detection_delegate_helper_unittest.cc",
"leak_detection_delegate_unittest.cc",
]
}
if (password_reuse_detection_support) {
......@@ -598,7 +596,9 @@ source_set("unit_tests") {
"//components/password_manager/core/browser:proto",
"//components/password_manager/core/browser/form_parsing: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:unit_tests",
"//components/password_manager/core/common",
"//components/prefs:test_support",
"//components/security_state/core",
......@@ -630,13 +630,6 @@ source_set("unit_tests") {
"//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") {
......
......@@ -24,12 +24,7 @@ void RunGetCallback(GetCallback callback, const CredentialInfo& info) {
} // namespace
CredentialManagerImpl::CredentialManagerImpl(PasswordManagerClient* client)
: client_(client)
#if !defined(OS_IOS)
,
leak_delegate_(client)
#endif // !defined(OS_IOS)
{
: client_(client), leak_delegate_(client) {
auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin,
client_->GetPrefs());
}
......@@ -59,10 +54,8 @@ void CredentialManagerImpl::Store(const CredentialInfo& credential,
CreatePasswordFormFromCredentialInfo(credential, origin));
// Check whether a stored password credential was leaked.
#if !defined(OS_IOS)
if (credential.type == CredentialType::CREDENTIAL_TYPE_PASSWORD)
leak_delegate_.StartLeakCheck(*form);
#endif
std::string signon_realm = origin.GetOrigin().spec();
PasswordStore::FormDigest observed_digest(
......
......@@ -53,11 +53,11 @@ class CredentialManagerImpl
// Exposed publicly for testing.
PasswordStore::FormDigest GetSynthesizedFormForOrigin() const;
#if defined(UNIT_TEST) && !defined(OS_IOS)
#if defined(UNIT_TEST)
void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) {
leak_delegate_.set_leak_factory(std::move(factory));
}
#endif // defined(UNIT_TEST) && !defined(OS_IOS)
#endif // defined(UNIT_TEST)
private:
// CredentialManagerPendingRequestTaskDelegate:
......@@ -95,10 +95,8 @@ class CredentialManagerImpl
std::unique_ptr<CredentialManagerPendingPreventSilentAccessTask>
pending_require_user_mediation_;
#if !defined(OS_IOS)
// Helper for making the requests on leak detection.
LeakDetectionDelegate leak_delegate_;
#endif // !defined(OS_IOS)
DISALLOW_COPY_AND_ASSIGN(CredentialManagerImpl);
};
......
......@@ -191,11 +191,9 @@ void PasswordManager::RegisterLocalPrefs(PrefRegistrySimple* registry) {
}
PasswordManager::PasswordManager(PasswordManagerClient* client)
: client_(client)
#if !defined(OS_IOS)
,
: client_(client),
leak_delegate_(client)
#endif // !defined(OS_IOS)
{
DCHECK(client_);
}
......@@ -796,9 +794,7 @@ void PasswordManager::OnLoginSuccessful() {
DCHECK(submitted_manager->GetSubmittedForm());
client_->GetStoreResultFilter()->ReportFormLoginSuccess(*submitted_manager);
#if !defined(OS_IOS)
leak_delegate_.StartLeakCheck(submitted_manager->GetPendingCredentials());
#endif
auto submission_event =
submitted_manager->GetSubmittedForm()->submission_event;
......
......@@ -163,11 +163,10 @@ class PasswordManager : public FormSubmissionObserver {
PasswordFormManager* GetSubmittedManagerForTest() const {
return GetSubmittedManager();
}
#if !defined(OS_IOS)
void set_leak_factory(std::unique_ptr<LeakDetectionCheckFactory> factory) {
leak_delegate_.set_leak_factory(std::move(factory));
}
#endif // !defined(OS_IOS)
#endif // defined(UNIT_TEST)
......@@ -346,11 +345,9 @@ class PasswordManager : public FormSubmissionObserver {
// CredentialManagerImpl takes care of it.
bool store_password_called_ = false;
#if !defined(OS_IOS)
// Helper for making the requests on leak detection.
LeakDetectionDelegate leak_delegate_;
#endif // !defined(OS_IOS)
base::Optional<PossibleUsernameData> possible_username_;
DISALLOW_COPY_AND_ASSIGN(PasswordManager);
......
......@@ -55,6 +55,7 @@ source_set("passwords") {
"//components/password_manager/core/browser",
"//components/password_manager/core/browser:affiliation",
"//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/ios",
"//components/prefs",
......@@ -176,6 +177,7 @@ source_set("unit_tests") {
"//components/autofill/ios/browser",
"//components/password_manager/core/browser",
"//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/ios",
"//components/password_manager/ios:test_support",
......
......@@ -6,6 +6,7 @@
#define IOS_CHROME_BROWSER_PASSWORDS_CREDENTIAL_MANAGER_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"
namespace web {
......@@ -31,6 +32,13 @@ class CredentialManager {
web::WebState* web_state);
~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:
// HandleScriptCommand parses JSON message and invokes Get, Store or
// PreventSilentAccess on CredentialManagerImpl.
......
......@@ -9,6 +9,8 @@
#include "base/bind.h"
#include "base/mac/foundation_util.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 "ios/chrome/browser/passwords/credential_manager_util.h"
#import "ios/chrome/browser/passwords/test/test_password_manager_client.h"
......@@ -21,6 +23,7 @@
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
......@@ -49,6 +52,21 @@ constexpr char kFileOrigin[] = "file://example_file";
// SSL certificate to load for testing.
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
class CredentialManagerBaseTest
......@@ -161,6 +179,18 @@ class CredentialManagerTest : public CredentialManagerBaseTest {
// Tests storing a PasswordCredential.
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|.
ExecuteJavaScript(
@"var credential = new PasswordCredential({"
......
......@@ -28,6 +28,8 @@ TestPasswordManagerClient::TestPasswordManagerClient()
password_manager::prefs::kCredentialsEnableAutosignin, true);
prefs_->registry()->RegisterBooleanPref(
password_manager::prefs::kWasAutoSignInFirstRunExperienceShown, true);
prefs_->registry()->RegisterBooleanPref(
password_manager::prefs::kPasswordLeakDetectionEnabled, true);
}
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