caps/tests/mochitest/test_disallowInheritPrincipal.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=732413
     5 -->
     6 <head>
     7   <title>Test for Bug 732413</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=732413">Mozilla Bug 732413</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 <script type="application/javascript">
    20 /** Test for Bug 732413
    21     Passing DISALLOW_INHERIT_PRINCIPAL flag should be effective even if
    22     aPrincipal is the system principal.
    23  **/
    25 const nsIScriptSecurityManager = SpecialPowers.Ci.nsIScriptSecurityManager;
    26 var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
    27                        .getService(nsIScriptSecurityManager);
    28 var sysPrincipal = secMan.getSystemPrincipal();
    29 isnot(sysPrincipal, undefined, "Should have a principal");
    30 isnot(sysPrincipal, null, "Should have a non-null principal");
    31 is(secMan.isSystemPrincipal(sysPrincipal), true,
    32    "Should have system principal here");
    35 var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
    36                 getService(SpecialPowers.Ci.nsIIOService);
    37 var inheritingURI = ioService.newURI("javascript:1+1", null, null);
    39 // First try a normal call to checkLoadURIWithPrincipal
    40 try {
    41   secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
    42                                    nsIScriptSecurityManager.STANDARD);
    43   ok(true, "checkLoadURI allowed the load");
    44 } catch (e) {
    45   ok(false, "checkLoadURI failed unexpectedly: " + e);
    46 }
    48 // Now call checkLoadURIWithPrincipal with DISALLOW_INHERIT_PRINCIPAL
    49 try {
    50   secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
    51                                    nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
    52   ok(false, "checkLoadURI allowed the load unexpectedly");
    53 } catch (e) {
    54   ok(true, "checkLoadURI prevented load of principal-inheriting URI");
    55 }
    57 </script>
    58 </pre>
    59 </body>
    60 </html>

mercurial