tor-browser

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

test_invalid_source_expression.html (1803B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 1086612 - CSP: Let source expression be the empty set in case no valid source can be parsed</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 SimpleTest.waitForExplicitFinish();
     18 
     19 /* Description of the test:
     20 * We try to parse a policy:
     21 *   script-src bankid:/*
     22 * where the source expression (bankid:/*) is invalid. In that case the source-expression
     23 * should be the empty set ('none'), see: http://www.w3.org/TR/CSP11/#source-list-parsing
     24 * We confirm that the script is blocked by CSP.
     25 */
     26 
     27 const policy = "script-src bankid:/*";
     28 
     29 function runTest() {
     30  var src = "file_testserver.sjs";
     31  // append the file that should be served
     32  src += "?file=" + escape("tests/dom/security/test/csp/file_invalid_source_expression.html");
     33  // append the CSP that should be used to serve the file
     34  src += "&csp=" + escape(policy);
     35 
     36  document.getElementById("testframe").addEventListener("load", test);
     37  document.getElementById("testframe").src = src;
     38 }
     39 
     40 function test() {
     41  try {
     42    document.getElementById("testframe").removeEventListener('load', test);
     43    var testframe = document.getElementById("testframe");
     44    var divcontent = testframe.contentWindow.document.getElementById('testdiv').innerHTML;
     45    is(divcontent, "blocked", "should be 'blocked'!");
     46  }
     47  catch (e) {
     48    ok(false, "ERROR: could not access content!");
     49  }
     50  SimpleTest.finish();
     51 }
     52 
     53 runTest();
     54 
     55 </script>
     56 </body>
     57 </html>