Skip to content

Commit

Permalink
Add unpartitioned cookie to partitioned service worker/cookies WPT
Browse files Browse the repository at this point in the history
This tests that partitioned workers in unnonced partitions can still
access unpartitioned SameSite=None cookies. It also tests that workers
in nonced partitions cannot.

Bug: 1427879
Change-Id: I9863c90706e007f1e7249b5f0aeada13830310f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4540460
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/main@{#1144907}
  • Loading branch information
DCtheTall authored and chromium-wpt-export-bot committed May 16, 2023
1 parent 25eb850 commit 182f582
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
document.cookie = '__Host-partitioned=123; Secure; Path=/; SameSite=None; Partitioned;';
assert_true(document.cookie.includes('__Host-partitioned=123'));

// Set an unpartitioned cookie.
document.cookie = 'unpartitioned=456; Secure; Path=/; SameSite=None;';
assert_true(document.cookie.includes('unpartitioned=456'));

// Test that the partitioned cookie is available to this worker via HTTP.
wait_promise = new Promise(resolve => {
resolve_wait_promise = resolve;
Expand All @@ -71,6 +75,7 @@
await wait_promise;
assert_true(got.ok, 'Get cookies');
assert_true(got.cookies.includes('__Host-partitioned'), 'Can access partitioned cookie via HTTP');
assert_true(got.cookies.includes('unpartitioned'), 'Can access unpartitioned cookie via HTTP');

// Test that the partitioned cookie is available to this worker via CookieStore API.
wait_promise = new Promise(resolve => {
Expand All @@ -95,4 +100,4 @@

</script>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
document.cookie = '__Host-partitioned=123; Secure; Path=/; SameSite=None; Partitioned;';
assert_true(document.cookie.includes('__Host-partitioned=123'));

// Make sure DOM cannot access the unpartitioned cookie.
assert_false(document.cookie.includes('unpartitioned=456'));

const reg = await service_worker_unregister_and_register(t, script, scope);
await wait_for_state(t, reg.installing, 'activated');

Expand Down Expand Up @@ -61,9 +64,32 @@
filtered_registrations[0].active.postMessage({type: 'echo_cookies_js'});
await wait_promise;
assert_true(got.ok, 'Get cookies');
assert_true(got.cookies.includes('__Host-partitioned'), 'Can access partitioned cookie');;
assert_true(
got.cookies.includes('__Host-partitioned'),
'Credentialless frame worker can access partitioned cookie via JS');
assert_false(
got.cookies.includes('unpartitioned'),
'Credentialless frame worker cannot access unpartitioned cookie via JS');

// Test that the partitioned cookie is available to this worker via HTTP.
wait_promise = new Promise(resolve => {
resolve_wait_promise = resolve;
});
on_message = ev => {
got = ev.data;
resolve_wait_promise();
};
filtered_registrations[0].active.postMessage({ type: 'echo_cookies_http' });
await wait_promise;
assert_true(got.ok, 'Get cookies');
assert_true(
got.cookies.includes('__Host-partitioned'),
'Credentialless frame worker can access partitioned cookie via HTTP');
assert_false(
got.cookies.includes('unpartitioned'),
'Credentialless frame worker cannot access unpartitioned cookie via HTTP');
});

</script>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const absolute_scope = new URL(scope, window.location).href;

assert_false(document.cookie.includes('__Host-partitioned=123'), 'DOM cannot access partitioned cookie');
assert_true(document.cookie.includes('unpartitioned=456'), 'DOM can access unpartitioned cookie');

const reg = await service_worker_unregister_and_register(t, script, scope);
await wait_for_state(t, reg.installing, 'activated');
Expand Down Expand Up @@ -59,7 +60,10 @@
assert_true(got.ok, 'Get cookies');
assert_false(
got.cookies.includes('__Host-partitioned'),
'Worker cannot access partitioned cookie');
'Worker cannot access partitioned cookie via HTTP');
assert_true(
got.cookies.includes('unpartitioned'),
'Worker can access unpartitioned cookie via HTTP');

// Test that the partitioned cookie is not available to this worker via CookieStore API.
wait_promise = new Promise(resolve => {
Expand All @@ -74,9 +78,12 @@
assert_true(got.ok, 'Get cookies');
assert_false(
got.cookies.includes('__Host-partitioned'),
'Worker cannot access partitioned cookie');
'Worker cannot access partitioned cookie via JS');
assert_true(
got.cookies.includes('unpartitioned'),
'Worker can access unpartitioned cookie via JS');
});

</script>
</body>
</html>
</html>

0 comments on commit 182f582

Please sign in to comment.