From e87686073df996c0e5a537cd6e1d4a4c8b46f3b1 Mon Sep 17 00:00:00 2001 From: boocmp Date: Fri, 22 Nov 2024 21:47:07 +0700 Subject: [PATCH] Tests compilation. --- .../ad_block_service_browsertest.cc | 4 +- .../brave_component_contents_verifier.cc | 97 +++++++++---------- .../brave_component_contents_verifier.h | 13 ++- .../ad_block_component_service_manager.cc | 13 +++ .../ad_block_component_service_manager.h | 1 + test/BUILD.gn | 1 + 6 files changed, 75 insertions(+), 54 deletions(-) diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index 1ba308182d84..4f3157943bbc 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -24,6 +24,7 @@ #include "base/threading/thread_restrictions.h" #include "brave/app/brave_command_ids.h" #include "brave/browser/brave_browser_process.h" +#include "brave/browser/component_updater/brave_component_contents_verifier.h" #include "brave/browser/net/brave_ad_block_tp_network_delegate_helper.h" #include "brave/components/brave_shields/content/browser/ad_block_custom_filters_provider.h" #include "brave/components/brave_shields/content/browser/ad_block_engine.h" @@ -245,7 +246,8 @@ void AdBlockServiceTest::UpdateAdBlockResources(const std::string& resources) { static_cast( service->resource_provider()) - ->OnComponentReady(component_path); + ->OnComponentReady(component_updater::CreateComponentContentsAccessor( + false, component_path)); } void AdBlockServiceTest::UpdateAdBlockInstanceWithRules( diff --git a/browser/component_updater/brave_component_contents_verifier.cc b/browser/component_updater/brave_component_contents_verifier.cc index 88d1e9614a97..9d04e0b9e1ab 100644 --- a/browser/component_updater/brave_component_contents_verifier.cc +++ b/browser/component_updater/brave_component_contents_verifier.cc @@ -13,18 +13,46 @@ #include "base/files/file_path.h" #include "base/functional/bind.h" -#include "brave/components/brave_component_updater/browser/component_contents_verifier.h" #include "crypto/secure_hash.h" #include "crypto/sha2.h" #include "extensions/buildflags/buildflags.h" #if BUILDFLAG(ENABLE_EXTENSIONS) - #include "extensions/browser/content_hash_tree.h" #include "extensions/browser/verified_contents.h" +#endif namespace { +// Only proxies the file access. +class ComponentNoChecksContentsAccessorImpl + : public brave_component_updater::ComponentContentsAccessor { + public: + explicit ComponentNoChecksContentsAccessorImpl( + const base::FilePath& component_root) + : component_root_(component_root) {} + + const base::FilePath& GetComponentRoot() const override { + return component_root_; + } + + bool IsComponentSignatureValid() const override { return true; } + + void IgnoreInvalidSignature(bool) override {} + + bool VerifyContents(const base::FilePath& relative_path, + base::span contents) override { + return true; + } + + protected: + ~ComponentNoChecksContentsAccessorImpl() override = default; + + const base::FilePath component_root_; +}; + +#if BUILDFLAG(ENABLE_EXTENSIONS) + constexpr const uint8_t kComponentContentsVerifierPublicKey[] = { 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, @@ -85,33 +113,6 @@ std::string GetRootHasheForContent(base::span contents, block_size / crypto::kSHA256Length); } -// Only proxies the file access. -class ComponentNoChecksContentsAccessorImpl - : public brave_component_updater::ComponentContentsAccessor { - public: - explicit ComponentNoChecksContentsAccessorImpl( - const base::FilePath& component_root) - : component_root_(component_root) {} - - const base::FilePath& GetComponentRoot() const override { - return component_root_; - } - - bool IsComponentSignatureValid() const override { return true; } - - void IgnoreInvalidSignature(bool) override {} - - bool VerifyContents(const base::FilePath& relative_path, - base::span contents) override { - return true; - } - - protected: - ~ComponentNoChecksContentsAccessorImpl() override = default; - - const base::FilePath component_root_; -}; - // Proxies the file access and checks the verified_contents.json. class ComponentContentsAccessorImpl : public ComponentNoChecksContentsAccessorImpl { @@ -162,35 +163,27 @@ class ComponentContentsAccessorImpl } // namespace -namespace component_updater { -void SetupComponentContentsVerifier() { - auto factory = base::BindRepeating( - [](const base::FilePath& component_root) - -> scoped_refptr { - return base::MakeRefCounted( - component_root); - }); - brave_component_updater::ComponentContentsVerifier::Setup(std::move(factory)); -} -} // namespace component_updater - -#else // BUILDFLAG(ENABLE_EXTENSIONS) +#endif // BUILDFLAG(ENABLE_EXTENSIONS) namespace component_updater { -// We expect that on these platforms the component files are -// protected by the OS. +scoped_refptr +CreateComponentContentsAccessor(bool with_verifier, + const base::FilePath& component_root) { +#if BUILDFLAG(ENABLE_EXTENSIONS) + if (with_verifier) { + return base::MakeRefCounted(component_root); + } +#endif + // if there is no extensions enabled then we expect that on these platforms + // the component files are protected by the OS. + return base::MakeRefCounted( + component_root); +} void SetupComponentContentsVerifier() { - auto factory = base::BindRepeating( - [](const base::FilePath& component_root) - -> scoped_refptr { - return base::MakeRefCounted( - component_root); - }); + auto factory = base::BindRepeating(CreateComponentContentsAccessor, true); brave_component_updater::ComponentContentsVerifier::Setup(std::move(factory)); } } // namespace component_updater - -#endif // BUILDFLAG(ENABLE_EXTENSIONS) diff --git a/browser/component_updater/brave_component_contents_verifier.h b/browser/component_updater/brave_component_contents_verifier.h index cc2177cce036..70e9a2a3f291 100644 --- a/browser/component_updater/brave_component_contents_verifier.h +++ b/browser/component_updater/brave_component_contents_verifier.h @@ -6,10 +6,21 @@ #ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_CONTENTS_VERIFIER_H_ #define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_CONTENTS_VERIFIER_H_ +#include "base/memory/scoped_refptr.h" +#include "brave/components/brave_component_updater/browser/component_contents_verifier.h" + +namespace base { +class FilePath; +} + namespace component_updater { +scoped_refptr +CreateComponentContentsAccessor(bool with_verifier, + const base::FilePath& component_root); + void SetupComponentContentsVerifier(); -} +} // namespace component_updater #endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_CONTENTS_VERIFIER_H_ diff --git a/components/brave_shields/core/browser/ad_block_component_service_manager.cc b/components/brave_shields/core/browser/ad_block_component_service_manager.cc index 616f9821ea0b..2d9dd884a468 100644 --- a/components/brave_shields/core/browser/ad_block_component_service_manager.cc +++ b/components/brave_shields/core/browser/ad_block_component_service_manager.cc @@ -189,6 +189,19 @@ bool AdBlockComponentServiceManager::IsFilterListAvailable( return catalog_entry != filter_list_catalog_.end(); } +base::FilePath AdBlockComponentServiceManager::GetFilterSetPath( + const std::string& uuid) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(!uuid.empty()); + auto it = component_filters_providers_.find(uuid); + + if (it == component_filters_providers_.end()) { + return base::FilePath(); + } + + return it->second->GetFilterSetPath(); +} + bool AdBlockComponentServiceManager::IsFilterListEnabled( const std::string& uuid) const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); diff --git a/components/brave_shields/core/browser/ad_block_component_service_manager.h b/components/brave_shields/core/browser/ad_block_component_service_manager.h index c8ac89830b0c..8d9696082f1c 100644 --- a/components/brave_shields/core/browser/ad_block_component_service_manager.h +++ b/components/brave_shields/core/browser/ad_block_component_service_manager.h @@ -55,6 +55,7 @@ class AdBlockComponentServiceManager // Get the filter set path for a given filter list. // If the filter list is not available, an empty path is returned. + base::FilePath GetFilterSetPath(const std::string& uuid); bool IsFilterListAvailable(const std::string& uuid) const; bool IsFilterListEnabled(const std::string& uuid) const; void EnableFilterList(const std::string& uuid, bool enabled); diff --git a/test/BUILD.gn b/test/BUILD.gn index 32087929a573..343ea9644a11 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -836,6 +836,7 @@ test("brave_browser_tests") { "//brave/browser/brave_wallet:browser_tests", "//brave/browser/brave_wallet:tab_helper", "//brave/browser/browsing_data:browser_tests", + "//brave/browser/component_updater", "//brave/browser/decentralized_dns/test:browser_tests", "//brave/browser/ephemeral_storage:browser_tests", "//brave/browser/ethereum_remote_client/buildflags",