test_disallowInheritPrincipal.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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">
  15. </div>
  16. <pre id="test">
  17. <script type="application/javascript">
  18. /** Test for Bug 732413
  19. Passing DISALLOW_INHERIT_PRINCIPAL flag should be effective even if
  20. aPrincipal is the system principal.
  21. **/
  22. const nsIScriptSecurityManager = SpecialPowers.Ci.nsIScriptSecurityManager;
  23. var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
  24. .getService(nsIScriptSecurityManager);
  25. var sysPrincipal = secMan.getSystemPrincipal();
  26. isnot(sysPrincipal, undefined, "Should have a principal");
  27. isnot(sysPrincipal, null, "Should have a non-null principal");
  28. is(secMan.isSystemPrincipal(sysPrincipal), true,
  29. "Should have system principal here");
  30. var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
  31. getService(SpecialPowers.Ci.nsIIOService);
  32. var inheritingURI = ioService.newURI("javascript:1+1", null, null);
  33. // First try a normal call to checkLoadURIWithPrincipal
  34. try {
  35. secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
  36. nsIScriptSecurityManager.STANDARD);
  37. ok(true, "checkLoadURI allowed the load");
  38. } catch (e) {
  39. ok(false, "checkLoadURI failed unexpectedly: " + e);
  40. }
  41. // Now call checkLoadURIWithPrincipal with DISALLOW_INHERIT_PRINCIPAL
  42. try {
  43. secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
  44. nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
  45. ok(false, "checkLoadURI allowed the load unexpectedly");
  46. } catch (e) {
  47. ok(true, "checkLoadURI prevented load of principal-inheriting URI");
  48. }
  49. </script>
  50. </pre>
  51. </body>
  52. </html>