Commit 8b44d4f8 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

Async Cookies: Test that HttpOnly cookie changes are not dispatched to SW.

Bug: 729800
Change-Id: I194f3f4b86794236cc90fbc8614b1da680c8aaa6
Reviewed-on: https://chromium-review.googlesource.com/1107315Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568707}
parent 0e1b15ef
......@@ -288,19 +288,8 @@ class CookieStoreManagerTest
return registration_id;
}
// Simplified helper for SetCanonicalCookie.
//
// Creates a CanonicalCookie that is not secure, not http-only,
// and not restricted to first parties. Returns false if creation fails.
bool SetSessionCookie(const char* name,
const char* value,
const char* domain,
const char* path) {
net::CanonicalCookie cookie(
name, value, domain, path, base::Time(), base::Time(), base::Time(),
/* secure = */ false,
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT);
// Synchronous helper for CookieManager::SetCanonicalCookie.
bool SetCanonicalCookie(const net::CanonicalCookie& cookie) {
base::RunLoop run_loop;
bool success = false;
cookie_manager_->SetCanonicalCookie(
......@@ -315,6 +304,21 @@ class CookieStoreManagerTest
return success;
}
// Simplified helper for SetCanonicalCookie.
//
// Creates a CanonicalCookie that is not secure, not http-only,
// and not restricted to first parties. Returns false if creation fails.
bool SetSessionCookie(const char* name,
const char* value,
const char* domain,
const char* path) {
return SetCanonicalCookie(net::CanonicalCookie(
name, value, domain, path, base::Time(), base::Time(), base::Time(),
/* secure = */ false,
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT));
}
bool reset_context_during_test() const { return GetParam(); }
static constexpr const int64_t kInvalidRegistrationId = -1;
......@@ -824,6 +828,58 @@ TEST_P(CookieStoreManagerTest, CookieChangeUrl) {
worker_test_helper_->changes()[0].second);
}
TEST_P(CookieStoreManagerTest, HttpOnlyCookieChange) {
std::vector<CookieStoreSync::Subscriptions> batches;
batches.emplace_back();
CookieStoreSync::Subscriptions& subscriptions = batches.back();
subscriptions.emplace_back(blink::mojom::CookieChangeSubscription::New());
subscriptions.back()->name = "";
subscriptions.back()->match_type =
::network::mojom::CookieMatchType::STARTS_WITH;
subscriptions.back()->url = GURL(kExampleScope);
worker_test_helper_->SetOnInstallSubscriptions(std::move(batches),
example_service_ptr_.get());
int64_t registration_id =
RegisterServiceWorker(kExampleScope, kExampleWorkerScript);
ASSERT_NE(registration_id, kInvalidRegistrationId);
base::Optional<CookieStoreSync::Subscriptions> all_subscriptions_opt =
example_service_->GetSubscriptions(registration_id);
ASSERT_TRUE(all_subscriptions_opt.has_value());
ASSERT_EQ(1u, all_subscriptions_opt.value().size());
if (reset_context_during_test())
ResetServiceWorkerContext();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie(
"cookie-name-1", "cookie-value-1", "example.com", "/", base::Time(),
base::Time(), base::Time(),
/* secure = */ false,
/* httponly = */ true, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT)));
thread_bundle_.RunUntilIdle();
EXPECT_EQ(0u, worker_test_helper_->changes().size());
worker_test_helper_->changes().clear();
ASSERT_TRUE(SetCanonicalCookie(net::CanonicalCookie(
"cookie-name-2", "cookie-value-2", "example.com", "/", base::Time(),
base::Time(), base::Time(),
/* secure = */ false,
/* httponly = */ false, net::CookieSameSite::NO_RESTRICTION,
net::COOKIE_PRIORITY_DEFAULT)));
thread_bundle_.RunUntilIdle();
ASSERT_EQ(1u, worker_test_helper_->changes().size());
EXPECT_EQ("cookie-name-2", worker_test_helper_->changes()[0].first.Name());
EXPECT_EQ("cookie-value-2", worker_test_helper_->changes()[0].first.Value());
EXPECT_EQ("example.com", worker_test_helper_->changes()[0].first.Domain());
EXPECT_EQ("/", worker_test_helper_->changes()[0].first.Path());
EXPECT_EQ(::network::mojom::CookieChangeCause::INSERTED,
worker_test_helper_->changes()[0].second);
}
TEST_P(CookieStoreManagerTest, GetSubscriptionsFromWrongOrigin) {
std::vector<CookieStoreSync::Subscriptions> batches;
batches.emplace_back();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment