tor-browser

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

network-partition-key.js (1678B)


      1 // Runs multiple fetches that validate connections see only a single partition_id.
      2 // Requests are run in parallel so that they use multiple connections to maximize the
      3 // chance of exercising all matching connections in the connection pool. Only returns
      4 // once all requests have completed to make cleaning up server state non-racy.
      5 function check_partition_ids(location) {
      6  const NUM_FETCHES = 20;
      7 
      8  var base_url = 'SUBRESOURCE_PREFIX:&dispatch=check_partition';
      9 
     10  // Not a perfect parse of the query string, but good enough for this test.
     11  var include_credentials = base_url.search('include_credentials=true') != -1;
     12  var exclude_credentials = base_url.search('include_credentials=false') != -1;
     13  if (include_credentials != !exclude_credentials)
     14    throw new Exception('Credentials mode not specified');
     15 
     16 
     17  // Run NUM_FETCHES in parallel.
     18  var fetches = [];
     19  for (i = 0; i < NUM_FETCHES; ++i) {
     20    var fetch_params = {
     21      credentials: 'omit',
     22      mode: 'cors',
     23      headers: {
     24        'Header-To-Force-CORS': 'cors'
     25      },
     26    };
     27 
     28    // Use a unique URL for each request, in case the caching layer serializes multiple
     29    // requests for the same URL.
     30    var url = `${base_url}&${token()}`;
     31 
     32    fetches.push(fetch(url, fetch_params).then(
     33        function (response) {
     34          return response.text().then(function(text) {
     35            assert_equals(text, 'ok', `Socket unexpectedly reused`);
     36          });
     37        }));
     38  }
     39 
     40  // Wait for all promises to complete.
     41  return Promise.allSettled(fetches).then(function (results) {
     42    results.forEach(function (result) {
     43      if (result.status != 'fulfilled')
     44        throw result.reason;
     45    });
     46  });
     47 }