tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_allowWaivers.js (1255B)


      1 function checkWaivers(from, allowed) {
      2  var sb = new Cu.Sandbox('http://example.com');
      3  from.test = sb.eval('var o = {prop: 2, f: function() {return 42;}}; o');
      4 
      5  // Make sure that |from| has Xrays to sb.
      6  Assert.equal(from.eval('test.prop'), 2);
      7  Assert.equal(from.eval('test.f'), undefined);
      8 
      9  // Make sure that waivability works as expected.
     10  Assert.equal(from.eval('!!test.wrappedJSObject'), allowed);
     11  Assert.equal(from.eval('XPCNativeWrapper.unwrap(test) !== test'), allowed);
     12 
     13  // Make a sandbox with the same principal as |from|, but without any waiver
     14  // restrictions, and make sure that the waiver does not transfer.
     15  var friend = new Cu.Sandbox(Cu.getObjectPrincipal(from));
     16  friend.test = from.test;
     17  friend.eval('var waived = test.wrappedJSObject;');
     18  Assert.equal(friend.eval('waived.f()'), 42);
     19  friend.from = from;
     20  friend.eval('from.waived = waived');
     21  Assert.equal(from.eval('!!waived.f'), allowed);
     22 }
     23 
     24 function run_test() {
     25  checkWaivers(new Cu.Sandbox('http://example.com'), true);
     26  checkWaivers(new Cu.Sandbox('http://example.com', {allowWaivers: false}), false);
     27  checkWaivers(new Cu.Sandbox(['http://example.com']), true);
     28  checkWaivers(new Cu.Sandbox(['http://example.com'], {allowWaivers: false}), false);
     29 }