content/base/test/csp/test_self_none_as_hostname_confusion.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=587377
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 587377</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=587377">Mozilla Bug 587377</a>
michael@0 14 <p id="display"></p>
michael@0 15
michael@0 16 <iframe id="cspframe"></iframe>
michael@0 17
michael@0 18 <pre id="test">
michael@0 19
michael@0 20 <script class="testbody" type="text/javascript">
michael@0 21 // Load locale string during mochitest
michael@0 22 var stringBundleService = SpecialPowers.Cc["@mozilla.org/intl/stringbundle;1"]
michael@0 23 .getService(SpecialPowers.Ci.nsIStringBundleService);
michael@0 24 var localizer = stringBundleService.createBundle("chrome://global/locale/security/csp.properties");
michael@0 25 var confusionMsg = localizer.formatStringFromName("hostNameMightBeKeyword", ["SELF", "self"], 2);
michael@0 26
michael@0 27 function cleanup() {
michael@0 28 SpecialPowers.postConsoleSentinel();
michael@0 29 SimpleTest.finish();
michael@0 30 };
michael@0 31
michael@0 32 // To prevent the test from asserting twice and calling SimpleTest.finish() twice,
michael@0 33 // startTest will be marked false as soon as the confusionMsg is detected.
michael@0 34 startTest = false;
michael@0 35 SpecialPowers.registerConsoleListener(function ConsoleMsgListener(aMsg) {
michael@0 36 if (startTest) {
michael@0 37 if (aMsg.message.indexOf(confusionMsg) > -1) {
michael@0 38 startTest = false;
michael@0 39 ok(true, "CSP header with a hostname similar to keyword should be warned");
michael@0 40 SimpleTest.executeSoon(cleanup);
michael@0 41 } else {
michael@0 42 // don't see the warning yet? wait.
michael@0 43 return;
michael@0 44 }
michael@0 45 }
michael@0 46 });
michael@0 47
michael@0 48 // set up and start testing
michael@0 49 SimpleTest.waitForExplicitFinish();
michael@0 50 SpecialPowers.pushPrefEnv(
michael@0 51 {'set': [["security.csp.speccompliant", true]]},
michael@0 52 function() {
michael@0 53 document.getElementById('cspframe').src = 'file_self_none_as_hostname_confusion.html';
michael@0 54 startTest = true;
michael@0 55 });
michael@0 56 </script>
michael@0 57 </pre>
michael@0 58 </body>
michael@0 59 </html>

mercurial