tor-browser

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

max-payload.https.window.js (1746B)


      1 // META: script=/common/get-host-info.sub.js
      2 // META: script=/common/utils.js
      3 // META: script=/fetch/fetch-later/resources/fetch-later-helper.js
      4 // META: script=/fetch/fetch-later/quota/resources/helper.js
      5 'use strict';
      6 
      7 const {HTTPS_ORIGIN} = get_host_info();
      8 
      9 // Skips FormData & URLSearchParams, as browser adds extra bytes to them
     10 // in addition to the user-provided content. It is difficult to test a
     11 // request right at the quota limit.
     12 // Skips File & Blob as it's difficult to estimate what additional data are
     13 // added into them.
     14 const dataType = BeaconDataType.String;
     15 
     16 // Request headers are counted into total request size.
     17 const headers = new Headers({'Content-Type': 'text/plain;charset=UTF-8'});
     18 
     19 // Test making a POST request with max possible payload.
     20 promise_test(async _ => {
     21  const uuid = token();
     22  const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN});
     23  await expectFetchLater(
     24      {
     25        activateAfter: 0,
     26        method: 'POST',
     27        bodySize: getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers),
     28      },
     29      {
     30        targetUrl: requestUrl,
     31        uuid: uuid,
     32      });
     33 }, `fetchLater() accepts max payload in a POST request body of ${dataType}.`);
     34 
     35 // Test making a POST request with max+1 possible payload.
     36 test(_ => {
     37  const uuid = token();
     38  const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN});
     39 
     40  assert_throws_quotaexceedederror(() => {
     41    fetchLater(requestUrl, {
     42          activateAfter: 0,
     43          method: 'POST',
     44          body: generatePayload(
     45              getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
     46              dataType),
     47        });
     48  }, null, null);
     49 }, `fetchLater() rejects max+1 payload in a POST request body of ${dataType}.`);