tor-browser

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

fetch-wildcard.sub.window.js (2116B)


      1 // META: script=/common/get-host-info.sub.js
      2 //
      3 // The following tests assume the policy `Connection-Allowlist: (response-origin "*://*.hosts[alt]:*")` has been set.
      4 
      5 const port = get_host_info().HTTP_PORT_ELIDED;
      6 const SUCCESS = true;
      7 const FAILURE = false;
      8 
      9 function fetch_test(origin, expectation) {
     10  if (expectation === FAILURE) {
     11    return promise_test(async t => {
     12      const fetcher = fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" });
     13      return promise_rejects_js(t, TypeError, fetcher);
     14    }, `Fetch to ${origin} fails.`);
     15  }
     16 
     17  promise_test(async t => {
     18    const r = await fetch(`${origin}/common/blank-with-cors.html`, { mode: "cors", credential: "omit" });
     19    assert_equals(r.status, 200);
     20  }, `Fetch to ${origin} succeeds.`);
     21 }
     22 
     23 const test_cases = [
     24  // We're loading this page from `http://hosts[][]`, so that origin should
     25  // succeed, while its subdomains should fail.
     26  { origin: "http://{{hosts[][]}}" + port, expectation: SUCCESS },
     27  { origin: "http://{{hosts[][www]}}" + port, expectation: FAILURE },
     28  { origin: "http://{{hosts[][www1]}}" + port, expectation: FAILURE },
     29  { origin: "http://{{hosts[][www2]}}" + port, expectation: FAILURE },
     30  { origin: "http://{{hosts[][天気の良い日]}}" + port, expectation: FAILURE },
     31  { origin: "http://{{hosts[][élève]}}" + port, expectation: FAILURE },
     32 
     33  // The pattern we've specified in the header ("*://*.hosts[alt]:*/") will
     34  // match any subdomain of `hosts[alt]` (though not, as it turns out,
     35  // `hosts[alt]` itself.
     36  { origin: "http://{{hosts[alt][]}}" + port, expectation: FAILURE },
     37  { origin: "http://{{hosts[alt][www]}}" + port, expectation: SUCCESS },
     38  { origin: "http://{{hosts[alt][www1]}}" + port, expectation: SUCCESS },
     39  { origin: "http://{{hosts[alt][www2]}}" + port, expectation: SUCCESS },
     40  { origin: "http://{{hosts[alt][天気の良い日]}}" + port, expectation: SUCCESS },
     41  { origin: "http://{{hosts[alt][élève]}}" + port, expectation: SUCCESS },
     42 ];
     43 
     44 for (let i = 0; i < test_cases.length; i++) {
     45  fetch_test(test_cases[i].origin, test_cases[i].expectation);
     46 }