Commit 6a5d7abc authored by Nela Kaczmarek's avatar Nela Kaczmarek Committed by Commit Bot

Add HashAffiliationFetcher skeleton to retrieve affiliations by hash prefix.

This change creates HashAffiliationFetcher skeleton that extends AffiliationFetcherBase.
This fetcher will provide additional privacy layer as it will request affiliations for a larger group of facets by passing only the prefixes of hashed URLs.

Bug: 1108279
Change-Id: I4a2b09aa7d8c3c51f4b30ba966a17ba5afb9b09b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423883
Commit-Queue: Nela Kaczmarek <nelakaczmarek@google.com>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812653}
parent b47d994e
...@@ -211,6 +211,8 @@ static_library("browser") { ...@@ -211,6 +211,8 @@ static_library("browser") {
"site_affiliation/affiliation_service_impl.h", "site_affiliation/affiliation_service_impl.h",
"site_affiliation/asset_link_data.cc", "site_affiliation/asset_link_data.cc",
"site_affiliation/asset_link_data.h", "site_affiliation/asset_link_data.h",
"site_affiliation/hash_affiliation_fetcher.cc",
"site_affiliation/hash_affiliation_fetcher.h",
"sql_table_builder.cc", "sql_table_builder.cc",
"sql_table_builder.h", "sql_table_builder.h",
"statistics_table.cc", "statistics_table.cc",
...@@ -648,6 +650,7 @@ source_set("unit_tests") { ...@@ -648,6 +650,7 @@ source_set("unit_tests") {
"psl_matching_helper_unittest.cc", "psl_matching_helper_unittest.cc",
"site_affiliation/affiliation_service_impl_unittest.cc", "site_affiliation/affiliation_service_impl_unittest.cc",
"site_affiliation/asset_link_data_unittest.cc", "site_affiliation/asset_link_data_unittest.cc",
"site_affiliation/hash_affiliation_fetcher_unittest.cc",
"sql_table_builder_unittest.cc", "sql_table_builder_unittest.cc",
"statistics_table_unittest.cc", "statistics_table_unittest.cc",
"store_metrics_reporter_unittest.cc", "store_metrics_reporter_unittest.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 "components/password_manager/core/browser/site_affiliation/hash_affiliation_fetcher.h"
#include <memory>
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "google_apis/google_api_keys.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "url/gurl.h"
namespace password_manager {
HashAffiliationFetcher::HashAffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate)
: AffiliationFetcherBase(std::move(url_loader_factory), delegate) {}
HashAffiliationFetcher::~HashAffiliationFetcher() = default;
// TODO: Add an implementation.
void HashAffiliationFetcher::StartRequest(
const std::vector<FacetURI>& facet_uris,
RequestInfo request_info) {}
const std::vector<FacetURI>& HashAffiliationFetcher::GetRequestedFacetURIs()
const {
return requested_facet_uris_;
}
// static
GURL HashAffiliationFetcher::BuildQueryURL() {
return net::AppendQueryParameter(
GURL("https://www.googleapis.com/affiliation/v1/"
"affiliation:lookupByHashPrefix"),
"key", google_apis::GetAPIKey());
}
} // namespace password_manager
// 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_HASH_AFFILIATION_FETCHER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_HASH_AFFILIATION_FETCHER_H_
#include "components/password_manager/core/browser/site_affiliation/affiliation_fetcher_base.h"
namespace password_manager {
// Fetches authoritative information about facets' affiliations with additional
// privacy layer. It uses SHA-256 to hash facet URLs and sends only a specified
// amount of hash prefixes to eventually retrieve a larger group of affiliations
// including those actually required.
class HashAffiliationFetcher : public AffiliationFetcherBase {
public:
HashAffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate);
~HashAffiliationFetcher() override;
void StartRequest(const std::vector<FacetURI>& facet_uris,
RequestInfo request_info) override;
// AffiliationFetcherInterface
const std::vector<FacetURI>& GetRequestedFacetURIs() const override;
// Builds the URL for the Affiliation API's lookup method.
static GURL BuildQueryURL();
private:
std::vector<FacetURI> requested_facet_uris_;
};
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_HASH_AFFILIATION_FETCHER_H_
// 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 "components/password_manager/core/browser/site_affiliation/hash_affiliation_fetcher.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliation_fetcher_delegate.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace password_manager {
class HashAffiliationFetcherTest : public testing::Test {
public:
HashAffiliationFetcherTest() = default;
~HashAffiliationFetcherTest() override = default;
};
TEST_F(HashAffiliationFetcherTest, BuildQueryURL) {
network::TestURLLoaderFactory test_url_loader_factory;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory);
MockAffiliationFetcherDelegate mock_delegate;
HashAffiliationFetcher fetcher(test_shared_loader_factory, &mock_delegate);
EXPECT_EQ(GURL("https://www.googleapis.com/affiliation/v1/"
"affiliation:lookupByHashPrefix?key=dummytoken"),
fetcher.BuildQueryURL());
}
} // namespace password_manager
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