summaryrefslogtreecommitdiff
path: root/chromium/net/reporting
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-06 12:48:11 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:33:43 +0000
commit7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch)
treefa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/net/reporting
parent79b4f909db1049fca459c07cca55af56a9b54fe3 (diff)
downloadqtwebengine-chromium-7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3.tar.gz
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/net/reporting')
-rw-r--r--chromium/net/reporting/reporting_browsing_data_remover_unittest.cc5
-rw-r--r--chromium/net/reporting/reporting_cache.h6
-rw-r--r--chromium/net/reporting/reporting_cache_impl.cc37
-rw-r--r--chromium/net/reporting/reporting_cache_impl.h4
-rw-r--r--chromium/net/reporting/reporting_cache_unittest.cc54
-rw-r--r--chromium/net/reporting/reporting_delivery_agent.cc2
-rw-r--r--chromium/net/reporting/reporting_delivery_agent_unittest.cc49
-rw-r--r--chromium/net/reporting/reporting_endpoint_manager.cc3
-rw-r--r--chromium/net/reporting/reporting_endpoint_manager_unittest.cc4
-rw-r--r--chromium/net/reporting/reporting_garbage_collector_unittest.cc9
-rw-r--r--chromium/net/reporting/reporting_header_parser.cc16
-rw-r--r--chromium/net/reporting/reporting_header_parser.h3
-rw-r--r--chromium/net/reporting/reporting_header_parser_fuzzer.cc4
-rw-r--r--chromium/net/reporting/reporting_header_parser_unittest.cc728
-rw-r--r--chromium/net/reporting/reporting_network_change_observer_unittest.cc9
-rw-r--r--chromium/net/reporting/reporting_report.cc21
-rw-r--r--chromium/net/reporting/reporting_report.h8
-rw-r--r--chromium/net/reporting/reporting_service.cc33
-rw-r--r--chromium/net/reporting/reporting_test_util.cc3
-rw-r--r--chromium/net/reporting/reporting_uploader_unittest.cc2
20 files changed, 621 insertions, 379 deletions
diff --git a/chromium/net/reporting/reporting_browsing_data_remover_unittest.cc b/chromium/net/reporting/reporting_browsing_data_remover_unittest.cc
index 09ae18705f1..1ddb5c266ad 100644
--- a/chromium/net/reporting/reporting_browsing_data_remover_unittest.cc
+++ b/chromium/net/reporting/reporting_browsing_data_remover_unittest.cc
@@ -41,9 +41,10 @@ class ReportingBrowsingDataRemoverTest : public ReportingTestBase {
}
}
+ // TODO(chlily): Take NIK.
void AddReport(const GURL& url) {
- cache()->AddReport(url, kUserAgent_, kGroup_, kType_,
- std::make_unique<base::DictionaryValue>(), 0,
+ cache()->AddReport(NetworkIsolationKey::Todo(), url, kUserAgent_, kGroup_,
+ kType_, std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
}
diff --git a/chromium/net/reporting/reporting_cache.h b/chromium/net/reporting/reporting_cache.h
index fb09d715b2e..d891801304e 100644
--- a/chromium/net/reporting/reporting_cache.h
+++ b/chromium/net/reporting/reporting_cache.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/callback.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/time/time.h"
@@ -57,7 +58,8 @@ class NET_EXPORT ReportingCache {
//
// All parameters correspond to the desired values for the relevant fields in
// ReportingReport.
- virtual void AddReport(const GURL& url,
+ virtual void AddReport(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
const std::string& user_agent,
const std::string& group_name,
const std::string& type,
@@ -128,8 +130,8 @@ class NET_EXPORT ReportingCache {
// Adds a new client to the cache for |origin|, or updates the existing one
// to match the new header. All values are assumed to be valid as they have
// passed through the ReportingHeaderParser.
- // TODO(chlily): Take NetworkIsolationKey.
virtual void OnParsedHeader(
+ const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) = 0;
diff --git a/chromium/net/reporting/reporting_cache_impl.cc b/chromium/net/reporting/reporting_cache_impl.cc
index 82ca25254c7..14fc211c02d 100644
--- a/chromium/net/reporting/reporting_cache_impl.cc
+++ b/chromium/net/reporting/reporting_cache_impl.cc
@@ -29,17 +29,19 @@ ReportingCacheImpl::~ReportingCacheImpl() {
}
}
-void ReportingCacheImpl::AddReport(const GURL& url,
- const std::string& user_agent,
- const std::string& group_name,
- const std::string& type,
- std::unique_ptr<const base::Value> body,
- int depth,
- base::TimeTicks queued,
- int attempts) {
- auto report = std::make_unique<ReportingReport>(url, user_agent, group_name,
- type, std::move(body), depth,
- queued, attempts);
+void ReportingCacheImpl::AddReport(
+ const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
+ const std::string& user_agent,
+ const std::string& group_name,
+ const std::string& type,
+ std::unique_ptr<const base::Value> body,
+ int depth,
+ base::TimeTicks queued,
+ int attempts) {
+ auto report = std::make_unique<ReportingReport>(
+ network_isolation_key, url, user_agent, group_name, type, std::move(body),
+ depth, queued, attempts);
auto inserted = reports_.insert(std::move(report));
DCHECK(inserted.second);
@@ -84,6 +86,9 @@ base::Value ReportingCacheImpl::GetReportsAsValue() const {
std::vector<base::Value> report_list;
for (const ReportingReport* report : sorted_reports) {
base::Value report_dict(base::Value::Type::DICTIONARY);
+ report_dict.SetKey(
+ "network_isolation_key",
+ base::Value(report->network_isolation_key.ToDebugString()));
report_dict.SetKey("url", base::Value(report->url.spec()));
report_dict.SetKey("group", base::Value(report->group));
report_dict.SetKey("type", base::Value(report->type));
@@ -215,12 +220,11 @@ bool ReportingCacheImpl::IsReportDoomedForTesting(
}
void ReportingCacheImpl::OnParsedHeader(
+ const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) {
SanityCheckClients();
- // TODO(chlily): Respect NetworkIsolationKey.
- NetworkIsolationKey network_isolation_key = NetworkIsolationKey::Todo();
Client new_client(network_isolation_key, origin);
base::Time now = clock().Now();
new_client.last_used = now;
@@ -234,11 +238,8 @@ void ReportingCacheImpl::OnParsedHeader(
// Creates an endpoint group and sets its |last_used| to |now|.
CachedReportingEndpointGroup new_group(parsed_endpoint_group, now);
- // TODO(chlily): This DCHECK passes right now because the groups have their
- // NIK set to an empty NIK by the header parser, and we also set the
- // client's NIK to an empty NIK above. Eventually it should pass because the
- // header parser should provide the NIK it used for the groups so that the
- // client can be created using the same NIK.
+ // Consistency check: the new client should have the same NIK and origin as
+ // all groups parsed from this header.
DCHECK_EQ(new_group.group_key.network_isolation_key,
new_client.network_isolation_key);
DCHECK_EQ(new_group.group_key.origin, new_client.origin);
diff --git a/chromium/net/reporting/reporting_cache_impl.h b/chromium/net/reporting/reporting_cache_impl.h
index a13623edf71..1a3df74b150 100644
--- a/chromium/net/reporting/reporting_cache_impl.h
+++ b/chromium/net/reporting/reporting_cache_impl.h
@@ -38,7 +38,8 @@ class ReportingCacheImpl : public ReportingCache {
~ReportingCacheImpl() override;
// ReportingCache implementation
- void AddReport(const GURL& url,
+ void AddReport(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
const std::string& user_agent,
const std::string& group_name,
const std::string& type,
@@ -65,6 +66,7 @@ class ReportingCacheImpl : public ReportingCache {
bool IsReportPendingForTesting(const ReportingReport* report) const override;
bool IsReportDoomedForTesting(const ReportingReport* report) const override;
void OnParsedHeader(
+ const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) override;
std::set<url::Origin> GetAllOrigins() const override;
diff --git a/chromium/net/reporting/reporting_cache_unittest.cc b/chromium/net/reporting/reporting_cache_unittest.cc
index d1e03ae27ea..49739c243a5 100644
--- a/chromium/net/reporting/reporting_cache_unittest.cc
+++ b/chromium/net/reporting/reporting_cache_unittest.cc
@@ -99,6 +99,7 @@ class ReportingCacheTest : public ReportingTestBase,
// Adds a new report to the cache, and returns it.
const ReportingReport* AddAndReturnReport(
+ const NetworkIsolationKey& network_isolation_key,
const GURL& url,
const std::string& user_agent,
const std::string& group,
@@ -115,8 +116,8 @@ class ReportingCacheTest : public ReportingTestBase,
// in test cases, so I've optimized for readability over execution speed.
std::vector<const ReportingReport*> before;
cache()->GetReports(&before);
- cache()->AddReport(url, user_agent, group, type, std::move(body), depth,
- queued, attempts);
+ cache()->AddReport(network_isolation_key, url, user_agent, group, type,
+ std::move(body), depth, queued, attempts);
std::vector<const ReportingReport*> after;
cache()->GetReports(&after);
@@ -124,6 +125,7 @@ class ReportingCacheTest : public ReportingTestBase,
// If report isn't in before, we've found the new instance.
if (std::find(before.begin(), before.end(), report) == before.end()) {
// Sanity check the result before we return it.
+ EXPECT_EQ(network_isolation_key, report->network_isolation_key);
EXPECT_EQ(url, report->url);
EXPECT_EQ(user_agent, report->user_agent);
EXPECT_EQ(group, report->group);
@@ -222,7 +224,7 @@ TEST_P(ReportingCacheTest, Reports) {
cache()->GetReports(&reports);
EXPECT_TRUE(reports.empty());
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
EXPECT_EQ(1, observer()->cached_reports_update_count());
@@ -231,6 +233,7 @@ TEST_P(ReportingCacheTest, Reports) {
ASSERT_EQ(1u, reports.size());
const ReportingReport* report = reports[0];
ASSERT_TRUE(report);
+ EXPECT_EQ(kNik_, report->network_isolation_key);
EXPECT_EQ(kUrl1_, report->url);
EXPECT_EQ(kUserAgent_, report->user_agent);
EXPECT_EQ(kGroup1_, report->group);
@@ -260,10 +263,10 @@ TEST_P(ReportingCacheTest, Reports) {
TEST_P(ReportingCacheTest, RemoveAllReports) {
LoadReportingClients();
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
EXPECT_EQ(2, observer()->cached_reports_update_count());
@@ -282,7 +285,7 @@ TEST_P(ReportingCacheTest, RemoveAllReports) {
TEST_P(ReportingCacheTest, RemovePendingReports) {
LoadReportingClients();
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
EXPECT_EQ(1, observer()->cached_reports_update_count());
@@ -320,7 +323,7 @@ TEST_P(ReportingCacheTest, RemovePendingReports) {
TEST_P(ReportingCacheTest, RemoveAllPendingReports) {
LoadReportingClients();
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
EXPECT_EQ(1, observer()->cached_reports_update_count());
@@ -361,11 +364,11 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
// We need a reproducible expiry timestamp for this test case.
const base::TimeTicks now = base::TimeTicks();
const ReportingReport* report1 =
- AddAndReturnReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ AddAndReturnReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
now + base::TimeDelta::FromSeconds(200), 0);
const ReportingReport* report2 =
- AddAndReturnReport(kUrl1_, kUserAgent_, kGroup2_, kType_,
+ AddAndReturnReport(kOtherNik_, kUrl1_, kUserAgent_, kGroup2_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
now + base::TimeDelta::FromSeconds(100), 1);
// Mark report1 and report2 as pending.
@@ -375,11 +378,13 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
cache()->RemoveReports({report2}, ReportingReport::Outcome::UNKNOWN);
base::Value actual = cache()->GetReportsAsValue();
- base::Value expected = base::test::ParseJson(R"json(
+ base::Value expected = base::test::ParseJson(base::StringPrintf(
+ R"json(
[
{
"url": "https://origin1/path",
"group": "group2",
+ "network_isolation_key": "%s",
"type": "default",
"status": "doomed",
"body": {},
@@ -390,6 +395,7 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
{
"url": "https://origin1/path",
"group": "group1",
+ "network_isolation_key": "%s",
"type": "default",
"status": "pending",
"body": {},
@@ -398,24 +404,27 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
"queued": "200000",
},
]
- )json");
+ )json",
+ kOtherNik_.ToDebugString().c_str(), kNik_.ToDebugString().c_str()));
EXPECT_EQ(expected, actual);
// Add two new reports that will show up as "queued".
const ReportingReport* report3 =
- AddAndReturnReport(kUrl2_, kUserAgent_, kGroup1_, kType_,
+ AddAndReturnReport(kNik_, kUrl2_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 2,
now + base::TimeDelta::FromSeconds(200), 0);
const ReportingReport* report4 =
- AddAndReturnReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ AddAndReturnReport(kOtherNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
now + base::TimeDelta::FromSeconds(300), 0);
actual = cache()->GetReportsAsValue();
- expected = base::test::ParseJson(R"json(
+ expected = base::test::ParseJson(base::StringPrintf(
+ R"json(
[
{
"url": "https://origin1/path",
"group": "group2",
+ "network_isolation_key": "%s",
"type": "default",
"status": "doomed",
"body": {},
@@ -426,6 +435,7 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
{
"url": "https://origin1/path",
"group": "group1",
+ "network_isolation_key": "%s",
"type": "default",
"status": "pending",
"body": {},
@@ -436,6 +446,7 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
{
"url": "https://origin2/path",
"group": "group1",
+ "network_isolation_key": "%s",
"type": "default",
"status": "queued",
"body": {},
@@ -446,6 +457,7 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
{
"url": "https://origin1/path",
"group": "group1",
+ "network_isolation_key": "%s",
"type": "default",
"status": "queued",
"body": {},
@@ -454,7 +466,9 @@ TEST_P(ReportingCacheTest, GetReportsAsValue) {
"queued": "300000",
},
]
- )json");
+ )json",
+ kOtherNik_.ToDebugString().c_str(), kNik_.ToDebugString().c_str(),
+ kNik_.ToDebugString().c_str(), kOtherNik_.ToDebugString().c_str()));
EXPECT_EQ(expected, actual);
// GetReportsToDeliver only returns the non-pending reports.
@@ -911,7 +925,7 @@ TEST_P(ReportingCacheTest, GetClientsAsValue) {
},
]
)json",
- kNik_.ToDebugString().data(), kOtherNik_.ToDebugString().data()));
+ kNik_.ToDebugString().c_str(), kOtherNik_.ToDebugString().c_str()));
// Compare disregarding order.
auto expected_list = expected->TakeList();
@@ -1155,7 +1169,7 @@ TEST_P(ReportingCacheTest, EvictOldestReport) {
// Enqueue the maximum number of reports, spaced apart in time.
for (size_t i = 0; i < max_report_count; ++i) {
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
tick_clock()->Advance(base::TimeDelta::FromMinutes(1));
@@ -1163,7 +1177,7 @@ TEST_P(ReportingCacheTest, EvictOldestReport) {
EXPECT_EQ(max_report_count, report_count());
// Add one more report to force the cache to evict one.
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -1188,7 +1202,7 @@ TEST_P(ReportingCacheTest, DontEvictPendingReports) {
std::vector<const ReportingReport*> reports;
for (size_t i = 0; i < max_report_count; ++i) {
reports.push_back(
- AddAndReturnReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ AddAndReturnReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0));
tick_clock()->Advance(base::TimeDelta::FromMinutes(1));
@@ -1201,7 +1215,7 @@ TEST_P(ReportingCacheTest, DontEvictPendingReports) {
// Add one more report to force the cache to evict one. Since the cache has
// only pending reports, it will be forced to evict the *new* report!
- cache()->AddReport(kUrl1_, kUserAgent_, kGroup1_, kType_,
+ cache()->AddReport(kNik_, kUrl1_, kUserAgent_, kGroup1_, kType_,
std::make_unique<base::DictionaryValue>(), 0, kNowTicks_,
0);
diff --git a/chromium/net/reporting/reporting_delivery_agent.cc b/chromium/net/reporting/reporting_delivery_agent.cc
index a5a2c49ef32..fca2421b239 100644
--- a/chromium/net/reporting/reporting_delivery_agent.cc
+++ b/chromium/net/reporting/reporting_delivery_agent.cc
@@ -11,8 +11,8 @@
#include <vector>
#include "base/bind.h"
+#include "base/check.h"
#include "base/json/json_writer.h"
-#include "base/logging.h"
#include "base/time/tick_clock.h"
#include "base/timer/timer.h"
#include "base/values.h"
diff --git a/chromium/net/reporting/reporting_delivery_agent_unittest.cc b/chromium/net/reporting/reporting_delivery_agent_unittest.cc
index a079808db8f..893cdd61eb2 100644
--- a/chromium/net/reporting/reporting_delivery_agent_unittest.cc
+++ b/chromium/net/reporting/reporting_delivery_agent_unittest.cc
@@ -39,6 +39,7 @@ class ReportingDeliveryAgentTest : public ReportingTestBase {
UsePolicy(policy);
}
+ const NetworkIsolationKey kNik_ = NetworkIsolationKey::Todo();
const GURL kUrl_ = GURL("https://origin/path");
const GURL kSubdomainUrl_ = GURL("https://sub.origin/path");
const url::Origin kOrigin_ = url::Origin::Create(GURL("https://origin/"));
@@ -48,7 +49,7 @@ class ReportingDeliveryAgentTest : public ReportingTestBase {
const std::string kType_ = "type";
const base::Time kExpires_ = base::Time::Now() + base::TimeDelta::FromDays(7);
const ReportingEndpointGroupKey kGroupKey_ =
- ReportingEndpointGroupKey(NetworkIsolationKey(), kOrigin_, kGroup_);
+ ReportingEndpointGroupKey(kNik_, kOrigin_, kGroup_);
};
TEST_F(ReportingDeliveryAgentTest, SuccessfulImmediateUpload) {
@@ -56,8 +57,8 @@ TEST_F(ReportingDeliveryAgentTest, SuccessfulImmediateUpload) {
body.SetString("key", "value");
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_, body.CreateDeepCopy(),
- 0, tick_clock()->NowTicks(), 0);
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
+ body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
// Upload is automatically started when cache is modified.
@@ -105,7 +106,7 @@ TEST_F(ReportingDeliveryAgentTest, SuccessfulImmediateSubdomainUpload) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_,
OriginSubdomains::INCLUDE));
- cache()->AddReport(kSubdomainUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kSubdomainUrl_, kUserAgent_, kGroup_, kType_,
body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
// Upload is automatically started when cache is modified.
@@ -155,7 +156,7 @@ TEST_F(ReportingDeliveryAgentTest,
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_,
OriginSubdomains::INCLUDE));
- cache()->AddReport(kSubdomainUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kSubdomainUrl_, kUserAgent_, kGroup_, kType_,
body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
// Upload is automatically started when cache is modified.
@@ -187,13 +188,13 @@ TEST_F(ReportingDeliveryAgentTest, SuccessfulDelayedUpload) {
// Trigger and complete an upload to start the delivery timer.
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_, body.CreateDeepCopy(),
- 0, tick_clock()->NowTicks(), 0);
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
+ body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS);
// Add another report to upload after a delay.
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_, body.CreateDeepCopy(),
- 0, tick_clock()->NowTicks(), 0);
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
+ body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
EXPECT_TRUE(delivery_timer()->IsRunning());
delivery_timer()->Fire();
@@ -238,7 +239,7 @@ TEST_F(ReportingDeliveryAgentTest, SuccessfulDelayedUpload) {
TEST_F(ReportingDeliveryAgentTest, FailedUpload) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -291,8 +292,8 @@ TEST_F(ReportingDeliveryAgentTest, DisallowedUpload) {
body.SetString("key", "value");
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_, body.CreateDeepCopy(),
- 0, tick_clock()->NowTicks(), 0);
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
+ body.CreateDeepCopy(), 0, tick_clock()->NowTicks(), 0);
tick_clock()->Advance(base::TimeDelta::FromMilliseconds(kAgeMillis));
@@ -327,7 +328,7 @@ TEST_F(ReportingDeliveryAgentTest, RemoveEndpointUpload) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
ASSERT_TRUE(SetEndpointInCache(kOtherGroupKey, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -356,7 +357,7 @@ TEST_F(ReportingDeliveryAgentTest, RemoveEndpointUpload) {
TEST_F(ReportingDeliveryAgentTest, ConcurrentRemove) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -392,7 +393,7 @@ TEST_F(ReportingDeliveryAgentTest, ConcurrentRemoveDuringPermissionsCheck) {
context()->test_delegate()->set_pause_permissions_check(true);
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -434,17 +435,17 @@ TEST_F(ReportingDeliveryAgentTest,
ASSERT_TRUE(SetEndpointInCache(kDifferentGroupKey, kEndpoint_, kExpires_));
// Trigger and complete an upload to start the delivery timer.
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS);
// Now that the delivery timer is running, these reports won't be immediately
// uploaded.
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
- cache()->AddReport(kDifferentUrl, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kDifferentUrl, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
EXPECT_EQ(0u, pending_uploads().size());
@@ -467,7 +468,7 @@ TEST_F(ReportingDeliveryAgentTest,
TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToEndpoint) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -475,7 +476,7 @@ TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToEndpoint) {
delivery_timer()->Fire();
EXPECT_EQ(1u, pending_uploads().size());
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -503,7 +504,7 @@ TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToGroup) {
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kEndpoint_, kExpires_));
ASSERT_TRUE(SetEndpointInCache(kGroupKey_, kDifferentEndpoint, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -511,7 +512,7 @@ TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToGroup) {
delivery_timer()->Fire();
EXPECT_EQ(1u, pending_uploads().size());
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -542,10 +543,10 @@ TEST_F(ReportingDeliveryAgentTest, ParallelizeUploadsAcrossGroups) {
ASSERT_TRUE(
SetEndpointInCache(kDifferentGroupKey, kDifferentEndpoint, kExpires_));
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
- cache()->AddReport(kUrl_, kUserAgent_, kDifferentGroup, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kDifferentGroup, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
diff --git a/chromium/net/reporting/reporting_endpoint_manager.cc b/chromium/net/reporting/reporting_endpoint_manager.cc
index 35652768ebd..c903335b5e7 100644
--- a/chromium/net/reporting/reporting_endpoint_manager.cc
+++ b/chromium/net/reporting/reporting_endpoint_manager.cc
@@ -10,9 +10,10 @@
#include <utility>
#include <vector>
+#include "base/check.h"
#include "base/containers/mru_cache.h"
-#include "base/logging.h"
#include "base/macros.h"
+#include "base/notreached.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/time/tick_clock.h"
diff --git a/chromium/net/reporting/reporting_endpoint_manager_unittest.cc b/chromium/net/reporting/reporting_endpoint_manager_unittest.cc
index d05153d547a..0e020936a79 100644
--- a/chromium/net/reporting/reporting_endpoint_manager_unittest.cc
+++ b/chromium/net/reporting/reporting_endpoint_manager_unittest.cc
@@ -47,7 +47,8 @@ class TestReportingCache : public ReportingCache {
}
// Everything below is NOTREACHED.
- void AddReport(const GURL& url,
+ void AddReport(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
const std::string& user_agent,
const std::string& group_name,
const std::string& type,
@@ -103,6 +104,7 @@ class TestReportingCache : public ReportingCache {
return false;
}
void OnParsedHeader(
+ const NetworkIsolationKey& network_isolation_key,
const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) override {
NOTREACHED();
diff --git a/chromium/net/reporting/reporting_garbage_collector_unittest.cc b/chromium/net/reporting/reporting_garbage_collector_unittest.cc
index 78ad1601ca0..71ea1cead48 100644
--- a/chromium/net/reporting/reporting_garbage_collector_unittest.cc
+++ b/chromium/net/reporting/reporting_garbage_collector_unittest.cc
@@ -26,6 +26,7 @@ class ReportingGarbageCollectorTest : public ReportingTestBase {
return reports.size();
}
+ const NetworkIsolationKey kNik_;
const GURL kUrl_ = GURL("https://origin/path");
const std::string kUserAgent_ = "Mozilla/1.0";
const std::string kGroup_ = "group";
@@ -41,7 +42,7 @@ TEST_F(ReportingGarbageCollectorTest, Created) {
TEST_F(ReportingGarbageCollectorTest, Timer) {
EXPECT_FALSE(garbage_collection_timer()->IsRunning());
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
@@ -53,7 +54,7 @@ TEST_F(ReportingGarbageCollectorTest, Timer) {
}
TEST_F(ReportingGarbageCollectorTest, Report) {
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
garbage_collection_timer()->Fire();
@@ -62,7 +63,7 @@ TEST_F(ReportingGarbageCollectorTest, Report) {
}
TEST_F(ReportingGarbageCollectorTest, ExpiredReport) {
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
tick_clock()->Advance(2 * policy().max_report_age);
@@ -72,7 +73,7 @@ TEST_F(ReportingGarbageCollectorTest, ExpiredReport) {
}
TEST_F(ReportingGarbageCollectorTest, FailedReport) {
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
diff --git a/chromium/net/reporting/reporting_header_parser.cc b/chromium/net/reporting/reporting_header_parser.cc
index 12f0064a4b8..294f9039841 100644
--- a/chromium/net/reporting/reporting_header_parser.cc
+++ b/chromium/net/reporting/reporting_header_parser.cc
@@ -4,13 +4,14 @@
#include "net/reporting/reporting_header_parser.h"
+#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
+#include "base/check.h"
#include "base/json/json_reader.h"
-#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "base/values.h"
@@ -241,9 +242,11 @@ void ReportingHeaderParser::RecordHeaderDiscardedForJsonTooBig() {
}
// static
-void ReportingHeaderParser::ParseHeader(ReportingContext* context,
- const GURL& url,
- std::unique_ptr<base::Value> value) {
+void ReportingHeaderParser::ParseHeader(
+ ReportingContext* context,
+ const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
+ std::unique_ptr<base::Value> value) {
DCHECK(url.SchemeIsCryptographic());
const base::ListValue* group_list = nullptr;
@@ -254,7 +257,6 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context,
ReportingCache* cache = context->cache();
url::Origin origin = url::Origin::Create(url);
- NetworkIsolationKey network_isolation_key = NetworkIsolationKey::Todo();
std::vector<ReportingEndpointGroup> parsed_header;
@@ -279,8 +281,8 @@ void ReportingHeaderParser::ParseHeader(ReportingContext* context,
return;
}
- // TODO(chlily): Pass NIK to cache.
- cache->OnParsedHeader(origin, std::move(parsed_header));
+ cache->OnParsedHeader(network_isolation_key, origin,
+ std::move(parsed_header));
RecordHeaderOutcome(HeaderOutcome::PARSED);
}
diff --git a/chromium/net/reporting/reporting_header_parser.h b/chromium/net/reporting/reporting_header_parser.h
index 3556904cdb1..adba204742a 100644
--- a/chromium/net/reporting/reporting_header_parser.h
+++ b/chromium/net/reporting/reporting_header_parser.h
@@ -17,6 +17,7 @@ class Value;
namespace net {
+class NetworkIsolationKey;
class ReportingContext;
class NET_EXPORT ReportingHeaderParser {
@@ -79,8 +80,8 @@ class NET_EXPORT ReportingHeaderParser {
static void RecordHeaderDiscardedForJsonInvalid();
static void RecordHeaderDiscardedForJsonTooBig();
- // TODO(chlily): Pass in the NetworkIsolationKey.
static void ParseHeader(ReportingContext* context,
+ const NetworkIsolationKey& network_isolation_key,
const GURL& url,
std::unique_ptr<base::Value> value);
diff --git a/chromium/net/reporting/reporting_header_parser_fuzzer.cc b/chromium/net/reporting/reporting_header_parser_fuzzer.cc
index 58637b8d264..d52179fc790 100644
--- a/chromium/net/reporting/reporting_header_parser_fuzzer.cc
+++ b/chromium/net/reporting/reporting_header_parser_fuzzer.cc
@@ -10,6 +10,7 @@
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "base/values.h"
+#include "net/base/network_isolation_key.h"
#include "net/reporting/reporting_cache.h"
#include "net/reporting/reporting_header_parser.h"
#include "net/reporting/reporting_policy.pb.h"
@@ -38,7 +39,8 @@ void FuzzReportingHeaderParser(const std::string& data_json,
// TODO: consider including proto definition for URL after moving that to
// testing/libfuzzer/proto and creating a separate converter.
- net::ReportingHeaderParser::ParseHeader(&context, GURL("https://origin/path"),
+ net::ReportingHeaderParser::ParseHeader(&context, net::NetworkIsolationKey(),
+ GURL("https://origin/path"),
std::move(data_value));
if (context.cache()->GetEndpointCount() == 0) {
return;
diff --git a/chromium/net/reporting/reporting_header_parser_unittest.cc b/chromium/net/reporting/reporting_header_parser_unittest.cc
index cedaa990d0a..fcedd578574 100644
--- a/chromium/net/reporting/reporting_header_parser_unittest.cc
+++ b/chromium/net/reporting/reporting_header_parser_unittest.cc
@@ -66,7 +66,7 @@ class ReportingHeaderParserTest : public ReportingTestBase,
OriginSubdomains include_subdomains = OriginSubdomains::DEFAULT,
base::TimeDelta ttl = base::TimeDelta::FromDays(1),
url::Origin origin = url::Origin()) {
- ReportingEndpointGroupKey group_key(NetworkIsolationKey() /* unused */,
+ ReportingEndpointGroupKey group_key(kNik_ /* unused */,
url::Origin() /* unused */, name);
ReportingEndpointGroup group;
group.group_key = group_key;
@@ -127,33 +127,43 @@ class ReportingHeaderParserTest : public ReportingTestBase,
return s.str();
}
- void ParseHeader(const GURL& url, const std::string& json) {
+ void ParseHeader(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
+ const std::string& json) {
std::unique_ptr<base::Value> value =
base::JSONReader::ReadDeprecated("[" + json + "]");
- if (value)
- ReportingHeaderParser::ParseHeader(context(), url, std::move(value));
+ if (value) {
+ ReportingHeaderParser::ParseHeader(context(), network_isolation_key, url,
+ std::move(value));
+ }
}
- const GURL kUrl_ = GURL("https://origin.test/path");
- const url::Origin kOrigin_ =
- url::Origin::Create(GURL("https://origin.test/"));
+ const GURL kUrl1_ = GURL("https://origin1.test/path");
+ const url::Origin kOrigin1_ = url::Origin::Create(kUrl1_);
const GURL kUrl2_ = GURL("https://origin2.test/path");
- const url::Origin kOrigin2_ =
- url::Origin::Create(GURL("https://origin2.test/"));
+ const url::Origin kOrigin2_ = url::Origin::Create(kUrl2_);
+ const NetworkIsolationKey kNik_;
+ const NetworkIsolationKey kOtherNik_ =
+ NetworkIsolationKey(kOrigin1_, kOrigin2_);
const GURL kUrlEtld_ = GURL("https://co.uk/foo.html/");
const url::Origin kOriginEtld_ = url::Origin::Create(kUrlEtld_);
- const GURL kEndpoint_ = GURL("https://endpoint.test/");
+ const GURL kEndpoint1_ = GURL("https://endpoint1.test/");
const GURL kEndpoint2_ = GURL("https://endpoint2.test/");
const GURL kEndpoint3_ = GURL("https://endpoint3.test/");
const GURL kEndpointPathAbsolute_ =
- GURL("https://origin.test/path-absolute-url");
- const std::string kGroup_ = "group";
+ GURL("https://origin1.test/path-absolute-url");
+ const std::string kGroup1_ = "group1";
const std::string kGroup2_ = "group2";
- const std::string kType_ = "type";
- const ReportingEndpointGroupKey kGroupKey_ =
- ReportingEndpointGroupKey(NetworkIsolationKey(), kOrigin_, kGroup_);
- const ReportingEndpointGroupKey kGroupKey2_ =
- ReportingEndpointGroupKey(NetworkIsolationKey(), kOrigin_, kGroup2_);
+ // There are 2^3 = 8 of these to test the different combinations of matching
+ // vs mismatching NIK, origin, and group.
+ const ReportingEndpointGroupKey kGroupKey11_ =
+ ReportingEndpointGroupKey(kNik_, kOrigin1_, kGroup1_);
+ const ReportingEndpointGroupKey kGroupKey21_ =
+ ReportingEndpointGroupKey(kNik_, kOrigin2_, kGroup1_);
+ const ReportingEndpointGroupKey kGroupKey12_ =
+ ReportingEndpointGroupKey(kNik_, kOrigin1_, kGroup2_);
+ const ReportingEndpointGroupKey kGroupKey22_ =
+ ReportingEndpointGroupKey(kNik_, kOrigin2_, kGroup2_);
private:
std::unique_ptr<MockPersistentReportingStore> store_;
@@ -210,7 +220,7 @@ TEST_P(ReportingHeaderParserTest, Invalid) {
for (size_t i = 0; i < base::size(kInvalidHeaderTestCases); ++i) {
auto& test_case = kInvalidHeaderTestCases[i];
- ParseHeader(kUrl_, test_case.header_value);
+ ParseHeader(kNik_, kUrl1_, test_case.header_value);
EXPECT_EQ(0u, cache()->GetEndpointCount())
<< "Invalid Report-To header (" << test_case.description << ": \""
@@ -225,22 +235,22 @@ TEST_P(ReportingHeaderParserTest, Invalid) {
}
TEST_P(ReportingHeaderParserTest, Basic) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint.group_key.group_name);
- EXPECT_EQ(kEndpoint_, endpoint.info.url);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint.group_key.group_name);
+ EXPECT_EQ(kEndpoint1_, endpoint.info.url);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
@@ -252,9 +262,9 @@ TEST_P(ReportingHeaderParserTest, Basic) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -262,20 +272,20 @@ TEST_P(ReportingHeaderParserTest, Basic) {
TEST_P(ReportingHeaderParserTest, PathAbsoluteURLEndpoint) {
std::string header =
- "{\"group\": \"group\", \"max_age\":1, \"endpoints\": "
+ "{\"group\": \"group1\", \"max_age\":1, \"endpoints\": "
"[{\"url\":\"/path-absolute-url\"}]}";
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(1u, cache()->GetEndpointCount());
ReportingEndpoint endpoint =
- FindEndpointInCache(kGroupKey_, kEndpointPathAbsolute_);
+ FindEndpointInCache(kGroupKey11_, kEndpointPathAbsolute_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint.group_key.group_name);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint.group_key.group_name);
EXPECT_EQ(kEndpointPathAbsolute_, endpoint.info.url);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
@@ -289,12 +299,12 @@ TEST_P(ReportingHeaderParserTest, PathAbsoluteURLEndpoint) {
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(
CommandType::ADD_REPORTING_ENDPOINT,
- ReportingEndpoint(kGroupKey_, ReportingEndpoint::EndpointInfo{
- kEndpointPathAbsolute_}));
+ ReportingEndpoint(kGroupKey11_, ReportingEndpoint::EndpointInfo{
+ kEndpointPathAbsolute_}));
expected_commands.emplace_back(
CommandType::ADD_REPORTING_ENDPOINT_GROUP,
CachedReportingEndpointGroup(
- kGroupKey_, OriginSubdomains::DEFAULT /* irrelevant */,
+ kGroupKey11_, OriginSubdomains::DEFAULT /* irrelevant */,
base::Time() /* irrelevant */, base::Time() /* irrelevant */));
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
@@ -302,22 +312,21 @@ TEST_P(ReportingHeaderParserTest, PathAbsoluteURLEndpoint) {
}
TEST_P(ReportingHeaderParserTest, OmittedGroupName) {
- ReportingEndpointGroupKey kGroupKey(NetworkIsolationKey(), kOrigin_,
- "default");
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ ReportingEndpointGroupKey kGroupKey(kNik_, kOrigin1_, "default");
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header =
ConstructHeaderGroupString(MakeEndpointGroup(std::string(), endpoints));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(EndpointGroupExistsInCache(kGroupKey, OriginSubdomains::DEFAULT));
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey, kEndpoint1_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
EXPECT_EQ("default", endpoint.group_key.group_name);
- EXPECT_EQ(kEndpoint_, endpoint.info.url);
+ EXPECT_EQ(kEndpoint1_, endpoint.info.url);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
@@ -329,7 +338,7 @@ TEST_P(ReportingHeaderParserTest, OmittedGroupName) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey, kEndpoint_);
+ kGroupKey, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
kGroupKey);
EXPECT_THAT(mock_store()->GetAllCommands(),
@@ -338,17 +347,17 @@ TEST_P(ReportingHeaderParserTest, OmittedGroupName) {
}
TEST_P(ReportingHeaderParserTest, IncludeSubdomainsTrue) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header = ConstructHeaderGroupString(
- MakeEndpointGroup(kGroup_, endpoints, OriginSubdomains::INCLUDE));
- ParseHeader(kUrl_, header);
+ MakeEndpointGroup(kGroup1_, endpoints, OriginSubdomains::INCLUDE));
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::INCLUDE));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::INCLUDE));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- EXPECT_TRUE(EndpointExistsInCache(kGroupKey_, kEndpoint_));
+ EXPECT_TRUE(EndpointExistsInCache(kGroupKey11_, kEndpoint1_));
if (mock_store()) {
mock_store()->Flush();
@@ -356,27 +365,27 @@ TEST_P(ReportingHeaderParserTest, IncludeSubdomainsTrue) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
TEST_P(ReportingHeaderParserTest, IncludeSubdomainsFalse) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header = ConstructHeaderGroupString(
- MakeEndpointGroup(kGroup_, endpoints, OriginSubdomains::EXCLUDE),
+ MakeEndpointGroup(kGroup1_, endpoints, OriginSubdomains::EXCLUDE),
false /* omit_defaults */);
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::EXCLUDE));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::EXCLUDE));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- EXPECT_TRUE(EndpointExistsInCache(kGroupKey_, kEndpoint_));
+ EXPECT_TRUE(EndpointExistsInCache(kGroupKey11_, kEndpoint1_));
if (mock_store()) {
mock_store()->Flush();
@@ -384,59 +393,57 @@ TEST_P(ReportingHeaderParserTest, IncludeSubdomainsFalse) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
TEST_P(ReportingHeaderParserTest, IncludeSubdomainsEtldRejected) {
- ReportingEndpointGroupKey kGroupKey(NetworkIsolationKey(), kOriginEtld_,
- kGroup_);
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ ReportingEndpointGroupKey kGroupKey(kNik_, kOriginEtld_, kGroup1_);
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header = ConstructHeaderGroupString(
- MakeEndpointGroup(kGroup_, endpoints, OriginSubdomains::INCLUDE));
- ParseHeader(kUrlEtld_, header);
+ MakeEndpointGroup(kGroup1_, endpoints, OriginSubdomains::INCLUDE));
+ ParseHeader(kNik_, kUrlEtld_, header);
EXPECT_EQ(0u, cache()->GetEndpointGroupCountForTesting());
EXPECT_FALSE(
EndpointGroupExistsInCache(kGroupKey, OriginSubdomains::INCLUDE));
EXPECT_EQ(0u, cache()->GetEndpointCount());
- EXPECT_FALSE(EndpointExistsInCache(kGroupKey, kEndpoint_));
+ EXPECT_FALSE(EndpointExistsInCache(kGroupKey, kEndpoint1_));
}
TEST_P(ReportingHeaderParserTest, NonIncludeSubdomainsEtldAccepted) {
- ReportingEndpointGroupKey kGroupKey(NetworkIsolationKey(), kOriginEtld_,
- kGroup_);
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ ReportingEndpointGroupKey kGroupKey(kNik_, kOriginEtld_, kGroup1_);
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header = ConstructHeaderGroupString(
- MakeEndpointGroup(kGroup_, endpoints, OriginSubdomains::EXCLUDE));
- ParseHeader(kUrlEtld_, header);
+ MakeEndpointGroup(kGroup1_, endpoints, OriginSubdomains::EXCLUDE));
+ ParseHeader(kNik_, kUrlEtld_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(EndpointGroupExistsInCache(kGroupKey, OriginSubdomains::EXCLUDE));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- EXPECT_TRUE(EndpointExistsInCache(kGroupKey, kEndpoint_));
+ EXPECT_TRUE(EndpointExistsInCache(kGroupKey, kEndpoint1_));
}
TEST_P(ReportingHeaderParserTest, IncludeSubdomainsNotBoolean) {
std::string header =
- "{\"group\": \"" + kGroup_ +
+ "{\"group\": \"" + kGroup1_ +
"\", "
"\"max_age\":86400, \"include_subdomains\": \"NotABoolean\", "
"\"endpoints\": [{\"url\":\"" +
- kEndpoint_.spec() + "\"}]}";
- ParseHeader(kUrl_, header);
+ kEndpoint1_.spec() + "\"}]}";
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- EXPECT_TRUE(EndpointExistsInCache(kGroupKey_, kEndpoint_));
+ EXPECT_TRUE(EndpointExistsInCache(kGroupKey11_, kEndpoint1_));
if (mock_store()) {
mock_store()->Flush();
@@ -444,9 +451,9 @@ TEST_P(ReportingHeaderParserTest, IncludeSubdomainsNotBoolean) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -455,17 +462,17 @@ TEST_P(ReportingHeaderParserTest, IncludeSubdomainsNotBoolean) {
TEST_P(ReportingHeaderParserTest, NonDefaultPriority) {
const int kNonDefaultPriority = 10;
std::vector<ReportingEndpoint::EndpointInfo> endpoints = {
- {kEndpoint_, kNonDefaultPriority}};
+ {kEndpoint1_, kNonDefaultPriority}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
EXPECT_EQ(kNonDefaultPriority, endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
@@ -477,9 +484,9 @@ TEST_P(ReportingHeaderParserTest, NonDefaultPriority) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -488,18 +495,18 @@ TEST_P(ReportingHeaderParserTest, NonDefaultPriority) {
TEST_P(ReportingHeaderParserTest, NonDefaultWeight) {
const int kNonDefaultWeight = 10;
std::vector<ReportingEndpoint::EndpointInfo> endpoints = {
- {kEndpoint_, ReportingEndpoint::EndpointInfo::kDefaultPriority,
+ {kEndpoint1_, ReportingEndpoint::EndpointInfo::kDefaultPriority,
kNonDefaultWeight}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
@@ -511,9 +518,9 @@ TEST_P(ReportingHeaderParserTest, NonDefaultWeight) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -524,15 +531,15 @@ TEST_P(ReportingHeaderParserTest, MaxAge) {
base::TimeDelta ttl = base::TimeDelta::FromSeconds(kMaxAgeSecs);
base::Time expires = clock()->Now() + ttl;
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header = ConstructHeaderGroupString(
- MakeEndpointGroup(kGroup_, endpoints, OriginSubdomains::DEFAULT, ttl));
+ MakeEndpointGroup(kGroup1_, endpoints, OriginSubdomains::DEFAULT, ttl));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
- EXPECT_TRUE(EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT,
- expires));
+ EXPECT_TRUE(EndpointGroupExistsInCache(kGroupKey11_,
+ OriginSubdomains::DEFAULT, expires));
if (mock_store()) {
mock_store()->Flush();
@@ -540,40 +547,40 @@ TEST_P(ReportingHeaderParserTest, MaxAge) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
TEST_P(ReportingHeaderParserTest, MultipleEndpointsSameGroup) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_},
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_},
{kEndpoint2_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(2u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint.group_key.group_name);
- EXPECT_EQ(kEndpoint_, endpoint.info.url);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint.group_key.group_name);
+ EXPECT_EQ(kEndpoint1_, endpoint.info.url);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
endpoint.info.weight);
- ReportingEndpoint endpoint2 = FindEndpointInCache(kGroupKey_, kEndpoint2_);
+ ReportingEndpoint endpoint2 = FindEndpointInCache(kGroupKey11_, kEndpoint2_);
ASSERT_TRUE(endpoint2);
- EXPECT_EQ(kOrigin_, endpoint2.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint2.group_key.group_name);
+ EXPECT_EQ(kOrigin1_, endpoint2.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint2.group_key.group_name);
EXPECT_EQ(kEndpoint2_, endpoint2.info.url);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint2.info.priority);
@@ -586,47 +593,45 @@ TEST_P(ReportingHeaderParserTest, MultipleEndpointsSameGroup) {
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint2_);
+ kGroupKey11_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
TEST_P(ReportingHeaderParserTest, MultipleEndpointsDifferentGroups) {
- ReportingEndpointGroupKey kOtherGroupKey(NetworkIsolationKey(), kOrigin_,
- kGroup2_);
- std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint_}};
- std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint1_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1)) +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1)) +
", " +
ConstructHeaderGroupString(MakeEndpointGroup(kGroup2_, endpoints2));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
EXPECT_EQ(2u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kOtherGroupKey, OriginSubdomains::DEFAULT));
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EndpointGroupExistsInCache(kGroupKey12_, OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(2u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint.group_key.group_name);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint.group_key.group_name);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
endpoint.info.weight);
- ReportingEndpoint endpoint2 = FindEndpointInCache(kOtherGroupKey, kEndpoint_);
+ ReportingEndpoint endpoint2 = FindEndpointInCache(kGroupKey12_, kEndpoint1_);
ASSERT_TRUE(endpoint2);
- EXPECT_EQ(kOrigin_, endpoint2.group_key.origin);
+ EXPECT_EQ(kOrigin1_, endpoint2.group_key.origin);
EXPECT_EQ(kGroup2_, endpoint2.group_key.group_name);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint2.info.priority);
@@ -639,13 +644,13 @@ TEST_P(ReportingHeaderParserTest, MultipleEndpointsDifferentGroups) {
EXPECT_EQ(2, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kOtherGroupKey, kEndpoint_);
+ kGroupKey12_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kOtherGroupKey);
+ kGroupKey12_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -653,42 +658,37 @@ TEST_P(ReportingHeaderParserTest, MultipleEndpointsDifferentGroups) {
TEST_P(ReportingHeaderParserTest, MultipleHeadersFromDifferentOrigins) {
// First origin sets a header with two endpoints in the same group.
- std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint_},
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_},
{kEndpoint2_}};
std::string header1 =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1));
- ParseHeader(kUrl_, header1);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1));
+ ParseHeader(kNik_, kUrl1_, header1);
// Second origin has two endpoint groups.
- std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint1_}};
std::vector<ReportingEndpoint::EndpointInfo> endpoints3 = {{kEndpoint2_}};
std::string header2 =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints2)) +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints2)) +
", " +
ConstructHeaderGroupString(MakeEndpointGroup(kGroup2_, endpoints3));
- ParseHeader(kUrl2_, header2);
+ ParseHeader(kNik_, kUrl2_, header2);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin2_));
- ReportingEndpointGroupKey kGroupKey1(NetworkIsolationKey(), kOrigin2_,
- kGroup_);
- ReportingEndpointGroupKey kGroupKey2(NetworkIsolationKey(), kOrigin2_,
- kGroup2_);
-
EXPECT_EQ(3u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey1, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey21_, OriginSubdomains::DEFAULT));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey2, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey22_, OriginSubdomains::DEFAULT));
EXPECT_EQ(4u, cache()->GetEndpointCount());
- EXPECT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
- EXPECT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint2_));
- EXPECT_TRUE(FindEndpointInCache(kGroupKey1, kEndpoint_));
- EXPECT_TRUE(FindEndpointInCache(kGroupKey2, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey21_, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey22_, kEndpoint2_));
if (mock_store()) {
mock_store()->Flush();
@@ -696,54 +696,247 @@ TEST_P(ReportingHeaderParserTest, MultipleHeadersFromDifferentOrigins) {
EXPECT_EQ(3, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint2_);
+ kGroupKey11_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey1, kEndpoint_);
+ kGroupKey21_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey2, kEndpoint2_);
+ kGroupKey22_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey1);
+ kGroupKey21_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey2);
+ kGroupKey22_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
+// Test that each combination of NIK, origin, and group name is considered
+// distinct.
+// See also: ReportingCacheTest.ClientsKeyedByEndpointGroupKey
+TEST_P(ReportingHeaderParserTest, EndpointGroupKey) {
+ // Raise the endpoint limits for this test.
+ ReportingPolicy policy;
+ policy.max_endpoints_per_origin = 5; // This test should use 4.
+ policy.max_endpoint_count = 20; // This test should use 16.
+ UsePolicy(policy);
+
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_},
+ {kEndpoint2_}};
+ std::string header1 =
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1)) +
+ ", " +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup2_, endpoints1));
+
+ const ReportingEndpointGroupKey kOtherGroupKey11 =
+ ReportingEndpointGroupKey(kOtherNik_, kOrigin1_, kGroup1_);
+ const ReportingEndpointGroupKey kOtherGroupKey21 =
+ ReportingEndpointGroupKey(kOtherNik_, kOrigin2_, kGroup1_);
+ const ReportingEndpointGroupKey kOtherGroupKey12 =
+ ReportingEndpointGroupKey(kOtherNik_, kOrigin1_, kGroup2_);
+ const ReportingEndpointGroupKey kOtherGroupKey22 =
+ ReportingEndpointGroupKey(kOtherNik_, kOrigin2_, kGroup2_);
+
+ const struct {
+ NetworkIsolationKey network_isolation_key;
+ GURL url;
+ ReportingEndpointGroupKey group1_key;
+ ReportingEndpointGroupKey group2_key;
+ } kHeaderSources[] = {
+ {kNik_, kUrl1_, kGroupKey11_, kGroupKey12_},
+ {kNik_, kUrl2_, kGroupKey21_, kGroupKey22_},
+ {kOtherNik_, kUrl1_, kOtherGroupKey11, kOtherGroupKey12},
+ {kOtherNik_, kUrl2_, kOtherGroupKey21, kOtherGroupKey22},
+ };
+
+ size_t endpoint_group_count = 0u;
+ size_t endpoint_count = 0u;
+ MockPersistentReportingStore::CommandList expected_commands;
+
+ // Set 2 endpoints in each of 2 groups for each of 2x2 combinations of
+ // (NIK, origin).
+ for (const auto& source : kHeaderSources) {
+ // Verify pre-parsing state
+ EXPECT_FALSE(FindEndpointInCache(source.group1_key, kEndpoint1_));
+ EXPECT_FALSE(FindEndpointInCache(source.group1_key, kEndpoint2_));
+ EXPECT_FALSE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ EXPECT_FALSE(FindEndpointInCache(source.group2_key, kEndpoint2_));
+ EXPECT_FALSE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_FALSE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::DEFAULT));
+
+ ParseHeader(source.network_isolation_key, source.url, header1);
+ endpoint_group_count += 2u;
+ endpoint_count += 4u;
+ EXPECT_EQ(endpoint_group_count, cache()->GetEndpointGroupCountForTesting());
+ EXPECT_EQ(endpoint_count, cache()->GetEndpointCount());
+
+ // Verify post-parsing state
+ EXPECT_TRUE(FindEndpointInCache(source.group1_key, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(source.group1_key, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint2_));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::DEFAULT));
+
+ if (mock_store()) {
+ mock_store()->Flush();
+ EXPECT_EQ(static_cast<int>(endpoint_count),
+ mock_store()->StoredEndpointsCount());
+ EXPECT_EQ(static_cast<int>(endpoint_group_count),
+ mock_store()->StoredEndpointGroupsCount());
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
+ source.group1_key, kEndpoint1_);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
+ source.group1_key, kEndpoint2_);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
+ source.group1_key);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
+ source.group2_key, kEndpoint1_);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
+ source.group2_key, kEndpoint2_);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
+ source.group2_key);
+ EXPECT_THAT(mock_store()->GetAllCommands(),
+ testing::IsSupersetOf(expected_commands));
+ }
+ }
+
+ // Check that expected data is present in the ReportingCache at the end.
+ for (const auto& source : kHeaderSources) {
+ EXPECT_TRUE(FindEndpointInCache(source.group1_key, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(source.group1_key, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint2_));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(cache()->ClientExistsForTesting(
+ source.network_isolation_key, url::Origin::Create(source.url)));
+ }
+
+ // Test updating existing configurations
+
+ // This removes endpoint 1, updates the priority of endpoint 2, and adds
+ // endpoint 3.
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint2_, 2},
+ {kEndpoint3_}};
+ // Removes group 1, updates include_subdomains for group 2.
+ std::string header2 = ConstructHeaderGroupString(
+ MakeEndpointGroup(kGroup2_, endpoints2, OriginSubdomains::INCLUDE));
+
+ for (const auto& source : kHeaderSources) {
+ // Verify pre-update state
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ ReportingEndpoint endpoint =
+ FindEndpointInCache(source.group2_key, kEndpoint2_);
+ EXPECT_TRUE(endpoint);
+ EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
+ endpoint.info.priority);
+ EXPECT_FALSE(FindEndpointInCache(source.group2_key, kEndpoint3_));
+
+ ParseHeader(source.network_isolation_key, source.url, header2);
+ endpoint_group_count--;
+ endpoint_count -= 2;
+ EXPECT_EQ(endpoint_group_count, cache()->GetEndpointGroupCountForTesting());
+ EXPECT_EQ(endpoint_count, cache()->GetEndpointCount());
+
+ // Verify post-update state
+ EXPECT_FALSE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::INCLUDE));
+ EXPECT_FALSE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ endpoint = FindEndpointInCache(source.group2_key, kEndpoint2_);
+ EXPECT_TRUE(endpoint);
+ EXPECT_EQ(2, endpoint.info.priority);
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint3_));
+
+ if (mock_store()) {
+ mock_store()->Flush();
+ EXPECT_EQ(static_cast<int>(endpoint_count),
+ mock_store()->StoredEndpointsCount());
+ EXPECT_EQ(static_cast<int>(endpoint_group_count),
+ mock_store()->StoredEndpointGroupsCount());
+ expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
+ source.group1_key, kEndpoint1_);
+ expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
+ source.group1_key, kEndpoint2_);
+ expected_commands.emplace_back(
+ CommandType::DELETE_REPORTING_ENDPOINT_GROUP, source.group1_key);
+ expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
+ source.group2_key, kEndpoint1_);
+ expected_commands.emplace_back(
+ CommandType::UPDATE_REPORTING_ENDPOINT_DETAILS, source.group2_key,
+ kEndpoint2_);
+ expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
+ source.group2_key, kEndpoint3_);
+ expected_commands.emplace_back(
+ CommandType::UPDATE_REPORTING_ENDPOINT_GROUP_DETAILS,
+ source.group2_key);
+ EXPECT_THAT(mock_store()->GetAllCommands(),
+ testing::IsSupersetOf(expected_commands));
+ }
+ }
+
+ // Check that expected data is present in the ReportingCache at the end.
+ for (const auto& source : kHeaderSources) {
+ EXPECT_FALSE(FindEndpointInCache(source.group1_key, kEndpoint1_));
+ EXPECT_FALSE(FindEndpointInCache(source.group1_key, kEndpoint2_));
+ EXPECT_FALSE(FindEndpointInCache(source.group2_key, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(source.group2_key, kEndpoint3_));
+ EXPECT_FALSE(EndpointGroupExistsInCache(source.group1_key,
+ OriginSubdomains::DEFAULT));
+ EXPECT_TRUE(EndpointGroupExistsInCache(source.group2_key,
+ OriginSubdomains::INCLUDE));
+ EXPECT_TRUE(cache()->ClientExistsForTesting(
+ source.network_isolation_key, url::Origin::Create(source.url)));
+ }
+}
+
TEST_P(ReportingHeaderParserTest,
HeaderErroneouslyContainsMultipleGroupsOfSameName) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_}};
std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint2_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1)) +
- ", " + ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints2));
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1)) +
+ ", " +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints2));
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
// Result is as if they set the two groups with the same name as one group.
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(2u, cache()->GetEndpointCount());
- ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey_, kEndpoint_);
+ ReportingEndpoint endpoint = FindEndpointInCache(kGroupKey11_, kEndpoint1_);
ASSERT_TRUE(endpoint);
- EXPECT_EQ(kOrigin_, endpoint.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint.group_key.group_name);
+ EXPECT_EQ(kOrigin1_, endpoint.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint.group_key.group_name);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
endpoint.info.weight);
- ReportingEndpoint endpoint2 = FindEndpointInCache(kGroupKey_, kEndpoint2_);
+ ReportingEndpoint endpoint2 = FindEndpointInCache(kGroupKey11_, kEndpoint2_);
ASSERT_TRUE(endpoint2);
- EXPECT_EQ(kOrigin_, endpoint2.group_key.origin);
- EXPECT_EQ(kGroup_, endpoint2.group_key.group_name);
+ EXPECT_EQ(kOrigin1_, endpoint2.group_key.origin);
+ EXPECT_EQ(kGroup1_, endpoint2.group_key.group_name);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultPriority,
endpoint2.info.priority);
EXPECT_EQ(ReportingEndpoint::EndpointInfo::kDefaultWeight,
@@ -755,11 +948,11 @@ TEST_P(ReportingHeaderParserTest,
EXPECT_EQ(1, mock_store()->StoredEndpointGroupsCount());
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint2_);
+ kGroupKey11_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -767,83 +960,84 @@ TEST_P(ReportingHeaderParserTest,
TEST_P(ReportingHeaderParserTest,
HeaderErroneouslyContainsGroupsWithRedundantEndpoints) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_},
- {kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_},
+ {kEndpoint1_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, kUrl1_, header);
// We should dedupe the identical endpoint URLs.
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ASSERT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
+ ASSERT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
}
TEST_P(ReportingHeaderParserTest,
HeaderErroneouslyContainsMultipleGroupsOfSameNameAndEndpoints) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{kEndpoint1_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints)) + ", " +
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints)) +
+ ", " + ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, kUrl1_, header);
// We should dedupe the identical endpoint URLs, even when they're in
- // different headers.
+ // different group.
EXPECT_EQ(1u, cache()->GetEndpointCount());
- ASSERT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
+ ASSERT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
}
TEST_P(ReportingHeaderParserTest,
HeaderErroneouslyContainsGroupsOfSameNameAndOverlappingEndpoints) {
- std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint_},
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_},
{kEndpoint2_}};
- std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint_},
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint1_},
{kEndpoint3_}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1)) +
- ", " + ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints2));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1)) +
+ ", " +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints2));
+ ParseHeader(kNik_, kUrl1_, header);
// We should dedupe the identical endpoint URLs, even when they're in
- // different headers.
+ // different group.
EXPECT_EQ(3u, cache()->GetEndpointCount());
- ASSERT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
- ASSERT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint2_));
- ASSERT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint3_));
+ ASSERT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
+ ASSERT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint2_));
+ ASSERT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint3_));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
}
TEST_P(ReportingHeaderParserTest, OverwriteOldHeader) {
// First, the origin sets a header with two endpoints in the same group.
std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {
- {kEndpoint_, 10 /* priority */}, {kEndpoint2_}};
+ {kEndpoint1_, 10 /* priority */}, {kEndpoint2_}};
std::string header1 =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1));
- ParseHeader(kUrl_, header1);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1));
+ ParseHeader(kNik_, kUrl1_, header1);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_EQ(2u, cache()->GetEndpointCount());
- EXPECT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
- EXPECT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint2_));
if (mock_store()) {
mock_store()->Flush();
EXPECT_EQ(2,
@@ -852,11 +1046,11 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeader) {
CommandType::ADD_REPORTING_ENDPOINT_GROUP));
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint2_);
+ kGroupKey11_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -864,28 +1058,28 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeader) {
// Second header from the same origin should overwrite the previous one.
std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {
// This endpoint should update the priority of the existing one.
- {kEndpoint_, 20 /* priority */}};
+ {kEndpoint1_, 20 /* priority */}};
// The second endpoint in this group will be deleted.
// This group is new.
std::vector<ReportingEndpoint::EndpointInfo> endpoints3 = {{kEndpoint2_}};
std::string header2 =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints2)) +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints2)) +
", " +
ConstructHeaderGroupString(MakeEndpointGroup(kGroup2_, endpoints3));
- ParseHeader(kUrl_, header2);
+ ParseHeader(kNik_, kUrl1_, header2);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey2_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey12_, OriginSubdomains::DEFAULT));
EXPECT_EQ(2u, cache()->GetEndpointCount());
- EXPECT_TRUE(FindEndpointInCache(kGroupKey_, kEndpoint_));
- EXPECT_EQ(20, FindEndpointInCache(kGroupKey_, kEndpoint_).info.priority);
- EXPECT_FALSE(FindEndpointInCache(kGroupKey_, kEndpoint2_));
- EXPECT_TRUE(FindEndpointInCache(kGroupKey2_, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey11_, kEndpoint1_));
+ EXPECT_EQ(20, FindEndpointInCache(kGroupKey11_, kEndpoint1_).info.priority);
+ EXPECT_FALSE(FindEndpointInCache(kGroupKey11_, kEndpoint2_));
+ EXPECT_TRUE(FindEndpointInCache(kGroupKey12_, kEndpoint2_));
if (mock_store()) {
mock_store()->Flush();
EXPECT_EQ(2 + 1,
@@ -896,22 +1090,22 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeader) {
1, mock_store()->CountCommands(CommandType::DELETE_REPORTING_ENDPOINT));
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey2_, kEndpoint2_);
+ kGroupKey12_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey2_);
+ kGroupKey12_);
expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint2_);
+ kGroupKey11_, kEndpoint2_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
}
TEST_P(ReportingHeaderParserTest, OverwriteOldHeaderWithCompletelyNew) {
- ReportingEndpointGroupKey kGroupKey1(NetworkIsolationKey(), kOrigin_, "1");
- ReportingEndpointGroupKey kGroupKey2(NetworkIsolationKey(), kOrigin_, "2");
- ReportingEndpointGroupKey kGroupKey3(NetworkIsolationKey(), kOrigin_, "3");
- ReportingEndpointGroupKey kGroupKey4(NetworkIsolationKey(), kOrigin_, "4");
- ReportingEndpointGroupKey kGroupKey5(NetworkIsolationKey(), kOrigin_, "5");
+ ReportingEndpointGroupKey kGroupKey1(kNik_, kOrigin1_, "1");
+ ReportingEndpointGroupKey kGroupKey2(kNik_, kOrigin1_, "2");
+ ReportingEndpointGroupKey kGroupKey3(kNik_, kOrigin1_, "3");
+ ReportingEndpointGroupKey kGroupKey4(kNik_, kOrigin1_, "4");
+ ReportingEndpointGroupKey kGroupKey5(kNik_, kOrigin1_, "5");
std::vector<ReportingEndpoint::EndpointInfo> endpoints1_1 = {{MakeURL(10)},
{MakeURL(11)}};
std::vector<ReportingEndpoint::EndpointInfo> endpoints2_1 = {{MakeURL(20)},
@@ -922,8 +1116,8 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeaderWithCompletelyNew) {
ConstructHeaderGroupString(MakeEndpointGroup("1", endpoints1_1)) + ", " +
ConstructHeaderGroupString(MakeEndpointGroup("2", endpoints2_1)) + ", " +
ConstructHeaderGroupString(MakeEndpointGroup("3", endpoints3_1));
- ParseHeader(kUrl_, header1);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ ParseHeader(kNik_, kUrl1_, header1);
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(3u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
EndpointGroupExistsInCache(kGroupKey1, OriginSubdomains::DEFAULT));
@@ -969,8 +1163,8 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeaderWithCompletelyNew) {
ConstructHeaderGroupString(MakeEndpointGroup("1", endpoints1_2)) + ", " +
ConstructHeaderGroupString(MakeEndpointGroup("2", endpoints2_2)) + ", " +
ConstructHeaderGroupString(MakeEndpointGroup("3", endpoints3_2));
- ParseHeader(kUrl_, header2);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ ParseHeader(kNik_, kUrl1_, header2);
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(3u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
EndpointGroupExistsInCache(kGroupKey1, OriginSubdomains::DEFAULT));
@@ -1027,8 +1221,8 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeaderWithCompletelyNew) {
std::string header3 =
ConstructHeaderGroupString(MakeEndpointGroup("4", endpoints4_3)) + ", " +
ConstructHeaderGroupString(MakeEndpointGroup("5", endpoints5_3));
- ParseHeader(kUrl_, header3);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ ParseHeader(kNik_, kUrl1_, header3);
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(2u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
EndpointGroupExistsInCache(kGroupKey4, OriginSubdomains::DEFAULT));
@@ -1080,8 +1274,9 @@ TEST_P(ReportingHeaderParserTest, OverwriteOldHeaderWithCompletelyNew) {
TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
// Without a pre-existing client, max_age: 0 should do nothing.
ASSERT_EQ(0u, cache()->GetEndpointCount());
- ParseHeader(kUrl_, "{\"endpoints\":[{\"url\":\"" + kEndpoint_.spec() +
- "\"}],\"max_age\":0}");
+ ParseHeader(kNik_, kUrl1_,
+ "{\"endpoints\":[{\"url\":\"" + kEndpoint1_.spec() +
+ "\"}],\"max_age\":0}");
EXPECT_EQ(0u, cache()->GetEndpointCount());
if (mock_store()) {
mock_store()->Flush();
@@ -1092,20 +1287,20 @@ TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
}
// Set a header with two endpoint groups.
- std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint_}};
+ std::vector<ReportingEndpoint::EndpointInfo> endpoints1 = {{kEndpoint1_}};
std::vector<ReportingEndpoint::EndpointInfo> endpoints2 = {{kEndpoint2_}};
std::string header1 =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints1)) +
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints1)) +
", " +
ConstructHeaderGroupString(MakeEndpointGroup(kGroup2_, endpoints2));
- ParseHeader(kUrl_, header1);
+ ParseHeader(kNik_, kUrl1_, header1);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(2u, cache()->GetEndpointGroupCountForTesting());
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey2_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey12_, OriginSubdomains::DEFAULT));
EXPECT_EQ(2u, cache()->GetEndpointCount());
if (mock_store()) {
mock_store()->Flush();
@@ -1115,35 +1310,35 @@ TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
CommandType::ADD_REPORTING_ENDPOINT_GROUP));
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT,
- kGroupKey2_, kEndpoint2_);
+ kGroupKey12_, kEndpoint2_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
expected_commands.emplace_back(CommandType::ADD_REPORTING_ENDPOINT_GROUP,
- kGroupKey2_);
+ kGroupKey12_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
// Set another header with max_age: 0 to delete one of the groups.
std::string header2 = ConstructHeaderGroupString(MakeEndpointGroup(
- kGroup_, endpoints1, OriginSubdomains::DEFAULT,
+ kGroup1_, endpoints1, OriginSubdomains::DEFAULT,
base::TimeDelta::FromSeconds(0))) +
", " +
ConstructHeaderGroupString(MakeEndpointGroup(
kGroup2_, endpoints2)); // Other group stays.
- ParseHeader(kUrl_, header2);
+ ParseHeader(kNik_, kUrl1_, header2);
- EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_TRUE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(1u, cache()->GetEndpointGroupCountForTesting());
// Group was deleted.
EXPECT_FALSE(
- EndpointGroupExistsInCache(kGroupKey_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey11_, OriginSubdomains::DEFAULT));
// Other group remains in the cache.
EXPECT_TRUE(
- EndpointGroupExistsInCache(kGroupKey2_, OriginSubdomains::DEFAULT));
+ EndpointGroupExistsInCache(kGroupKey12_, OriginSubdomains::DEFAULT));
EXPECT_EQ(1u, cache()->GetEndpointCount());
if (mock_store()) {
mock_store()->Flush();
@@ -1157,9 +1352,9 @@ TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
CommandType::DELETE_REPORTING_ENDPOINT_GROUP));
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
- kGroupKey_, kEndpoint_);
+ kGroupKey11_, kEndpoint1_);
expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT_GROUP,
- kGroupKey_);
+ kGroupKey11_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -1169,11 +1364,11 @@ TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
std::string header3 = ConstructHeaderGroupString(MakeEndpointGroup(
kGroup2_, std::vector<ReportingEndpoint::EndpointInfo>(),
OriginSubdomains::DEFAULT, base::TimeDelta::FromSeconds(0)));
- ParseHeader(kUrl_, header3);
+ ParseHeader(kNik_, kUrl1_, header3);
// Deletion of the last remaining group also deletes the client for this
// origin.
- EXPECT_FALSE(ClientExistsInCacheForOrigin(kOrigin_));
+ EXPECT_FALSE(ClientExistsInCacheForOrigin(kOrigin1_));
EXPECT_EQ(0u, cache()->GetEndpointGroupCountForTesting());
EXPECT_EQ(0u, cache()->GetEndpointCount());
if (mock_store()) {
@@ -1188,9 +1383,9 @@ TEST_P(ReportingHeaderParserTest, ZeroMaxAgeRemovesEndpointGroup) {
CommandType::DELETE_REPORTING_ENDPOINT_GROUP));
MockPersistentReportingStore::CommandList expected_commands;
expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT,
- kGroupKey2_, kEndpoint2_);
+ kGroupKey12_, kEndpoint2_);
expected_commands.emplace_back(CommandType::DELETE_REPORTING_ENDPOINT_GROUP,
- kGroupKey2_);
+ kGroupKey12_);
EXPECT_THAT(mock_store()->GetAllCommands(),
testing::IsSupersetOf(expected_commands));
}
@@ -1203,8 +1398,8 @@ TEST_P(ReportingHeaderParserTest, EvictEndpointsOverPerOriginLimit1) {
endpoints.push_back({MakeURL(i)});
}
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(kUrl_, header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, kUrl1_, header);
// Endpoint count should be at most the limit.
EXPECT_GE(policy().max_endpoints_per_origin, cache()->GetEndpointCount());
@@ -1231,7 +1426,7 @@ TEST_P(ReportingHeaderParserTest, EvictEndpointsOverPerOriginLimit2) {
if (i != policy().max_endpoints_per_origin)
header = header + ", ";
}
- ParseHeader(kUrl_, header);
+ ParseHeader(kNik_, kUrl1_, header);
// Endpoint count should be at most the limit.
EXPECT_GE(policy().max_endpoints_per_origin, cache()->GetEndpointCount());
@@ -1256,14 +1451,15 @@ TEST_P(ReportingHeaderParserTest, EvictEndpointsOverGlobalLimit) {
for (size_t i = 0; i < policy().max_endpoint_count; ++i) {
std::vector<ReportingEndpoint::EndpointInfo> endpoints = {{MakeURL(i)}};
std::string header =
- ConstructHeaderGroupString(MakeEndpointGroup(kGroup_, endpoints));
- ParseHeader(MakeURL(i), header);
+ ConstructHeaderGroupString(MakeEndpointGroup(kGroup1_, endpoints));
+ ParseHeader(kNik_, MakeURL(i), header);
}
EXPECT_EQ(policy().max_endpoint_count, cache()->GetEndpointCount());
// Parse one more header to trigger eviction.
- ParseHeader(kUrl_, "{\"endpoints\":[{\"url\":\"" + kEndpoint_.spec() +
- "\"}],\"max_age\":1}");
+ ParseHeader(kNik_, kUrl1_,
+ "{\"endpoints\":[{\"url\":\"" + kEndpoint1_.spec() +
+ "\"}],\"max_age\":1}");
// Endpoint count should be at most the limit.
EXPECT_GE(policy().max_endpoint_count, cache()->GetEndpointCount());
diff --git a/chromium/net/reporting/reporting_network_change_observer_unittest.cc b/chromium/net/reporting/reporting_network_change_observer_unittest.cc
index d5e07701b67..f5ae0ce626b 100644
--- a/chromium/net/reporting/reporting_network_change_observer_unittest.cc
+++ b/chromium/net/reporting/reporting_network_change_observer_unittest.cc
@@ -43,6 +43,7 @@ class ReportingNetworkChangeObserverTest : public ReportingTestBase {
return reports.size();
}
+ const NetworkIsolationKey kNik_;
const GURL kUrl_ = GURL("https://origin/path");
const url::Origin kOrigin_ = url::Origin::Create(kUrl_);
const GURL kEndpoint_ = GURL("https://endpoint/");
@@ -59,7 +60,7 @@ TEST_F(ReportingNetworkChangeObserverTest, ClearNothing) {
new_policy.persist_clients_across_network_changes = true;
UsePolicy(new_policy);
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
SetEndpoint();
@@ -78,7 +79,7 @@ TEST_F(ReportingNetworkChangeObserverTest, ClearReports) {
new_policy.persist_clients_across_network_changes = true;
UsePolicy(new_policy);
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
SetEndpoint();
@@ -97,7 +98,7 @@ TEST_F(ReportingNetworkChangeObserverTest, ClearClients) {
new_policy.persist_clients_across_network_changes = false;
UsePolicy(new_policy);
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
SetEndpoint();
@@ -116,7 +117,7 @@ TEST_F(ReportingNetworkChangeObserverTest, ClearReportsAndClients) {
new_policy.persist_clients_across_network_changes = false;
UsePolicy(new_policy);
- cache()->AddReport(kUrl_, kUserAgent_, kGroup_, kType_,
+ cache()->AddReport(kNik_, kUrl_, kUserAgent_, kGroup_, kType_,
std::make_unique<base::DictionaryValue>(), 0,
tick_clock()->NowTicks(), 0);
SetEndpoint();
diff --git a/chromium/net/reporting/reporting_report.cc b/chromium/net/reporting/reporting_report.cc
index 5c7f3e57291..63648cff1b9 100644
--- a/chromium/net/reporting/reporting_report.cc
+++ b/chromium/net/reporting/reporting_report.cc
@@ -24,15 +24,18 @@ void RecordReportOutcome(ReportingReport::Outcome outcome) {
} // namespace
-ReportingReport::ReportingReport(const GURL& url,
- const std::string& user_agent,
- const std::string& group,
- const std::string& type,
- std::unique_ptr<const base::Value> body,
- int depth,
- base::TimeTicks queued,
- int attempts)
- : url(url),
+ReportingReport::ReportingReport(
+ const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
+ const std::string& user_agent,
+ const std::string& group,
+ const std::string& type,
+ std::unique_ptr<const base::Value> body,
+ int depth,
+ base::TimeTicks queued,
+ int attempts)
+ : network_isolation_key(network_isolation_key),
+ url(url),
user_agent(user_agent),
group(group),
type(type),
diff --git a/chromium/net/reporting/reporting_report.h b/chromium/net/reporting/reporting_report.h
index a80fa6c410b..02018ad25df 100644
--- a/chromium/net/reporting/reporting_report.h
+++ b/chromium/net/reporting/reporting_report.h
@@ -11,6 +11,7 @@
#include "base/optional.h"
#include "base/time/time.h"
#include "net/base/net_export.h"
+#include "net/base/network_isolation_key.h"
#include "url/gurl.h"
namespace base {
@@ -51,7 +52,8 @@ struct NET_EXPORT ReportingReport {
};
// TODO(chlily): Remove |attempts| argument as it is (almost?) always 0.
- ReportingReport(const GURL& url,
+ ReportingReport(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
const std::string& user_agent,
const std::string& group,
const std::string& type,
@@ -69,6 +71,10 @@ struct NET_EXPORT ReportingReport {
// Whether the report is part of an ongoing delivery attempt.
bool IsUploadPending() const;
+ // The NIK of the request that triggered this report. (Not included in the
+ // delivered report.)
+ NetworkIsolationKey network_isolation_key;
+
// The URL of the document that triggered the report. (Included in the
// delivered report.)
GURL url;
diff --git a/chromium/net/reporting/reporting_service.cc b/chromium/net/reporting/reporting_service.cc
index a10ca1002b5..2a410343302 100644
--- a/chromium/net/reporting/reporting_service.cc
+++ b/chromium/net/reporting/reporting_service.cc
@@ -71,10 +71,12 @@ class ReportingServiceImpl : public ReportingService {
// base::Unretained is safe because the callback is stored in
// |task_backlog_| which will not outlive |this|.
- DoOrBacklogTask(base::BindOnce(&ReportingServiceImpl::DoQueueReport,
- base::Unretained(this),
- std::move(sanitized_url), user_agent, group,
- type, std::move(body), depth, queued_ticks));
+ // TODO(chlily): Get NetworkIsolationKey from caller.
+ NetworkIsolationKey network_isolation_key = NetworkIsolationKey::Todo();
+ DoOrBacklogTask(base::BindOnce(
+ &ReportingServiceImpl::DoQueueReport, base::Unretained(this),
+ network_isolation_key, std::move(sanitized_url), user_agent, group,
+ type, std::move(body), depth, queued_ticks));
}
void ProcessHeader(const GURL& url,
@@ -93,9 +95,10 @@ class ReportingServiceImpl : public ReportingService {
}
DVLOG(1) << "Received Reporting policy for " << url.GetOrigin();
- DoOrBacklogTask(base::BindOnce(&ReportingServiceImpl::DoProcessHeader,
- base::Unretained(this), url,
- std::move(header_value)));
+ // TODO(chlily): Get the proper NetworkIsolationKey from the caller.
+ DoOrBacklogTask(base::BindOnce(
+ &ReportingServiceImpl::DoProcessHeader, base::Unretained(this),
+ NetworkIsolationKey::Todo(), url, std::move(header_value)));
}
void RemoveBrowsingData(int data_type_mask,
@@ -148,7 +151,8 @@ class ReportingServiceImpl : public ReportingService {
std::move(task).Run();
}
- void DoQueueReport(GURL sanitized_url,
+ void DoQueueReport(const NetworkIsolationKey& network_isolation_key,
+ GURL sanitized_url,
const std::string& user_agent,
const std::string& group,
const std::string& type,
@@ -156,16 +160,17 @@ class ReportingServiceImpl : public ReportingService {
int depth,
base::TimeTicks queued_ticks) {
DCHECK(initialized_);
- context_->cache()->AddReport(sanitized_url, user_agent, group, type,
- std::move(body), depth, queued_ticks,
- 0 /* attempts */);
+ context_->cache()->AddReport(network_isolation_key, sanitized_url,
+ user_agent, group, type, std::move(body),
+ depth, queued_ticks, 0 /* attempts */);
}
- void DoProcessHeader(const GURL& url,
+ void DoProcessHeader(const NetworkIsolationKey& network_isolation_key,
+ const GURL& url,
std::unique_ptr<base::Value> header_value) {
DCHECK(initialized_);
- ReportingHeaderParser::ParseHeader(context_.get(), url,
- std::move(header_value));
+ ReportingHeaderParser::ParseHeader(context_.get(), network_isolation_key,
+ url, std::move(header_value));
}
void DoRemoveBrowsingData(
diff --git a/chromium/net/reporting/reporting_test_util.cc b/chromium/net/reporting/reporting_test_util.cc
index 490231d3771..47ebd724330 100644
--- a/chromium/net/reporting/reporting_test_util.cc
+++ b/chromium/net/reporting/reporting_test_util.cc
@@ -9,9 +9,10 @@
#include <vector>
#include "base/bind.h"
+#include "base/check_op.h"
#include "base/json/json_reader.h"
-#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "base/notreached.h"
#include "base/strings/stringprintf.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
diff --git a/chromium/net/reporting/reporting_uploader_unittest.cc b/chromium/net/reporting/reporting_uploader_unittest.cc
index b1fb4ad3122..66b61e7e4ef 100644
--- a/chromium/net/reporting/reporting_uploader_unittest.cc
+++ b/chromium/net/reporting/reporting_uploader_unittest.cc
@@ -452,7 +452,7 @@ TEST_F(ReportingUploaderTest, DontSendCookies) {
auto cookie = CanonicalCookie::Create(url, "foo=bar", base::Time::Now(),
base::nullopt /* server_time */);
context_.cookie_store()->SetCanonicalCookieAsync(
- std::move(cookie), url.scheme(), CookieOptions::MakeAllInclusive(),
+ std::move(cookie), url, CookieOptions::MakeAllInclusive(),
cookie_callback.MakeCallback());
cookie_callback.WaitUntilDone();
ASSERT_TRUE(cookie_callback.result().IsInclude());