tor-browser

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

multiple-registrations.https.html (2781B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="helper.js" type="module"></script>
      6 
      7 <script type="module">
      8  import { expireCookie, waitForCookie, addCookieAndSessionCleanup, configureServer, setupShardedServerState, postJson, documentHasCookie } from "./helper.js";
      9 
     10  async function runMultipleRegistrationsTest(t, useSingleHeader) {
     11    await setupShardedServerState();
     12    const expectedCookieAndValue1 = "auth_cookie=abcdef0123";
     13    const expectedCookieAndAttributes1 = `${expectedCookieAndValue1};Domain=${location.hostname};Path=/device-bound-session-credentials`;
     14    const expectedCookieAndValue2 = "other_cookie=ghijkl4567";
     15    const expectedCookieAndAttributes2 = `${expectedCookieAndValue2};Domain=${location.hostname};Path=/device-bound-session-credentials`;
     16    addCookieAndSessionCleanup(t);
     17 
     18    // Configure server to configure cookies for next two created sessions.
     19    await configureServer({
     20      cookieDetailsForNextRegisteredSessions: [[{ nameAndValue: expectedCookieAndValue1 }], [{ nameAndValue: expectedCookieAndValue2 }]]
     21    });
     22 
     23    // Prompt starting one session, and wait until registration completes.
     24    const loginResponse = await postJson('login.py', { numSessions: 2, useSingleHeader });
     25    assert_equals(loginResponse.status, 200);
     26    await waitForCookie(expectedCookieAndValue1, /*expectCookie=*/true);
     27    await waitForCookie(expectedCookieAndValue2, /*expectCookie=*/true);
     28 
     29    async function triggerRefreshAndCheckBothCookies() {
     30      const authResponse = await fetch('verify_authenticated.py');
     31      assert_equals(authResponse.status, 200);
     32      assert_true(documentHasCookie(expectedCookieAndValue1))
     33      assert_true(documentHasCookie(expectedCookieAndValue2))
     34    }
     35    // Trigger a refresh for the first session, and confirm we have both cookies.
     36    expireCookie(expectedCookieAndAttributes1);
     37    await triggerRefreshAndCheckBothCookies();
     38    // Trigger a refresh for the second session, and confirm we have both cookies.
     39    expireCookie(expectedCookieAndAttributes2);
     40    await triggerRefreshAndCheckBothCookies();
     41    // Trigger a refresh for both sessions, and confirm we have both cookies.
     42    expireCookie(expectedCookieAndAttributes1);
     43    expireCookie(expectedCookieAndAttributes2);
     44    await triggerRefreshAndCheckBothCookies();
     45  }
     46 
     47  promise_test(async t => {
     48    await runMultipleRegistrationsTest(t, /*useSingleHeader=*/true);
     49  }, "Multiple registrations can be triggered in one response (single header)");
     50 
     51  promise_test(async t => {
     52    await runMultipleRegistrationsTest(t, /*useSingleHeader=*/false);
     53  }, "Multiple registrations can be triggered in one response (multiple headers)");
     54 </script>