File: credentialless-service-worker.https.tentative.window.js

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (113 lines) | stat: -rw-r--r-- 4,105 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// META: timeout=long
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/common/dispatcher/dispatcher.js
// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
// META: script=./resources/common.js

const same_origin = get_host_info().HTTPS_ORIGIN;
const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;
const cookie_key = "credentialless_service_worker";
const cookie_same_origin = "same_origin";
const cookie_cross_origin = "cross_origin";

promise_test(async t => {
  await Promise.all([
    setCookie(same_origin, cookie_key, cookie_same_origin +
      cookie_same_site_none),
    setCookie(cross_origin, cookie_key, cookie_cross_origin +
      cookie_same_site_none),
  ]);

  // One iframe with DIP:none. (control)
  const w_control_token = token();
  const w_control_url = same_origin + executor_path +
    dip_none + `&uuid=${w_control_token}`
  const w_control = document.createElement("iframe");
  w_control.src = w_control_url;
  document.body.appendChild(w_control);

  // One iframe with DIP:credentialless. (experiment)
  const w_credentialless_token = token();
  const w_credentialless_url = same_origin + executor_path +
    dip_credentialless + `&uuid=${w_credentialless_token}`;
  const w_credentialless = document.createElement("iframe");
  w_credentialless.src = w_credentialless_url;
  document.body.appendChild(w_credentialless);

  const serviceWorkerTest = function(
    description, origin, dip_for_worker,
    expected_cookies_control,
    expected_cookies_credentialless)
  {
    promise_test(async test => {
      // Create workers for both window.
      const control_worker_token = token();
      const credentialless_worker_token = token();

      const w_control_worker_src = same_origin + executor_worker_path +
        dip_for_worker + `&uuid=${control_worker_token}`;
      const w_control_worker_reg =
        await service_worker_unregister_and_register(
          test, w_control_worker_src, w_control_url);

      const w_credentialless_worker_src = same_origin + executor_worker_path +
        dip_for_worker + `&uuid=${credentialless_worker_token}`;
      const w_credentialless_worker_reg =
        await service_worker_unregister_and_register(
          test, w_credentialless_worker_src, w_credentialless_url);

      // Fetch resources from the workers.
      const control_request_token = token();
      const credentialless_request_token = token();
      const control_request_url = showRequestHeaders(origin, control_request_token);
      const credentialless_request_url = showRequestHeaders(origin, credentialless_request_token);
      send(control_worker_token, `
        fetch("${control_request_url}", {
          mode: 'no-cors',
          credentials: 'include'
        })
      `);
      send(credentialless_worker_token, `
        fetch("${credentialless_request_url}", {
          mode: 'no-cors',
          credentials: 'include'
        })
      `);

      // Retrieve the resource request headers.
      const headers_control = JSON.parse(await receive(control_request_token));
      const headers_credentialless = JSON.parse(await receive(credentialless_request_token));

      assert_equals(parseCookies(headers_control)[cookie_key],
        expected_cookies_control,
        "dip:none => ");
      assert_equals(parseCookies(headers_credentialless)[cookie_key],
        expected_cookies_credentialless,
        "dip:credentialless => ");

      w_control_worker_reg.unregister();
      w_credentialless_worker_reg.unregister();
    }, `fetch ${description}`)
  };

  serviceWorkerTest("same-origin",
    same_origin, dip_none,
    cookie_same_origin,
    cookie_same_origin);

  serviceWorkerTest("same-origin + credentialless worker",
    same_origin, dip_credentialless,
    cookie_same_origin,
    cookie_same_origin);

  serviceWorkerTest("cross-origin",
    cross_origin, dip_none,
    cookie_cross_origin,
    cookie_cross_origin);

  serviceWorkerTest("cross-origin + credentialless worker",
    cross_origin, dip_credentialless,
    undefined,
    undefined);
})