tor-browser

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

credentials.https.html (3993B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Credentials for service worker scripts</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/get-host-info.sub.js"></script>
      7 <script src="/common/utils.js"></script>
      8 <script src="/cookies/resources/cookie-helper.sub.js"></script>
      9 <script src="resources/test-helpers.sub.js"></script>
     10 <body>
     11 <script>
     12 // Check if the service worker's script has appropriate credentials for a new
     13 // worker and byte-for-byte checking.
     14 
     15 const SCOPE = 'resources/in-scope';
     16 const COOKIE_NAME = `service-worker-credentials-${Math.random()}`;
     17 
     18 promise_test(async t => {
     19  // Set-Cookies for path=/.
     20  await fetch(
     21      `/cookies/resources/set-cookie.py?name=${COOKIE_NAME}&path=%2F`);
     22 }, 'Set cookies as initialization');
     23 
     24 async function get_cookies(worker) {
     25  worker.postMessage('get cookie');
     26  const message = await new Promise(resolve =>
     27      navigator.serviceWorker.addEventListener('message', resolve));
     28  return message.data;
     29 }
     30 
     31 promise_test(async t => {
     32  const key = token();
     33  const registration = await service_worker_unregister_and_register(
     34      t, `resources/echo-cookie-worker.py?key=${key}`, SCOPE);
     35  t.add_cleanup(() => registration.unregister());
     36  const worker = registration.installing;
     37 
     38  const cookies = await get_cookies(worker);
     39  assert_equals(cookies[COOKIE_NAME], '1', 'new worker has credentials');
     40 
     41  await registration.update();
     42  const updated_worker = registration.installing;
     43  const updated_cookies = await get_cookies(updated_worker);
     44  assert_equals(updated_cookies[COOKIE_NAME], '1',
     45                'updated worker has credentials');
     46 }, 'Main script should have credentials');
     47 
     48 promise_test(async t => {
     49  const key = token();
     50  const registration = await service_worker_unregister_and_register(
     51      t, `resources/import-echo-cookie-worker.js?key=${key}`, SCOPE);
     52  t.add_cleanup(() => registration.unregister());
     53  const worker = registration.installing;
     54 
     55  const cookies = await get_cookies(worker);
     56  assert_equals(cookies[COOKIE_NAME], '1', 'new worker has credentials');
     57 
     58  await registration.update();
     59  const updated_worker = registration.installing;
     60  const updated_cookies = await get_cookies(updated_worker);
     61  assert_equals(updated_cookies[COOKIE_NAME], '1',
     62                'updated worker has credentials');
     63 }, 'Imported script should have credentials');
     64 
     65 promise_test(async t => {
     66  const key = token();
     67  const registration = await service_worker_unregister_and_register(
     68      t, `resources/import-echo-cookie-worker-module.py?key=${key}`, SCOPE, {type: 'module'});
     69  t.add_cleanup(() => registration.unregister());
     70  const worker = registration.installing;
     71 
     72  const cookies = await get_cookies(worker);
     73  assert_equals(cookies[COOKIE_NAME], undefined, 'new module worker should not have credentials');
     74 
     75  await registration.update();
     76  const updated_worker = registration.installing;
     77  const updated_cookies = await get_cookies(updated_worker);
     78  assert_equals(updated_cookies[COOKIE_NAME], undefined,
     79                'updated worker should not have credentials');
     80 }, 'Module with an imported statement should not have credentials');
     81 
     82 promise_test(async t => {
     83  const key = token();
     84  const registration = await service_worker_unregister_and_register(
     85 t, `resources/echo-cookie-worker.py?key=${key}`, SCOPE, {type: 'module'});
     86  t.add_cleanup(() => registration.unregister());
     87  const worker = registration.installing;
     88 
     89  const cookies = await get_cookies(worker);
     90  assert_equals(cookies[COOKIE_NAME], undefined, 'new module worker should not have credentials');
     91 
     92  await registration.update();
     93  const updated_worker = registration.installing;
     94  const updated_cookies = await get_cookies(updated_worker);
     95  assert_equals(updated_cookies[COOKIE_NAME], undefined,
     96                'updated worker should not have credentials');
     97 }, 'Script with service worker served as modules should not have credentials');
     98 
     99 </script>
    100 </body>