Skip to content

Commit

Permalink
Tests compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
boocmp committed Nov 25, 2024
1 parent dce25e0 commit e876860
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 54 deletions.
4 changes: 3 additions & 1 deletion browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -245,7 +246,8 @@ void AdBlockServiceTest::UpdateAdBlockResources(const std::string& resources) {

static_cast<brave_shields::AdBlockDefaultResourceProvider*>(
service->resource_provider())
->OnComponentReady(component_path);
->OnComponentReady(component_updater::CreateComponentContentsAccessor(
false, component_path));
}

void AdBlockServiceTest::UpdateAdBlockInstanceWithRules(
Expand Down
97 changes: 45 additions & 52 deletions browser/component_updater/brave_component_contents_verifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint8_t> 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,
Expand Down Expand Up @@ -85,33 +113,6 @@ std::string GetRootHasheForContent(base::span<const uint8_t> 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<const uint8_t> 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 {
Expand Down Expand Up @@ -162,35 +163,27 @@ class ComponentContentsAccessorImpl

} // namespace

namespace component_updater {
void SetupComponentContentsVerifier() {
auto factory = base::BindRepeating(
[](const base::FilePath& component_root)
-> scoped_refptr<brave_component_updater::ComponentContentsAccessor> {
return base::MakeRefCounted<ComponentContentsAccessorImpl>(
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<brave_component_updater::ComponentContentsAccessor>
CreateComponentContentsAccessor(bool with_verifier,
const base::FilePath& component_root) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
if (with_verifier) {
return base::MakeRefCounted<ComponentContentsAccessorImpl>(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<ComponentNoChecksContentsAccessorImpl>(
component_root);
}

void SetupComponentContentsVerifier() {
auto factory = base::BindRepeating(
[](const base::FilePath& component_root)
-> scoped_refptr<brave_component_updater::ComponentContentsAccessor> {
return base::MakeRefCounted<ComponentNoChecksContentsAccessorImpl>(
component_root);
});
auto factory = base::BindRepeating(CreateComponentContentsAccessor, true);
brave_component_updater::ComponentContentsVerifier::Setup(std::move(factory));
}

} // namespace component_updater

#endif // BUILDFLAG(ENABLE_EXTENSIONS)
13 changes: 12 additions & 1 deletion browser/component_updater/brave_component_contents_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<brave_component_updater::ComponentContentsAccessor>
CreateComponentContentsAccessor(bool with_verifier,
const base::FilePath& component_root);

void SetupComponentContentsVerifier();

}
} // namespace component_updater

#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_CONTENTS_VERIFIER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e876860

Please sign in to comment.