content/base/test/csp/file_CSP_evalscript_main_allowed_getCRMFRequest.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/csp/file_CSP_evalscript_main_allowed_getCRMFRequest.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +// some javascript for the CSP eval() tests
     1.5 +// all of these evals should succeed, as the document loading this script
     1.6 +// has script-src 'self' 'unsafe-eval'
     1.7 +
     1.8 +function logResult(str, passed) {
     1.9 +  var elt = document.createElement('div');
    1.10 +  var color = passed ? "#cfc;" : "#fcc";
    1.11 +  elt.setAttribute('style', 'background-color:' + color + '; width:100%; border:1px solid black; padding:3px; margin:4px;');
    1.12 +  elt.innerHTML = str;
    1.13 +  document.body.appendChild(elt);
    1.14 +}
    1.15 +
    1.16 +// callback for when stuff is allowed by CSP
    1.17 +var onevalexecuted = (function(window) {
    1.18 +    return function(shouldrun, what, data) {
    1.19 +      window.parent.scriptRan(shouldrun, what, data);
    1.20 +      logResult((shouldrun ? "PASS: " : "FAIL: ") + what + " : " + data, shouldrun);
    1.21 +    };})(window);
    1.22 +
    1.23 +// callback for when stuff is blocked
    1.24 +var onevalblocked = (function(window) {
    1.25 +    return function(shouldrun, what, data) {
    1.26 +      window.parent.scriptBlocked(shouldrun, what, data);
    1.27 +      logResult((shouldrun ? "FAIL: " : "PASS: ") + what + " : " + data, !shouldrun);
    1.28 +    };})(window);
    1.29 +
    1.30 +
    1.31 +// Defer until document is loaded so that we can write the pretty result boxes
    1.32 +// out.
    1.33 +addEventListener('load', function() {
    1.34 +  // test that allows crypto.generateCRMFRequest eval to run
    1.35 +  try {
    1.36 +      var script =
    1.37 +        'console.log("dynamic script passed to crypto.generateCRMFRequest should execute")';
    1.38 +      crypto.generateCRMFRequest('CN=0', 0, 0, null, script, 384, null, 'rsa-dual-use');
    1.39 +      onevalexecuted(true, "eval(script) inside crypto.generateCRMFRequest",
    1.40 +                     "eval executed during crypto.generateCRMFRequest");
    1.41 +  } catch (e) {
    1.42 +    onevalblocked(true, "eval(script) inside crypto.generateCRMFRequest",
    1.43 +                  "eval was blocked during crypto.generateCRMFRequest");
    1.44 +  }
    1.45 +}, false);

mercurial