123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971 |
- // Copyright 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "services/network/first_party_sets/first_party_sets_manager.h"
- #include <set>
- #include <string>
- #include "base/containers/flat_set.h"
- #include "base/test/task_environment.h"
- #include "base/test/test_future.h"
- #include "net/base/schemeful_site.h"
- #include "net/cookies/cookie_constants.h"
- #include "net/cookies/first_party_set_entry.h"
- #include "net/cookies/first_party_set_metadata.h"
- #include "net/cookies/same_party_context.h"
- #include "services/network/public/mojom/first_party_sets.mojom.h"
- #include "testing/gmock/include/gmock/gmock-matchers.h"
- #include "testing/gmock/include/gmock/gmock.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "third_party/abseil-cpp/absl/types/optional.h"
- #include "url/gurl.h"
- using ::testing::IsEmpty;
- using ::testing::Pair;
- using ::testing::UnorderedElementsAre;
- using ::testing::Value;
- using Type = net::SamePartyContext::Type;
- using OverrideSets =
- base::flat_map<net::SchemefulSite, absl::optional<net::FirstPartySetEntry>>;
- namespace network {
- MATCHER_P(SerializesTo, want, "") {
- const std::string got = arg.Serialize();
- return testing::ExplainMatchResult(testing::Eq(want), got, result_listener);
- }
- class FirstPartySetsManagerTest : public ::testing::Test {
- public:
- explicit FirstPartySetsManagerTest(bool enabled, bool context_enabled)
- : manager_(enabled), fps_context_config_(context_enabled) {}
- void SetCompleteSets(
- const base::flat_map<net::SchemefulSite, net::FirstPartySetEntry>&
- content,
- const base::flat_map<net::SchemefulSite, net::SchemefulSite>& aliases) {
- network::mojom::PublicFirstPartySetsPtr public_sets =
- network::mojom::PublicFirstPartySets::New();
- public_sets->sets = content;
- public_sets->aliases = aliases;
- manager_.SetCompleteSets(std::move(public_sets));
- }
- net::FirstPartySetMetadata ComputeMetadataAndWait(
- const net::SchemefulSite& site,
- const net::SchemefulSite* top_frame_site,
- const std::set<net::SchemefulSite>& party_context) {
- base::test::TestFuture<net::FirstPartySetMetadata> future;
- absl::optional<net::FirstPartySetMetadata> result =
- manager_.ComputeMetadata(site, top_frame_site, party_context,
- fps_context_config_, future.GetCallback());
- return result.has_value() ? std::move(result).value() : future.Take();
- }
- FirstPartySetsManager::OwnersResult FindOwnersAndWait(
- const base::flat_set<net::SchemefulSite>& site) {
- base::test::TestFuture<FirstPartySetsManager::OwnersResult> future;
- absl::optional<FirstPartySetsManager::OwnersResult> result =
- manager_.FindOwners(site, fps_context_config_, future.GetCallback());
- return result.has_value() ? result.value() : future.Get();
- }
- FirstPartySetsManager& manager() { return manager_; }
- net::FirstPartySetsContextConfig& fps_context_config() {
- return fps_context_config_;
- }
- base::test::TaskEnvironment& env() { return env_; }
- protected:
- void SetFirstPartySetsContextConfig(bool enabled,
- OverrideSets customizations) {
- fps_context_config_ = net::FirstPartySetsContextConfig(enabled);
- fps_context_config_.SetCustomizations(std::move(customizations));
- }
- private:
- base::test::TaskEnvironment env_;
- FirstPartySetsManager manager_;
- net::FirstPartySetsContextConfig fps_context_config_;
- };
- class FirstPartySetsManagerDisabledTest : public FirstPartySetsManagerTest {
- public:
- FirstPartySetsManagerDisabledTest()
- : FirstPartySetsManagerTest(/*enabled=*/false, /*context_enabled=*/true) {
- }
- };
- TEST_F(FirstPartySetsManagerDisabledTest, SetCompleteSets) {
- net::SchemefulSite example_cctld(GURL("https://example.cctld"));
- net::SchemefulSite example_test(GURL("https://example.test"));
- net::SchemefulSite aaaa(GURL("https://aaaa.test"));
- SetCompleteSets({{aaaa, net::FirstPartySetEntry(
- example_test, net::SiteType::kAssociated, 0)},
- {example_test,
- net::FirstPartySetEntry(
- example_test, net::SiteType::kPrimary, absl::nullopt)}},
- {{example_cctld, example_test}});
- EXPECT_THAT(FindOwnersAndWait({
- aaaa,
- example_test,
- example_cctld,
- }),
- IsEmpty());
- }
- TEST_F(FirstPartySetsManagerDisabledTest, FindOwners) {
- net::SchemefulSite kExample =
- net::SchemefulSite(GURL("https://example.test"));
- EXPECT_THAT(FindOwnersAndWait({kExample}), IsEmpty());
- }
- TEST_F(FirstPartySetsManagerDisabledTest, ComputeMetadata_InfersSingletons) {
- net::SchemefulSite member(GURL("https://member1.test"));
- net::SchemefulSite example(GURL("https://example.test"));
- net::SchemefulSite wss_member(GURL("wss://member1.test"));
- SetFirstPartySetsContextConfig(
- true, {{net::SchemefulSite(GURL("https://member1.test")),
- {net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0)}},
- {net::SchemefulSite(GURL("https://example.test")),
- {net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt)}}});
- // Works if the site is provided with WSS scheme instead of HTTPS.
- EXPECT_THAT(
- ComputeMetadataAndWait(wss_member, &member, {member, example}).context(),
- net::SamePartyContext(Type::kCrossParty));
- EXPECT_THAT(ComputeMetadataAndWait(example, &member, {member}).context(),
- net::SamePartyContext(Type::kCrossParty));
- EXPECT_THAT(ComputeMetadataAndWait(member, &example, {member}).context(),
- net::SamePartyContext(Type::kCrossParty));
- EXPECT_THAT(
- ComputeMetadataAndWait(member, &member, {member, example}).context(),
- net::SamePartyContext(Type::kCrossParty));
- }
- class FirstPartySetsEnabledTest : public FirstPartySetsManagerTest {
- public:
- FirstPartySetsEnabledTest()
- : FirstPartySetsManagerTest(/*enabled=*/true, /*context_enabled=*/true) {}
- };
- TEST_F(FirstPartySetsEnabledTest, SetCompleteSets) {
- net::SchemefulSite example_cctld(GURL("https://example.cctld"));
- net::SchemefulSite example_test(GURL("https://example.test"));
- net::SchemefulSite aaaa(GURL("https://aaaa.test"));
- SetCompleteSets({{aaaa, net::FirstPartySetEntry(
- example_test, net::SiteType::kAssociated, 0)},
- {example_test,
- net::FirstPartySetEntry(
- example_test, net::SiteType::kPrimary, absl::nullopt)}},
- {{example_cctld, example_test}});
- EXPECT_THAT(
- FindOwnersAndWait({
- aaaa,
- example_test,
- example_cctld,
- }),
- UnorderedElementsAre(
- Pair(example_test,
- net::FirstPartySetEntry(example_test, net::SiteType::kPrimary,
- absl::nullopt)),
- Pair(example_cctld,
- net::FirstPartySetEntry(example_test, net::SiteType::kPrimary,
- absl::nullopt)),
- Pair(aaaa, net::FirstPartySetEntry(example_test,
- net::SiteType::kAssociated, 0))));
- }
- TEST_F(FirstPartySetsEnabledTest, SetCompleteSets_Idempotent) {
- SetCompleteSets({}, {});
- EXPECT_THAT(FindOwnersAndWait({}), IsEmpty());
- // The second call to SetCompleteSets should have no effect.
- SetCompleteSets({{net::SchemefulSite(GURL("https://aaaa.test")),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0)},
- {net::SchemefulSite(GURL("https://example.test")),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt)}},
- {});
- EXPECT_THAT(FindOwnersAndWait({
- net::SchemefulSite(GURL("https://aaaa.test")),
- net::SchemefulSite(GURL("https://example.test")),
- }),
- IsEmpty());
- }
- // Test fixture that allows precise control over when the instance gets FPS
- // data. Useful for testing async flows.
- class AsyncPopulatedFirstPartySetsManagerTest
- : public FirstPartySetsEnabledTest {
- public:
- AsyncPopulatedFirstPartySetsManagerTest() = default;
- protected:
- void Populate() {
- net::SchemefulSite foo(GURL("https://foo.test"));
- net::SchemefulSite example_test(GURL("https://example.test"));
- net::SchemefulSite example_cctld(GURL("https://example.cctld"));
- // /*content=*/ R"(
- // [
- // {
- // "owner": "https://example.test",
- // "members": ["https://member1.test", "https://member3.test"]
- // },
- // {
- // "owner": "https://foo.test",
- // "members": ["https://member2.test"]
- // }
- // ]
- // )";
- SetCompleteSets(
- {
- {net::SchemefulSite(GURL("https://member1.test")),
- net::FirstPartySetEntry(example_test, net::SiteType::kAssociated,
- 0)},
- {net::SchemefulSite(GURL("https://member3.test")),
- net::FirstPartySetEntry(example_test, net::SiteType::kAssociated,
- 0)},
- {example_test,
- net::FirstPartySetEntry(example_test, net::SiteType::kPrimary,
- absl::nullopt)},
- {net::SchemefulSite(GURL("https://member2.test")),
- net::FirstPartySetEntry(foo, net::SiteType::kAssociated, 0)},
- {foo, net::FirstPartySetEntry(foo, net::SiteType::kPrimary,
- absl::nullopt)},
- },
- {{example_cctld, example_test}});
- // We don't wait for the sets to be loaded before returning, in order to let
- // the tests provoke raciness if any exists.
- }
- };
- TEST_F(AsyncPopulatedFirstPartySetsManagerTest,
- QueryBeforeReady_ComputeMetadata) {
- base::test::TestFuture<net::FirstPartySetMetadata> future;
- {
- // Force deallocation to provoke a UAF if the impl just copies the pointer.
- net::SchemefulSite member(GURL("https://member1.test"));
- EXPECT_FALSE(manager().ComputeMetadata(
- member, &member, {member}, fps_context_config(), future.GetCallback()));
- }
- Populate();
- {
- net::SchemefulSite owner(GURL("https://example.test"));
- net::FirstPartySetEntry entry(owner, net::SiteType::kAssociated, 0);
- EXPECT_EQ(future.Get(),
- net::FirstPartySetMetadata(
- net::SamePartyContext(Type::kSameParty), &entry, &entry));
- }
- }
- TEST_F(AsyncPopulatedFirstPartySetsManagerTest, QueryBeforeReady_FindOwners) {
- base::test::TestFuture<FirstPartySetsManager::OwnersResult> future;
- EXPECT_FALSE(manager().FindOwners(
- {
- net::SchemefulSite(GURL("https://member1.test")),
- net::SchemefulSite(GURL("https://member2.test")),
- net::SchemefulSite(GURL("https://example.cctld")),
- },
- fps_context_config(), future.GetCallback()));
- Populate();
- EXPECT_THAT(future.Get(),
- UnorderedElementsAre(
- Pair(SerializesTo("https://member1.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0)),
- Pair(SerializesTo("https://example.cctld"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt)),
- Pair(SerializesTo("https://member2.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://foo.test")),
- net::SiteType::kAssociated, 0))));
- }
- class PopulatedFirstPartySetsManagerTest
- : public AsyncPopulatedFirstPartySetsManagerTest {
- public:
- PopulatedFirstPartySetsManagerTest() { Populate(); }
- };
- TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata_EmptyContext) {
- net::SchemefulSite example_site(GURL("https://example.test"));
- net::SchemefulSite nonmember(GURL("https://nonmember.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame, {})
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(example_site, top_frame, {})
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, {})
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- EXPECT_EQ(ComputeMetadataAndWait(example_site, &nonmember, {})
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(nonmember, &example_site, {})
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata_ContextIsNonmember) {
- std::set<net::SchemefulSite> context({
- net::SchemefulSite(GURL("https://nonmember.test")),
- });
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata_ContextIsOwner) {
- std::set<net::SchemefulSite> context(
- {net::SchemefulSite(GURL("https://example.test"))});
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata_ContextIsMember) {
- std::set<net::SchemefulSite> context(
- {net::SchemefulSite(GURL("https://member1.test"))});
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest,
- ComputeMetadata_ContextIsOwnerAndMember) {
- std::set<net::SchemefulSite> context({
- net::SchemefulSite(GURL("https://example.test")),
- net::SchemefulSite(GURL("https://member1.test")),
- });
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member3.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kSameParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest,
- ComputeMetadata_ContextMixesParties) {
- std::set<net::SchemefulSite> context({
- net::SchemefulSite(GURL("https://example.test")),
- net::SchemefulSite(GURL("https://member1.test")),
- net::SchemefulSite(GURL("https://foo.test")),
- });
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest,
- ComputeMetadata_ContextMixesMembersAndNonmembers) {
- std::set<net::SchemefulSite> context({
- net::SchemefulSite(GURL("https://example.test")),
- net::SchemefulSite(GURL("https://member1.test")),
- net::SchemefulSite(GURL("http://nonmember.test")),
- });
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest,
- ComputeMetadata_ContextMixesSchemes) {
- std::set<net::SchemefulSite> context({
- net::SchemefulSite(GURL("https://example.test")),
- net::SchemefulSite(GURL("https://member1.test")),
- net::SchemefulSite(GURL("http://example.test")),
- });
- net::SchemefulSite example_site(GURL("https://example.test"));
- for (const net::SchemefulSite* top_frame :
- std::initializer_list<net::SchemefulSite*>{&example_site, nullptr}) {
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("http://example.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member1.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://foo.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(
- ComputeMetadataAndWait(net::SchemefulSite(GURL("https://member2.test")),
- top_frame, context)
- .context()
- .context_type(),
- Type::kCrossParty);
- EXPECT_EQ(ComputeMetadataAndWait(
- net::SchemefulSite(GURL("https://nonmember.test")), top_frame,
- context)
- .context()
- .context_type(),
- Type::kCrossParty);
- }
- }
- TEST_F(PopulatedFirstPartySetsManagerTest, ComputeMetadata) {
- net::SchemefulSite nonmember(GURL("https://nonmember.test"));
- net::SchemefulSite nonmember1(GURL("https://nonmember1.test"));
- net::SchemefulSite member(GURL("https://member1.test"));
- net::SchemefulSite owner(GURL("https://example.test"));
- net::SchemefulSite wss_member(GURL("wss://member1.test"));
- net::SchemefulSite wss_nonmember(GURL("wss://nonmember.test"));
- net::FirstPartySetEntry primary_entry(owner, net::SiteType::kPrimary,
- absl::nullopt);
- net::FirstPartySetEntry associated_entry(owner, net::SiteType::kAssociated,
- 0);
- // Works as usual for sites that are in First-Party sets.
- EXPECT_EQ(ComputeMetadataAndWait(member, &member, {member}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &associated_entry, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(owner, &member, {member}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &primary_entry, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(member, &owner, {member}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &associated_entry, &primary_entry));
- EXPECT_EQ(ComputeMetadataAndWait(member, &member, {owner}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &associated_entry, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(member, &member, {member, owner}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &associated_entry, &associated_entry));
- // Works if the site is provided with WSS scheme instead of HTTPS.
- EXPECT_EQ(ComputeMetadataAndWait(wss_member, &member, {member, owner}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &associated_entry, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(nonmember, &member, {member}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- nullptr, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(member, &nonmember, {member}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- &associated_entry, nullptr));
- EXPECT_EQ(ComputeMetadataAndWait(wss_nonmember, &wss_member, {member, owner}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- nullptr, &associated_entry));
- EXPECT_EQ(ComputeMetadataAndWait(nonmember, &nonmember, {nonmember}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- nullptr, nullptr));
- EXPECT_EQ(ComputeMetadataAndWait(member, &member, {member, nonmember}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- &associated_entry, &associated_entry));
- }
- TEST_F(PopulatedFirstPartySetsManagerTest, FindOwners) {
- net::SchemefulSite kExample(GURL("https://example.test"));
- net::SchemefulSite kFoo(GURL("https://foo.test"));
- net::SchemefulSite kMember1(GURL("https://member1.test"));
- net::SchemefulSite kMember2(GURL("https://member2.test"));
- net::SchemefulSite kNonmember(GURL("https://nonmember.test"));
- EXPECT_THAT(FindOwnersAndWait({kExample}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://example.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt))));
- EXPECT_THAT(FindOwnersAndWait({kMember1}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://member1.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0))));
- EXPECT_THAT(FindOwnersAndWait({kNonmember}), IsEmpty());
- EXPECT_THAT(FindOwnersAndWait({kExample, kNonmember}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://example.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt))));
- EXPECT_THAT(FindOwnersAndWait({kMember1, kNonmember}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://member1.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0))));
- EXPECT_THAT(FindOwnersAndWait({kExample, kFoo}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://example.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt)),
- Pair(SerializesTo("https://foo.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://foo.test")),
- net::SiteType::kPrimary, absl::nullopt))));
- EXPECT_THAT(FindOwnersAndWait({kMember1, kFoo}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://member1.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0)),
- Pair(SerializesTo("https://foo.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://foo.test")),
- net::SiteType::kPrimary, absl::nullopt))));
- EXPECT_THAT(FindOwnersAndWait({kExample, kMember2}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://example.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kPrimary, absl::nullopt)),
- Pair(SerializesTo("https://member2.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://foo.test")),
- net::SiteType::kAssociated, 0))));
- EXPECT_THAT(FindOwnersAndWait({kMember1, kMember2}),
- UnorderedElementsAre(
- Pair(SerializesTo("https://member1.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://example.test")),
- net::SiteType::kAssociated, 0)),
- Pair(SerializesTo("https://member2.test"),
- net::FirstPartySetEntry(
- net::SchemefulSite(GURL("https://foo.test")),
- net::SiteType::kAssociated, 0))));
- }
- class OverrideSetsFirstPartySetsManagerTest : public FirstPartySetsEnabledTest {
- public:
- OverrideSetsFirstPartySetsManagerTest() {
- net::SchemefulSite foo(GURL("https://foo.test"));
- net::SchemefulSite example_test(GURL("https://example.test"));
- net::SchemefulSite example_cctld(GURL("https://example.cctld"));
- SetCompleteSets(
- {
- {net::SchemefulSite(GURL("https://member1.test")),
- net::FirstPartySetEntry(example_test, net::SiteType::kAssociated,
- 0)},
- {net::SchemefulSite(GURL("https://member2.test")),
- net::FirstPartySetEntry(example_test, net::SiteType::kAssociated,
- 0)},
- // Below are the owner self mappings.
- {example_test,
- net::FirstPartySetEntry(example_test, net::SiteType::kPrimary,
- absl::nullopt)},
- },
- {{example_cctld, example_test}});
- SetFirstPartySetsContextConfig(
- true,
- {
- // New entry:
- {foo,
- {net::FirstPartySetEntry(foo, net::SiteType::kPrimary,
- absl::nullopt)}},
- // Removed entry:
- {net::SchemefulSite(GURL("https://member1.test")), absl::nullopt},
- // Remapped entry:
- {net::SchemefulSite(GURL("https://member2.test")),
- {net::FirstPartySetEntry(foo, net::SiteType::kAssociated, 0)}},
- // Removed alias:
- {example_cctld, absl::nullopt},
- });
- }
- };
- TEST_F(OverrideSetsFirstPartySetsManagerTest, FindOwners) {
- net::SchemefulSite foo(GURL("https://foo.test"));
- net::SchemefulSite example_test(GURL("https://example.test"));
- net::SchemefulSite example_cctld(GURL("https://example.cctld"));
- net::SchemefulSite member2(GURL("https://member2.test"));
- EXPECT_THAT(FindOwnersAndWait({
- net::SchemefulSite(GURL("https://member1.test")),
- member2,
- foo,
- // No entry for example_cctld since it's been deleted in the
- // override, even though it's an alias and its canonical site
- // still has a valid entry.
- example_cctld,
- example_test,
- }),
- UnorderedElementsAre(
- Pair(foo, net::FirstPartySetEntry(
- foo, net::SiteType::kPrimary, absl::nullopt)),
- Pair(member2, net::FirstPartySetEntry(
- foo, net::SiteType::kAssociated, 0)),
- Pair(example_test, net::FirstPartySetEntry(
- example_test, net::SiteType::kPrimary,
- absl::nullopt))));
- }
- TEST_F(OverrideSetsFirstPartySetsManagerTest, ComputeMetadata) {
- net::SchemefulSite example(GURL("https://example.test"));
- net::SchemefulSite foo(GURL("https://foo.test"));
- net::SchemefulSite member1(GURL("https://member1.test"));
- net::SchemefulSite member2(GURL("https://member2.test"));
- net::FirstPartySetEntry example_primary_entry(
- example, net::SiteType::kPrimary, absl::nullopt);
- net::FirstPartySetEntry foo_primary_entry(foo, net::SiteType::kPrimary,
- absl::nullopt);
- net::FirstPartySetEntry foo_associated_entry(foo, net::SiteType::kAssociated,
- 0);
- // member1 has been removed from its set.
- EXPECT_EQ(ComputeMetadataAndWait(member1, &example, {}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kCrossParty),
- nullptr, &example_primary_entry));
- // member2 and foo are sites in a new set.
- EXPECT_EQ(
- ComputeMetadataAndWait(member2, &foo, {}),
- net::FirstPartySetMetadata(net::SamePartyContext(Type::kSameParty),
- &foo_associated_entry, &foo_primary_entry));
- }
- } // namespace network
|