tor-browser

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

file_bug888172.sjs (1546B)


      1 // SJS file for CSP mochitests
      2 
      3 const { NetUtil } = ChromeUtils.importESModule(
      4   "resource://gre/modules/NetUtil.sys.mjs"
      5 );
      6 
      7 function loadHTMLFromFile(path) {
      8   // Load the HTML to return in the response from file.
      9   // Since it's relative to the cwd of the test runner, we start there and
     10   // append to get to the actual path of the file.
     11   var testHTMLFile = Cc["@mozilla.org/file/directory_service;1"]
     12     .getService(Ci.nsIProperties)
     13     .get("CurWorkD", Ci.nsIFile);
     14   var dirs = path.split("/");
     15   for (var i = 0; i < dirs.length; i++) {
     16     testHTMLFile.append(dirs[i]);
     17   }
     18   var testHTMLFileStream = Cc[
     19     "@mozilla.org/network/file-input-stream;1"
     20   ].createInstance(Ci.nsIFileInputStream);
     21   testHTMLFileStream.init(testHTMLFile, -1, 0, 0);
     22   var testHTML = NetUtil.readInputStreamToString(
     23     testHTMLFileStream,
     24     testHTMLFileStream.available()
     25   );
     26   return testHTML;
     27 }
     28 
     29 function handleRequest(request, response) {
     30   var query = {};
     31   request.queryString.split("&").forEach(function (val) {
     32     var [name, value] = val.split("=");
     33     query[name] = unescape(value);
     34   });
     35 
     36   // avoid confusing cache behaviors
     37   response.setHeader("Cache-Control", "no-cache", false);
     38 
     39   // Deliver the CSP policy encoded in the URI
     40   if (query.csp) {
     41     response.setHeader("Content-Security-Policy", unescape(query.csp), false);
     42   }
     43 
     44   // Send HTML to test allowed/blocked behaviors
     45   response.setHeader("Content-Type", "text/html", false);
     46   response.write(
     47     loadHTMLFromFile("tests/dom/security/test/csp/file_bug888172.html")
     48   );
     49 }