Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // some javascript for the CSP eval() tests |
michael@0 | 2 | // all of these evals should succeed, as the document loading this script |
michael@0 | 3 | // has script-src 'self' 'unsafe-eval' |
michael@0 | 4 | |
michael@0 | 5 | function logResult(str, passed) { |
michael@0 | 6 | var elt = document.createElement('div'); |
michael@0 | 7 | var color = passed ? "#cfc;" : "#fcc"; |
michael@0 | 8 | elt.setAttribute('style', 'background-color:' + color + '; width:100%; border:1px solid black; padding:3px; margin:4px;'); |
michael@0 | 9 | elt.innerHTML = str; |
michael@0 | 10 | document.body.appendChild(elt); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | // callback for when stuff is allowed by CSP |
michael@0 | 14 | var onevalexecuted = (function(window) { |
michael@0 | 15 | return function(shouldrun, what, data) { |
michael@0 | 16 | window.parent.scriptRan(shouldrun, what, data); |
michael@0 | 17 | logResult((shouldrun ? "PASS: " : "FAIL: ") + what + " : " + data, shouldrun); |
michael@0 | 18 | };})(window); |
michael@0 | 19 | |
michael@0 | 20 | // callback for when stuff is blocked |
michael@0 | 21 | var onevalblocked = (function(window) { |
michael@0 | 22 | return function(shouldrun, what, data) { |
michael@0 | 23 | window.parent.scriptBlocked(shouldrun, what, data); |
michael@0 | 24 | logResult((shouldrun ? "FAIL: " : "PASS: ") + what + " : " + data, !shouldrun); |
michael@0 | 25 | };})(window); |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | // Defer until document is loaded so that we can write the pretty result boxes |
michael@0 | 29 | // out. |
michael@0 | 30 | addEventListener('load', function() { |
michael@0 | 31 | // test that allows crypto.generateCRMFRequest eval to run |
michael@0 | 32 | try { |
michael@0 | 33 | var script = |
michael@0 | 34 | 'console.log("dynamic script passed to crypto.generateCRMFRequest should execute")'; |
michael@0 | 35 | crypto.generateCRMFRequest('CN=0', 0, 0, null, script, 384, null, 'rsa-dual-use'); |
michael@0 | 36 | onevalexecuted(true, "eval(script) inside crypto.generateCRMFRequest", |
michael@0 | 37 | "eval executed during crypto.generateCRMFRequest"); |
michael@0 | 38 | } catch (e) { |
michael@0 | 39 | onevalblocked(true, "eval(script) inside crypto.generateCRMFRequest", |
michael@0 | 40 | "eval was blocked during crypto.generateCRMFRequest"); |
michael@0 | 41 | } |
michael@0 | 42 | }, false); |