tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

partitioned-cookies.tentative.https.html (3798B)


      1 <!DOCTYPE html>
      2 <head>
      3 <meta charset="utf-8"/>
      4 <meta name="timeout" content="long">
      5 <title>Service Worker: Partitioned Cookies</title>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="resources/test-helpers.sub.js"></script>
      9 <script src="/common/get-host-info.sub.js"></script>
     10 <script src="resources/partitioned-cookies-test-helpers.js"></script>
     11 </head>
     12 
     13 <!--
     14  This test exercises partitioned service workers' interaction with partitioned
     15  cookies. Partitioned service workers should only be able to interact with
     16  partitioned cookies whose partition key matches the worker's partition.
     17 -->
     18 
     19 <body>
     20 <script>
     21 
     22 promise_test(async t => {
     23  const script = './resources/partitioned-cookies-sw.js'
     24  const scope = './resources/partitioned-cookies-'
     25  const absolute_scope = new URL(scope, window.location).href;
     26 
     27  // Set a Partitioned cookie.
     28  document.cookie =
     29      '__Host-partitioned=123; Secure; Path=/; SameSite=None; Partitioned;';
     30  assert_true(document.cookie.includes('__Host-partitioned=123'));
     31 
     32  // Set an unpartitioned cookie.
     33  document.cookie = 'unpartitioned=456; Secure; Path=/; SameSite=None;';
     34  assert_true(document.cookie.includes('unpartitioned=456'));
     35 
     36  const reg = await service_worker_unregister_and_register(t, script, scope);
     37  await wait_for_state(t, reg.installing, 'activated');
     38  t.add_cleanup(() => reg.unregister());
     39 
     40  const next_message = worker_message_generator();
     41 
     42  const retrieved_registrations =
     43        await navigator.serviceWorker.getRegistrations();
     44  // It's possible that other tests have left behind other service workers.
     45  // This steps filters those other SWs out.
     46  const filtered_registrations =
     47    retrieved_registrations.filter(reg => reg.scope == absolute_scope);
     48 
     49  // First test that the worker script started correctly and message passing
     50  // is enabed.
     51  filtered_registrations[0].active.postMessage({type: 'test_message'});
     52  const msg1 = await next_message();
     53  assert_true(msg1.ok, 'Message passing');
     54 
     55  // Test that the partitioned cookie is available to this worker via HTTP.
     56  filtered_registrations[0].active.postMessage({type: 'echo_cookies_http'});
     57  const msg2 = await next_message();
     58  assert_true(msg2.ok, 'Get cookies');
     59  assert_true(
     60      msg2.cookies.includes('__Host-partitioned'),
     61      'Can access partitioned cookie via HTTP');
     62  assert_true(
     63      msg2.cookies.includes('unpartitioned'),
     64      'Can access unpartitioned cookie via HTTP');
     65 
     66  // Test that the partitioned cookie is available to this worker via
     67  // CookieStore API.
     68  filtered_registrations[0].active.postMessage({type: 'echo_cookies_js'});
     69  const msg3 = await next_message();
     70  assert_true(msg3.ok, 'Get cookies');
     71  assert_true(
     72      msg3.cookies.includes('__Host-partitioned'),
     73      'Can access partitioned cookie via JS');
     74  assert_true(
     75      msg3.cookies.includes('unpartitioned'),
     76      'Can access unpartitioned cookie via JS');
     77 
     78  // Test that the partitioned cookie is not available to this worker in HTTP
     79  // requests from importScripts.
     80  filtered_registrations[0].active.postMessage({type: 'echo_cookies_import'});
     81  const msg4 = await next_message();
     82  assert_true(msg4.ok, 'Get cookies');
     83  assert_true(
     84      msg4.cookies.includes('__Host-partitioned'),
     85      'Can access partitioned cookie via importScripts');
     86  assert_true(
     87      msg4.cookies.includes('unpartitioned'),
     88      'Can access unpartitioned cookie via importScripts');
     89 
     90  const popup = window.open(
     91      new URL(
     92          `./resources/partitioned-cookies-3p-window.html?origin=${
     93              encodeURIComponent(self.location.origin)}`,
     94          get_host_info().HTTPS_NOTSAMESITE_ORIGIN + self.location.pathname));
     95  await fetch_tests_from_window(popup);
     96 });
     97 
     98 </script>
     99 </body>
    100 </html>