tor-browser

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

test_dual_header.html (2016B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 1036399 - Multiple CSP policies should be combined towards an intersection</title>
      5  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10  <p id="display"></p>
     11  <div id="content" style="visibility: hidden">
     12    <iframe style="width:100%;" id="testframe"></iframe>
     13  </div>
     14 
     15 <script class="testbody" type="text/javascript">
     16 
     17 /* Description of the test:
     18 * We have two tests where each tests serves a page using two CSP policies:
     19 *   a) * default-src 'self'
     20 *      * default-src 'self' 'unsafe-inline'
     21 *
     22 *   b) * default-src 'self' 'unsafe-inline'
     23 *      * default-src 'self' 'unsafe-inline'
     24 *
     25 * We make sure the inline script is *blocked* for test (a) but *allowed* for test (b).
     26 * Multiple CSPs should be combined towards an intersection and it shouldn't be possible
     27 * to open up (loosen) a CSP policy.
     28 */
     29 
     30 const TESTS = [
     31  { query: "tight", result: "blocked" },
     32  { query: "loose", result: "allowed" }
     33 ];
     34 var testCounter = -1;
     35 
     36 function ckeckResult() {
     37  try {
     38    document.getElementById("testframe").removeEventListener('load', ckeckResult);
     39    var testframe = document.getElementById("testframe");
     40    var divcontent = testframe.contentWindow.document.getElementById('testdiv').innerHTML;
     41    is(divcontent, curTest.result, "should be 'blocked'!");
     42  }
     43  catch (e) {
     44    ok(false, "error: could not access content in div container!");
     45  }
     46  loadNextTest();
     47 }
     48 
     49 function loadNextTest() {
     50  testCounter++;
     51  if (testCounter >= TESTS.length) {
     52    SimpleTest.finish();
     53    return;
     54  }
     55  curTest = TESTS[testCounter];
     56  var src = "file_dual_header_testserver.sjs?" + curTest.query;
     57  document.getElementById("testframe").addEventListener("load", ckeckResult);
     58  document.getElementById("testframe").src = src;
     59 }
     60 
     61 SimpleTest.waitForExplicitFinish();
     62 loadNextTest();
     63 
     64 </script>
     65 </body>
     66 </html>